fix: corrected update-checking logic

This commit is contained in:
tiny-craft 2023-09-17 01:15:55 +08:00
parent 53a198bdc5
commit e397e2c4c4
8 changed files with 21 additions and 15 deletions

1
.gitignore vendored
View File

@ -2,5 +2,6 @@ build/bin
node_modules
frontend/dist
frontend/wailsjs
design/
.vscode
.idea

View File

@ -3,7 +3,6 @@ package services
import (
"encoding/json"
"github.com/adrg/sysfont"
"io"
"net/http"
"sort"
"strings"
@ -87,7 +86,11 @@ func (p *preferencesService) GetFontList() (resp types.JSResp) {
}
func (p *preferencesService) SetClientVersion(ver string) {
p.clientVersion = ver
if !strings.HasPrefix(ver, "v") {
p.clientVersion = "v" + ver
} else {
p.clientVersion = ver
}
}
type latestRelease struct {
@ -105,13 +108,8 @@ func (p *preferencesService) CheckForUpdate() (resp types.JSResp) {
return
}
body, err := io.ReadAll(res.Body)
if err != nil {
resp.Msg = "invalid content"
return
}
var respObj latestRelease
err = json.Unmarshal(body, &respObj)
err = json.NewDecoder(res.Body).Decode(&respObj)
if err != nil {
resp.Msg = "invalid content"
return

View File

@ -81,7 +81,7 @@ watch(
<n-spin
:show="props.loading"
:theme-overrides="{ opacitySpinning: 0 }"
style="--wails-draggable: drag; border-radius: 10px"
style="border-radius: 10px"
:style="{ backgroundColor: themeVars.bodyColor }">
<div
id="app-content-wrapper"

View File

@ -175,7 +175,7 @@
"title": "Set Key TTL"
},
"upgrade": {
"new_version_tip": "A new version is available. Download now?",
"new_version_tip": "A new version({ver}) is available. Download now?",
"no_update": "You're update to date"
}
},

View File

@ -176,7 +176,7 @@
"title": "设置键存活时间"
},
"upgrade":{
"new_version_tip": "有可用的新版本,是否立即下载",
"new_version_tip": "有可用的新版本{ver},是否立即下载",
"no_update": "当前已是最新版"
}
},

View File

@ -250,9 +250,10 @@ const usePreferencesStore = defineStore('preferences', {
try {
const { success, data = {} } = await CheckForUpdate()
if (success) {
const { version, latest, pageUrl } = data
if (latest > version) {
$dialog.warning(i18nGlobal.t('dialogue.upgrade.new_version_tip'), () => {
const { version = 'v1.0.0', latest, page_url: pageUrl } = data
if (latest > version && !isEmpty(pageUrl)) {
const tip = i18nGlobal.t('dialogue.upgrade.new_version_tip', { ver: version })
$dialog.warning(tip, () => {
BrowserOpenURL(pageUrl)
})
return

View File

@ -21,7 +21,8 @@ body {
padding: 0;
background-color: #0000;
line-height: 1.5;
font-family: v-sans, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"
font-family: v-sans, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
--wails-draggable: drag;
}
#app {
@ -118,3 +119,7 @@ body {
//border-top: v-bind('themeVars.borderColor') 1px solid;
}
}
.n-dialog {
--wails-draggable: drag;
}

View File

@ -27,6 +27,7 @@ func main() {
app := NewApp()
connSvc := services.Connection()
prefSvc := services.Preferences()
prefSvc.SetClientVersion(version)
// menu
appMenu := menu.NewMenu()