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"`
|
Name string `json:"name"`
|
||||||
TagName string `json:"tag_name"`
|
Link string `json:"link"`
|
||||||
Url string `json:"url"`
|
Region []string `json:"region"`
|
||||||
HtmlUrl string `json:"html_url"`
|
}
|
||||||
|
|
||||||
|
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) {
|
func (p *preferencesService) CheckForUpdate() (resp types.JSResp) {
|
||||||
// request latest version
|
// 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 {
|
if err != nil || res.StatusCode != http.StatusOK {
|
||||||
resp.Msg = "network error"
|
resp.Msg = "network error"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var respObj latestRelease
|
var respObj upgradeInfo
|
||||||
err = json.NewDecoder(res.Body).Decode(&respObj)
|
err = json.NewDecoder(res.Body).Decode(&respObj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Msg = "invalid content"
|
resp.Msg = "invalid content"
|
||||||
|
@ -248,8 +257,10 @@ func (p *preferencesService) CheckForUpdate() (resp types.JSResp) {
|
||||||
resp.Success = true
|
resp.Success = true
|
||||||
resp.Data = map[string]any{
|
resp.Data = map[string]any{
|
||||||
"version": p.clientVersion,
|
"version": p.clientVersion,
|
||||||
"latest": respObj.TagName,
|
"latest": respObj.Version,
|
||||||
"page_url": respObj.HtmlUrl,
|
"description": respObj.Description,
|
||||||
|
"download_page": respObj.DownloadPage,
|
||||||
|
"sponsor": respObj.Sponsor,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,32 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import { computed } from 'vue'
|
||||||
import AddLink from '@/components/icons/AddLink.vue'
|
import AddLink from '@/components/icons/AddLink.vue'
|
||||||
import useDialogStore from 'stores/dialog.js'
|
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 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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -18,6 +42,10 @@ const dialogStore = useDialogStore()
|
||||||
</n-button>
|
</n-button>
|
||||||
</template>
|
</template>
|
||||||
</n-empty>
|
</n-empty>
|
||||||
|
|
||||||
|
<n-button v-if="sponsorAd != null" class="sponsor-ad" style="" text @click="onOpenSponsor(sponsorAd.link)">
|
||||||
|
{{ sponsorAd.name }}
|
||||||
|
</n-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -28,6 +56,13 @@ const dialogStore = useDialogStore()
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
& > .sponsor-ad {
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 20px;
|
||||||
|
vertical-align: bottom;
|
||||||
|
color: v-bind('themeVars.textColor3');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.color-preset-item {
|
.color-preset-item {
|
||||||
|
|
|
@ -467,15 +467,27 @@ const usePreferencesStore = defineStore('preferences', {
|
||||||
try {
|
try {
|
||||||
const { success, data = {} } = await CheckForUpdate()
|
const { success, data = {} } = await CheckForUpdate()
|
||||||
if (success) {
|
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 (
|
if (
|
||||||
(manual || latest > this.general.skipVersion) &&
|
(manual || compareVersion(latest, this.general.skipVersion) !== 0) &&
|
||||||
compareVersion(latest, version) > 0 &&
|
compareVersion(latest, version) > 0 &&
|
||||||
!isEmpty(pageUrl)
|
!isEmpty(downUrl)
|
||||||
) {
|
) {
|
||||||
const notiRef = $notification.show({
|
const notiRef = $notification.show({
|
||||||
title: i18nGlobal.t('dialogue.upgrade.title'),
|
title: `${i18nGlobal.t('dialogue.upgrade.title')} - ${latest}`,
|
||||||
content: i18nGlobal.t('dialogue.upgrade.new_version_tip', { ver: latest }),
|
content: descStr || i18nGlobal.t('dialogue.upgrade.new_version_tip', { ver: latest }),
|
||||||
action: () =>
|
action: () =>
|
||||||
h('div', { class: 'flex-box-h flex-item-expand' }, [
|
h('div', { class: 'flex-box-h flex-item-expand' }, [
|
||||||
h(NSpace, { wrapItem: false }, () => [
|
h(NSpace, { wrapItem: false }, () => [
|
||||||
|
@ -508,13 +520,13 @@ const usePreferencesStore = defineStore('preferences', {
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
size: 'small',
|
size: 'small',
|
||||||
secondary: true,
|
secondary: true,
|
||||||
onClick: () => BrowserOpenURL(pageUrl),
|
onClick: () => BrowserOpenURL(downUrl),
|
||||||
},
|
},
|
||||||
() => i18nGlobal.t('dialogue.upgrade.download_now'),
|
() => i18nGlobal.t('dialogue.upgrade.download_now'),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
onPositiveClick: () => BrowserOpenURL(pageUrl),
|
onPositiveClick: () => BrowserOpenURL(downUrl),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue