pref: change new version checking and add sponsor ad
This commit is contained in:
parent
dd70d6b595
commit
52aaad6339
|
@ -222,22 +222,31 @@ func (p *preferencesService) GetDecoder() []convutil.CmdConvert {
|
|||
})
|
||||
}
|
||||
|
||||
type latestRelease struct {
|
||||
type sponsorItem struct {
|
||||
Name string `json:"name"`
|
||||
TagName string `json:"tag_name"`
|
||||
Url string `json:"url"`
|
||||
HtmlUrl string `json:"html_url"`
|
||||
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"
|
||||
|
@ -248,8 +257,10 @@ func (p *preferencesService) CheckForUpdate() (resp types.JSResp) {
|
|||
resp.Success = true
|
||||
resp.Data = map[string]any{
|
||||
"version": p.clientVersion,
|
||||
"latest": respObj.TagName,
|
||||
"page_url": respObj.HtmlUrl,
|
||||
"latest": respObj.Version,
|
||||
"description": respObj.Description,
|
||||
"download_page": respObj.DownloadPage,
|
||||
"sponsor": respObj.Sponsor,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,8 +1,32 @@
|
|||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import AddLink from '@/components/icons/AddLink.vue'
|
||||
import useDialogStore from 'stores/dialog.js'
|
||||
import { NButton, useThemeVars } from 'naive-ui'
|
||||
import { BrowserOpenURL } from 'wailsjs/runtime/runtime.js'
|
||||
import { find, includes, isEmpty } from 'lodash'
|
||||
import usePreferencesStore from 'stores/preferences.js'
|
||||
|
||||
const themeVars = useThemeVars()
|
||||
const dialogStore = useDialogStore()
|
||||
const prefStore = usePreferencesStore()
|
||||
|
||||
const onOpenSponsor = (link) => {
|
||||
BrowserOpenURL(link)
|
||||
}
|
||||
|
||||
const sponsorAd = computed(() => {
|
||||
try {
|
||||
const content = localStorage.getItem('sponsor_ad')
|
||||
const ads = JSON.parse(content)
|
||||
const ad = find(ads, ({ region }) => {
|
||||
return isEmpty(region) || includes(region, prefStore.currentLanguage)
|
||||
})
|
||||
return ad || null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -18,6 +42,10 @@ const dialogStore = useDialogStore()
|
|||
</n-button>
|
||||
</template>
|
||||
</n-empty>
|
||||
|
||||
<n-button v-if="sponsorAd != null" class="sponsor-ad" style="" text @click="onOpenSponsor(sponsorAd.link)">
|
||||
{{ sponsorAd.name }}
|
||||
</n-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue