diff --git a/backend/services/preferences_service.go b/backend/services/preferences_service.go index 0a85eaf..927cac7 100644 --- a/backend/services/preferences_service.go +++ b/backend/services/preferences_service.go @@ -222,22 +222,31 @@ func (p *preferencesService) GetDecoder() []convutil.CmdConvert { }) } -type latestRelease struct { - Name string `json:"name"` - TagName string `json:"tag_name"` - Url string `json:"url"` - HtmlUrl string `json:"html_url"` +type sponsorItem struct { + Name string `json:"name"` + Link string `json:"link"` + Region []string `json:"region"` +} + +type upgradeInfo struct { + Version string `json:"version"` + Changelog map[string]string `json:"changelog"` + Description map[string]string `json:"description"` + DownloadURl map[string]string `json:"download_url"` + DownloadPage map[string]string `json:"download_page"` + Sponsor []sponsorItem `json:"sponsor,omitempty"` } func (p *preferencesService) CheckForUpdate() (resp types.JSResp) { // request latest version - res, err := http.Get("https://api.github.com/repos/tiny-craft/tiny-rdm/releases/latest") + //res, err := http.Get("https://api.github.com/repos/tiny-craft/tiny-rdm/releases/latest") + res, err := http.Get("https://redis.tinycraft.cc/client_version.json") if err != nil || res.StatusCode != http.StatusOK { resp.Msg = "network error" return } - var respObj latestRelease + var respObj upgradeInfo err = json.NewDecoder(res.Body).Decode(&respObj) if err != nil { resp.Msg = "invalid content" @@ -247,9 +256,11 @@ func (p *preferencesService) CheckForUpdate() (resp types.JSResp) { // compare with current version resp.Success = true resp.Data = map[string]any{ - "version": p.clientVersion, - "latest": respObj.TagName, - "page_url": respObj.HtmlUrl, + "version": p.clientVersion, + "latest": respObj.Version, + "description": respObj.Description, + "download_page": respObj.DownloadPage, + "sponsor": respObj.Sponsor, } return } diff --git a/frontend/src/components/content/ContentServerPane.vue b/frontend/src/components/content/ContentServerPane.vue index ccd13d1..5118b2b 100644 --- a/frontend/src/components/content/ContentServerPane.vue +++ b/frontend/src/components/content/ContentServerPane.vue @@ -1,8 +1,32 @@ + + @@ -28,6 +56,13 @@ const dialogStore = useDialogStore() justify-content: center; padding: 5px; box-sizing: border-box; + + & > .sponsor-ad { + text-align: center; + margin-top: 20px; + vertical-align: bottom; + color: v-bind('themeVars.textColor3'); + } } .color-preset-item { diff --git a/frontend/src/stores/preferences.js b/frontend/src/stores/preferences.js index fb1f025..df89f47 100644 --- a/frontend/src/stores/preferences.js +++ b/frontend/src/stores/preferences.js @@ -467,15 +467,27 @@ const usePreferencesStore = defineStore('preferences', { try { const { success, data = {} } = await CheckForUpdate() if (success) { - const { version = 'v1.0.0', latest, page_url: pageUrl } = data + const { + version = 'v1.0.0', + latest, + download_page: pageUrl = {}, + description = {}, + sponsor = [], + } = data + const downUrl = pageUrl[this.currentLanguage] || pageUrl['en'] + const descStr = description[this.currentLanguage] || description['en'] + // save sponsor ad + if (!isEmpty(sponsor)) { + localStorage.setItem('sponsor_ad', JSON.stringify(sponsor)) + } if ( - (manual || latest > this.general.skipVersion) && + (manual || compareVersion(latest, this.general.skipVersion) !== 0) && compareVersion(latest, version) > 0 && - !isEmpty(pageUrl) + !isEmpty(downUrl) ) { const notiRef = $notification.show({ - title: i18nGlobal.t('dialogue.upgrade.title'), - content: i18nGlobal.t('dialogue.upgrade.new_version_tip', { ver: latest }), + title: `${i18nGlobal.t('dialogue.upgrade.title')} - ${latest}`, + content: descStr || i18nGlobal.t('dialogue.upgrade.new_version_tip', { ver: latest }), action: () => h('div', { class: 'flex-box-h flex-item-expand' }, [ h(NSpace, { wrapItem: false }, () => [ @@ -508,13 +520,13 @@ const usePreferencesStore = defineStore('preferences', { type: 'primary', size: 'small', secondary: true, - onClick: () => BrowserOpenURL(pageUrl), + onClick: () => BrowserOpenURL(downUrl), }, () => i18nGlobal.t('dialogue.upgrade.download_now'), ), ]), ]), - onPositiveClick: () => BrowserOpenURL(pageUrl), + onPositiveClick: () => BrowserOpenURL(downUrl), }) return }