feat: add "skip this version"/"remain me later" for upgrade prompt
This commit is contained in:
parent
e397e2c4c4
commit
61be0165ea
|
@ -27,6 +27,8 @@ func (p *PreferencesStorage) DefaultPreferences() map[string]any {
|
||||||
"use_sys_proxy": false,
|
"use_sys_proxy": false,
|
||||||
"use_sys_proxy_http": false,
|
"use_sys_proxy_http": false,
|
||||||
"check_update": true,
|
"check_update": true,
|
||||||
|
"skip_version": "",
|
||||||
|
"aside_width": 300,
|
||||||
},
|
},
|
||||||
"editor": map[string]any{
|
"editor": map[string]any{
|
||||||
"font": "",
|
"font": "",
|
||||||
|
|
|
@ -175,8 +175,12 @@
|
||||||
"title": "Set Key TTL"
|
"title": "Set Key TTL"
|
||||||
},
|
},
|
||||||
"upgrade": {
|
"upgrade": {
|
||||||
|
"title": "New Version Available",
|
||||||
"new_version_tip": "A new version({ver}) 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",
|
||||||
|
"download_now": "Download",
|
||||||
|
"later": "Later",
|
||||||
|
"skip": "Skip This Update"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"menu": {
|
"menu": {
|
||||||
|
|
|
@ -176,8 +176,12 @@
|
||||||
"title": "设置键存活时间"
|
"title": "设置键存活时间"
|
||||||
},
|
},
|
||||||
"upgrade":{
|
"upgrade":{
|
||||||
"new_version_tip": "有可用的新版本({ver}),是否立即下载",
|
"title": "有可用新版本",
|
||||||
"no_update": "当前已是最新版"
|
"new_version_tip": "新版本({ver}),是否立即下载",
|
||||||
|
"no_update": "当前已是最新版",
|
||||||
|
"download_now": "立即下载",
|
||||||
|
"later": "稍后提醒我",
|
||||||
|
"skip": "忽略本次更新"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"menu": {
|
"menu": {
|
||||||
|
|
|
@ -10,7 +10,8 @@ import {
|
||||||
} from 'wailsjs/go/services/preferencesService.js'
|
} from 'wailsjs/go/services/preferencesService.js'
|
||||||
import { BrowserOpenURL } from 'wailsjs/runtime/runtime.js'
|
import { BrowserOpenURL } from 'wailsjs/runtime/runtime.js'
|
||||||
import { i18nGlobal } from '@/utils/i18n.js'
|
import { i18nGlobal } from '@/utils/i18n.js'
|
||||||
import { enUS, useOsTheme, zhCN } from 'naive-ui'
|
import { enUS, NButton, NSpace, useOsTheme, zhCN } from 'naive-ui'
|
||||||
|
import { h, nextTick } from 'vue'
|
||||||
|
|
||||||
const osTheme = useOsTheme()
|
const osTheme = useOsTheme()
|
||||||
const usePreferencesStore = defineStore('preferences', {
|
const usePreferencesStore = defineStore('preferences', {
|
||||||
|
@ -38,6 +39,7 @@ const usePreferencesStore = defineStore('preferences', {
|
||||||
useSysProxy: false,
|
useSysProxy: false,
|
||||||
useSysProxyHttp: false,
|
useSysProxyHttp: false,
|
||||||
checkUpdate: false,
|
checkUpdate: false,
|
||||||
|
skipVersion: '',
|
||||||
asideWidth: 300,
|
asideWidth: 300,
|
||||||
},
|
},
|
||||||
editor: {
|
editor: {
|
||||||
|
@ -251,10 +253,49 @@ const usePreferencesStore = defineStore('preferences', {
|
||||||
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, page_url: pageUrl } = data
|
||||||
if (latest > version && !isEmpty(pageUrl)) {
|
if ((manual || latest > this.general.skipVersion) && latest > version && !isEmpty(pageUrl)) {
|
||||||
const tip = i18nGlobal.t('dialogue.upgrade.new_version_tip', { ver: version })
|
const notiRef = $notification.show({
|
||||||
$dialog.warning(tip, () => {
|
title: i18nGlobal.t('dialogue.upgrade.title'),
|
||||||
BrowserOpenURL(pageUrl)
|
content: i18nGlobal.t('dialogue.upgrade.new_version_tip', { ver: latest }),
|
||||||
|
action: () =>
|
||||||
|
h('div', { class: 'flex-box-h flex-item-expand' }, [
|
||||||
|
h(NSpace, { wrapItem: false }, () => [
|
||||||
|
h(
|
||||||
|
NButton,
|
||||||
|
{
|
||||||
|
size: 'small',
|
||||||
|
secondary: true,
|
||||||
|
onClick: () => {
|
||||||
|
// skip this update
|
||||||
|
this.general.skipVersion = latest
|
||||||
|
this.savePreferences()
|
||||||
|
notiRef.destroy()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
() => i18nGlobal.t('dialogue.upgrade.skip'),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
NButton,
|
||||||
|
{
|
||||||
|
size: 'small',
|
||||||
|
secondary: true,
|
||||||
|
onClick: notiRef.destroy,
|
||||||
|
},
|
||||||
|
() => i18nGlobal.t('dialogue.upgrade.later'),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
NButton,
|
||||||
|
{
|
||||||
|
type: 'primary',
|
||||||
|
size: 'small',
|
||||||
|
secondary: true,
|
||||||
|
onClick: () => BrowserOpenURL(pageUrl),
|
||||||
|
},
|
||||||
|
() => i18nGlobal.t('dialogue.upgrade.download_now'),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
onPositiveClick: () => BrowserOpenURL(pageUrl),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -264,10 +305,12 @@ const usePreferencesStore = defineStore('preferences', {
|
||||||
$message.info(i18nGlobal.t('dialogue.upgrade.no_update'))
|
$message.info(i18nGlobal.t('dialogue.upgrade.no_update'))
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
nextTick().then(() => {
|
||||||
if (msgRef != null) {
|
if (msgRef != null) {
|
||||||
msgRef.destroy()
|
msgRef.destroy()
|
||||||
msgRef = null
|
msgRef = null
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import usePreferencesStore from 'stores/preferences.js'
|
import usePreferencesStore from 'stores/preferences.js'
|
||||||
import { createDiscreteApi, darkTheme } from 'naive-ui'
|
import { createDiscreteApi, darkTheme, useDialog } from 'naive-ui'
|
||||||
import { themeOverrides } from '@/utils/theme.js'
|
import { themeOverrides } from '@/utils/theme.js'
|
||||||
import { i18nGlobal } from '@/utils/i18n.js'
|
import { i18nGlobal } from '@/utils/i18n.js'
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
|
@ -28,6 +28,13 @@ function setupMessage(message) {
|
||||||
|
|
||||||
function setupNotification(notification) {
|
function setupNotification(notification) {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* @param {NotificationOption} option
|
||||||
|
* @return {NotificationReactive}
|
||||||
|
*/
|
||||||
|
show(option) {
|
||||||
|
return notification.create(option)
|
||||||
|
},
|
||||||
error: (content, option = {}) => {
|
error: (content, option = {}) => {
|
||||||
option.content = content
|
option.content = content
|
||||||
option.title = option.title || i18nGlobal.t('common.error')
|
option.title = option.title || i18nGlobal.t('common.error')
|
||||||
|
@ -50,8 +57,23 @@ function setupNotification(notification) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {DialogApiInjection} dialog
|
||||||
|
* @return {*}
|
||||||
|
*/
|
||||||
function setupDialog(dialog) {
|
function setupDialog(dialog) {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* @param {DialogOptions} option
|
||||||
|
* @return {DialogReactive}
|
||||||
|
*/
|
||||||
|
show(option) {
|
||||||
|
option.closable = option.closable === true
|
||||||
|
option.autoFocus = option.autoFocus === true
|
||||||
|
option.transformOrigin = 'center'
|
||||||
|
return dialog.create(option)
|
||||||
|
},
|
||||||
warning: (content, onConfirm) => {
|
warning: (content, onConfirm) => {
|
||||||
return dialog.warning({
|
return dialog.warning({
|
||||||
title: i18nGlobal.t('common.warning'),
|
title: i18nGlobal.t('common.warning'),
|
||||||
|
@ -86,7 +108,7 @@ export async function setupDiscreteApi() {
|
||||||
},
|
},
|
||||||
notificationProviderProps: {
|
notificationProviderProps: {
|
||||||
max: 5,
|
max: 5,
|
||||||
placement: 'top-right',
|
placement: 'bottom-right',
|
||||||
keepAliveOnHover: true,
|
keepAliveOnHover: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue