diff --git a/src/components/auto-update/checker.ts b/src/components/auto-update/checker.ts index 929f13335..370ef11a3 100644 --- a/src/components/auto-update/checker.ts +++ b/src/components/auto-update/checker.ts @@ -13,7 +13,8 @@ import { UpdateCheckItem, CheckSingleTypeUpdateConfig, } from './utils' -import { Options } from '.' +import type { Options } from '.' +import { isDataSaveMode } from '@/core/utils' export const checkUpdate = async (config: CheckUpdateConfig) => { const { @@ -23,9 +24,12 @@ export const checkUpdate = async (config: CheckUpdateConfig) => { force = false, maxCount = Infinity, } = config + if (isDataSaveMode()) { + return '当前为流量计费网络, 跳过更新检查.' + } const now = Number(new Date()) const { devMode } = getGeneralSettings() - const { options } = getComponentSettings(name) + const { options } = getComponentSettings(name) // Remove uninstalled items Object.keys(items) .filter(it => !existPredicate(it)) diff --git a/src/components/notify-new-version/index.ts b/src/components/notify-new-version/index.ts index b6f614715..32854a1d6 100644 --- a/src/components/notify-new-version/index.ts +++ b/src/components/notify-new-version/index.ts @@ -24,6 +24,10 @@ export const component = defineComponentMetadata({ const { monkey } = await import('@/core/ajax') const { meta } = await import('@/core/meta') const { Toast } = await import('@/core/toast') + const { isDataSaveMode } = await import('@/core/utils') + if (isDataSaveMode()) { + return + } const now = Number(new Date()) const duration = now - options.lastUpdateCheck if (duration < options.minimumDuration) { diff --git a/src/core/utils/index.ts b/src/core/utils/index.ts index a96acf4da..7c292f229 100644 --- a/src/core/utils/index.ts +++ b/src/core/utils/index.ts @@ -672,3 +672,8 @@ export const todo = (...args: unknown[]): never => { export const unreachable = (): never => { throw new Error(`unreachable`) } + +/** 是否为流量计费网络 (不支持的浏览器仍按 false 算) */ +export const isDataSaveMode = () => { + return navigator.connection?.saveData ?? false +} diff --git a/src/global.d.ts b/src/global.d.ts index 5f601e6d9..fc8a7e90c 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -9,6 +9,30 @@ declare global { const lodash: LoDashStatic const Vue: typeof import('vue/types/umd') + type EnumEventTarget = EventTarget & { + addEventListener( + type: EventTypes, + callback: EventListenerOrEventListenerObject | null, + options?: AddEventListenerOptions | boolean, + ): void + removeEventListener( + type: EventTypes, + callback: EventListenerOrEventListenerObject | null, + options?: EventListenerOptions | boolean, + ): void + } + interface NetworkInformation extends EnumEventTarget<'change'> { + downlink: number + downlinkMax: number + effectiveType: string + rtt: number + saveData: boolean + type: string + } + interface Navigator { + connection?: NetworkInformation + } + interface GitInfo { commitHash: string branch: string