diff --git a/src/components/notify-new-version/index.ts b/src/components/notify-new-version/index.ts
index 4020647b4..8a8f8fd85 100644
--- a/src/components/notify-new-version/index.ts
+++ b/src/components/notify-new-version/index.ts
@@ -1,13 +1,12 @@
import { cdnRoots } from '@/core/cdn-types'
-import { ComponentMetadata, componentsTags } from '../types'
+import { defineComponentMetadata } from '@/components/define'
+import { componentsTags } from '../types'
-export const component: ComponentMetadata = {
+export const component = defineComponentMetadata({
name: 'notifyNewVersion',
displayName: '新版本提示',
description: '定期检查脚本本体的更新, 并弹出提示.',
- tags: [
- componentsTags.utils,
- ],
+ tags: [componentsTags.utils],
options: {
lastUpdateCheck: {
displayName: '最后检查更新日期',
@@ -28,19 +27,28 @@ export const component: ComponentMetadata = {
const { getGeneralSettings } = await import('@/core/settings')
const now = Number(new Date())
const duration = now - options.lastUpdateCheck
- if (duration < options.minimumDuration) { // 未到间隔期
+ if (duration < options.minimumDuration) {
+ // 未到间隔期
return
}
// 本地调试版不检查
if (!GM_info.scriptUpdateURL) {
return
}
- const updateUrl = `${cdnRoots[getGeneralSettings().cdnRoot](meta.compilationInfo.branch)}dist/${meta.originalFilename}`
- const scriptText: string = await monkey({ url: updateUrl, responseType: 'text' })
+ const updateUrl = `${cdnRoots[getGeneralSettings().cdnRoot](
+ meta.compilationInfo.branch,
+ )}dist/${meta.originalFilename}`
+ const scriptText: string = await monkey({
+ url: updateUrl,
+ responseType: 'text',
+ })
options.lastUpdateCheck = Number(new Date())
- const versionMatch = scriptText.match(/^\/\/ @version\s*([\d\.]+)$/m)
+ const versionMatch = scriptText.match(/^\/\/ @version\s*([\d.]+)$/m)
if (!versionMatch?.[1]) {
- console.warn('[新版本提示] 未能检测出脚本版本, scriptText.length =', scriptText.length)
+ console.warn(
+ '[新版本提示] 未能检测出脚本版本, scriptText.length =',
+ scriptText.length,
+ )
return
}
const latestVersion = new Version(versionMatch[1])
@@ -48,9 +56,12 @@ export const component: ComponentMetadata = {
if (!latestVersion.greaterThan(currentVersion)) {
return
}
- Toast.info(/* html */`新版本 ${latestVersion.versionString} 已发布. 更新说明安装`, '检查更新')
+ Toast.info(
+ /* html */ `新版本 ${latestVersion.versionString} 已发布. 更新说明安装`,
+ '检查更新',
+ )
} catch (error) {
console.warn('[新版本提示] 检查更新时发生错误: ', error)
}
},
-}
+})