improve macos experience

This commit is contained in:
josc146 2024-02-05 00:25:04 +08:00
parent f1986fa9d0
commit d5cca4e542
4 changed files with 40 additions and 15 deletions

View File

@ -1,7 +1,9 @@
package backend_golang package backend_golang
import ( import (
"archive/zip"
"bufio" "bufio"
"bytes"
"context" "context"
"errors" "errors"
"io" "io"
@ -10,6 +12,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings"
"syscall" "syscall"
"time" "time"
@ -160,6 +163,7 @@ func (a *App) UpdateApp(url string) (broken bool, err error) {
ticker := time.NewTicker(250 * time.Millisecond) ticker := time.NewTicker(250 * time.Millisecond)
defer ticker.Stop() defer ticker.Stop()
// update progress
go func() { go func() {
for { for {
<-ticker.C <-ticker.C
@ -179,13 +183,35 @@ func (a *App) UpdateApp(url string) (broken bool, err error) {
} }
} }
}() }()
err = selfupdate.Apply(pr, selfupdate.Options{})
var updateFile io.Reader = pr
// extract macos binary from zip
if strings.HasSuffix(url, ".zip") && runtime.GOOS == "darwin" {
zipBytes, err := io.ReadAll(pr)
if err != nil {
return false, err
}
archive, err := zip.NewReader(bytes.NewReader(zipBytes), int64(len(zipBytes)))
if err != nil {
return false, err
}
file, err := archive.Open("Contents/MacOS/RWKV-Runner")
if err != nil {
return false, err
}
defer file.Close()
updateFile = file
}
// apply update
err = selfupdate.Apply(updateFile, selfupdate.Options{})
if err != nil { if err != nil {
if rerr := selfupdate.RollbackError(err); rerr != nil { if rerr := selfupdate.RollbackError(err); rerr != nil {
return true, rerr return true, rerr
} }
return false, err return false, err
} }
// restart app
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
name, err := os.Executable() name, err := os.Executable()
if err != nil { if err != nil {

View File

@ -272,18 +272,16 @@ const Settings: FC = observer(() => {
<AccordionHeader ref={advancedHeaderRef} size="large">{t('Advanced')}</AccordionHeader> <AccordionHeader ref={advancedHeaderRef} size="large">{t('Advanced')}</AccordionHeader>
<AccordionPanel> <AccordionPanel>
<div className="flex flex-col gap-2 overflow-hidden"> <div className="flex flex-col gap-2 overflow-hidden">
{commonStore.platform !== 'darwin' && <Labeled label={t('Custom Models Path')}
<Labeled label={t('Custom Models Path')} content={
content={ <Input className="grow" placeholder="./models"
<Input className="grow" placeholder="./models" value={commonStore.settings.customModelsPath}
value={commonStore.settings.customModelsPath} onChange={(e, data) => {
onChange={(e, data) => { commonStore.setSettings({
commonStore.setSettings({ customModelsPath: data.value
customModelsPath: data.value });
}); }} />
}} /> } />
} />
}
<Labeled label={t('Custom Python Path')} // if set, will not use precompiled cuda kernel <Labeled label={t('Custom Python Path')} // if set, will not use precompiled cuda kernel
content={ content={
<Input className="grow" placeholder="./py310/python" <Input className="grow" placeholder="./py310/python"

View File

@ -419,7 +419,8 @@ const LoraFinetune: FC = observer(() => {
outputPrefix, outputPrefix,
dataParams.vocabPath).then(async () => { dataParams.vocabPath).then(async () => {
if (!await FileExists(outputPrefix + '_text_document.idx')) { if (!await FileExists(outputPrefix + '_text_document.idx')) {
toast(t('Failed to convert data') + ' - ' + await GetPyError(), { type: 'error' }); if (commonStore.platform === 'windows' || commonStore.platform === 'linux')
toast(t('Failed to convert data') + ' - ' + await GetPyError(), { type: 'error' });
} else { } else {
toast(t('Convert Data successfully'), { type: 'success' }); toast(t('Convert Data successfully'), { type: 'success' });
} }

View File

@ -352,7 +352,7 @@ export async function checkUpdate(notifyEvenLatest: boolean = false) {
if (r.ok) { if (r.ok) {
r.json().then((data) => { r.json().then((data) => {
if (data.assets && data.assets.length > 0) { if (data.assets && data.assets.length > 0) {
const asset = data.assets.find((a: any) => a.name.toLowerCase().includes(commonStore.platform.toLowerCase())); const asset = data.assets.find((a: any) => a.name.toLowerCase().includes(commonStore.platform.toLowerCase().replace('darwin', 'macos')));
if (asset) { if (asset) {
const updateUrl = !commonStore.settings.giteeUpdatesSource ? const updateUrl = !commonStore.settings.giteeUpdatesSource ?
`https://github.com/josStorer/RWKV-Runner/releases/download/${versionTag}/${asset.name}` : `https://github.com/josStorer/RWKV-Runner/releases/download/${versionTag}/${asset.name}` :