Skip to content

Commit

Permalink
fix: corrected update-checking logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tiny-craft committed Sep 16, 2023
1 parent 53a198b commit e397e2c
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ build/bin
node_modules
frontend/dist
frontend/wailsjs
design/
.vscode
.idea
14 changes: 6 additions & 8 deletions backend/services/preferences_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package services
import (
"encoding/json"
"github.com/adrg/sysfont"
"io"
"net/http"
"sort"
"strings"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/AppContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/langs/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/langs/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
"title": "设置键存活时间"
},
"upgrade":{
"new_version_tip": "有可用的新版本,是否立即下载",
"new_version_tip": "有可用的新版本({ver}),是否立即下载",
"no_update": "当前已是最新版"
}
},
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/stores/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -118,3 +119,7 @@ body {
//border-top: v-bind('themeVars.borderColor') 1px solid;
}
}

.n-dialog {
--wails-draggable: drag;
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func main() {
app := NewApp()
connSvc := services.Connection()
prefSvc := services.Preferences()
prefSvc.SetClientVersion(version)

// menu
appMenu := menu.NewMenu()
Expand Down

0 comments on commit e397e2c

Please sign in to comment.