Merge branch 'preview-features' into preview

This commit is contained in:
the1812 2022-02-19 21:53:18 +08:00
commit 2b5c1f8f84
3 changed files with 23 additions and 9 deletions

View File

@ -17,7 +17,7 @@ import {
VButton,
VIcon,
} from '@/ui'
import { silentCheckUpdateAndReload } from './checker'
import { forceCheckUpdateAndReload } from './checker'
export default Vue.extend({
components: {
@ -34,7 +34,7 @@ export default Vue.extend({
try {
this.disabled = true
const toast = Toast.info('正在检查更新...', '检查所有更新')
await silentCheckUpdateAndReload()
await forceCheckUpdateAndReload()
toast.dismiss()
} finally {
this.disabled = false

View File

@ -10,6 +10,7 @@ import {
CheckSingleTypeUpdate,
UpdateRecord,
UpdateCheckItem,
CheckSingleTypeUpdateConfig,
} from './utils'
export const checkUpdate = async (config: CheckUpdateConfig) => {
@ -121,17 +122,27 @@ const checkByName = (method: CheckSingleTypeUpdate) => reload(
await method({ filterNames: itemNames, force: true })
},
) as (...itemNames: string[]) => Promise<void>
export const silentCheckUpdate = async () => {
export const checkAllUpdate = async (config: CheckSingleTypeUpdateConfig) => {
const { options } = getComponentSettings(name)
console.log('[自动更新器] 开始检查更新')
console.log(await checkComponentsUpdate({ maxCount: options.maxUpdateCount }) || '暂无组件更新')
console.log(await checkPluginsUpdate({ maxCount: options.maxUpdateCount }) || '暂无插件更新')
console.log(await checkStylesUpdate({ maxCount: options.maxUpdateCount }) || '暂无样式更新')
console.log(await checkComponentsUpdate(config) || '暂无组件更新')
console.log(await checkPluginsUpdate(config) || '暂无插件更新')
console.log(await checkStylesUpdate(config) || '暂无样式更新')
options.lastUpdateCheck = Number(new Date())
options.lastInstalledVersion = meta.version
console.log('[自动更新器] 完成更新检查')
}
export const silentCheckUpdate = () => checkAllUpdate({
maxCount: getComponentSettings(name).options.maxUpdateCount,
})
export const silentCheckUpdateAndReload = reload(silentCheckUpdate)
export const forceCheckUpdate = () => checkAllUpdate({
force: true,
})
export const forceCheckUpdateAndReload = reload(forceCheckUpdate)
export const checkComponentsByName = checkByName(checkComponentsUpdate)
export const checkPluginsByName = checkByName(checkPluginsUpdate)
export const checkStylesByName = checkByName(checkStylesUpdate)

View File

@ -14,8 +14,9 @@ import * as checkerMethods from './checker'
const {
checkComponentsUpdate,
checkLastFeature,
forceCheckUpdate,
forceCheckUpdateAndReload,
silentCheckUpdate,
silentCheckUpdateAndReload,
} = checkerMethods
export const component: ComponentMetadata = {
@ -68,8 +69,10 @@ export const component: ComponentMetadata = {
const isDurationExceeded = duration >= options.minimumDuration
const isVersionOutdated = new Version(meta.version)
.greaterThan(new Version(options.lastInstalledVersion))
if (isDurationExceeded || isVersionOutdated) {
if (isDurationExceeded) {
coreApis.lifeCycle.fullyLoaded(() => silentCheckUpdate())
} else if (isVersionOutdated) {
coreApis.lifeCycle.fullyLoaded(() => forceCheckUpdate())
}
return checkerMethods
@ -151,7 +154,7 @@ export const component: ComponentMetadata = {
action: async () => {
const { Toast } = await import('@/core/toast')
const toast = Toast.info('正在检查更新...', '检查所有更新')
await silentCheckUpdateAndReload()
await forceCheckUpdateAndReload()
toast.dismiss()
},
icon,