diff --git a/backend-golang/app.go b/backend-golang/app.go index dda75f0..66497aa 100644 --- a/backend-golang/app.go +++ b/backend-golang/app.go @@ -1,7 +1,9 @@ package backend_golang import ( + "archive/zip" "bufio" + "bytes" "context" "errors" "io" @@ -10,6 +12,7 @@ import ( "os/exec" "path/filepath" "runtime" + "strings" "syscall" "time" @@ -160,6 +163,7 @@ func (a *App) UpdateApp(url string) (broken bool, err error) { ticker := time.NewTicker(250 * time.Millisecond) defer ticker.Stop() + // update progress go func() { for { <-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 rerr := selfupdate.RollbackError(err); rerr != nil { return true, rerr } return false, err } + // restart app if runtime.GOOS == "windows" { name, err := os.Executable() if err != nil { diff --git a/frontend/src/pages/Settings.tsx b/frontend/src/pages/Settings.tsx index 5a0db5f..106d826 100644 --- a/frontend/src/pages/Settings.tsx +++ b/frontend/src/pages/Settings.tsx @@ -272,18 +272,16 @@ const Settings: FC = observer(() => { {t('Advanced')}
- {commonStore.platform !== 'darwin' && - { - commonStore.setSettings({ - customModelsPath: data.value - }); - }} /> - } /> - } + { + commonStore.setSettings({ + customModelsPath: data.value + }); + }} /> + } /> { outputPrefix, dataParams.vocabPath).then(async () => { 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 { toast(t('Convert Data successfully'), { type: 'success' }); } diff --git a/frontend/src/utils/index.tsx b/frontend/src/utils/index.tsx index 22b7a1d..5ddc70c 100644 --- a/frontend/src/utils/index.tsx +++ b/frontend/src/utils/index.tsx @@ -352,7 +352,7 @@ export async function checkUpdate(notifyEvenLatest: boolean = false) { if (r.ok) { r.json().then((data) => { 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) { const updateUrl = !commonStore.settings.giteeUpdatesSource ? `https://github.com/josStorer/RWKV-Runner/releases/download/${versionTag}/${asset.name}` :