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 node_modules
frontend/dist frontend/dist
frontend/wailsjs frontend/wailsjs
design/
.vscode .vscode
.idea .idea

View File

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

View File

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

View File

@ -175,7 +175,7 @@
"title": "Set Key TTL" "title": "Set Key TTL"
}, },
"upgrade": { "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" "no_update": "You're update to date"
} }
}, },

View File

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

View File

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

View File

@ -21,7 +21,8 @@ body {
padding: 0; padding: 0;
background-color: #0000; background-color: #0000;
line-height: 1.5; 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 { #app {
@ -118,3 +119,7 @@ body {
//border-top: v-bind('themeVars.borderColor') 1px solid; //border-top: v-bind('themeVars.borderColor') 1px solid;
} }
} }
.n-dialog {
--wails-draggable: drag;
}

View File

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