Skip to content

Commit 8bb9a2d

Browse files
authored
🐛 选择不定期检查脚本更新时,清除现有Alarm (#996)
1 parent a70400c commit 8bb9a2d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/app/service/service_worker/regular_updatecheck.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ export const initRegularUpdateCheck = async (systemConfig: SystemConfig) => {
1919
chrome.storage.local.get(["checkupdate_script_lasttime"]),
2020
systemConfig.getCheckScriptUpdateCycle(), // check_script_update_cycle
2121
]);
22-
if (updateCycleSecond === 0) return; // no regular update check
2322
const now = Date.now();
23+
if (updateCycleSecond === 0) {
24+
// SW启动时,即使停用了更新功能也要设置一下变数值
25+
allowRegularUpdateCheck = now + ALLOW_CHECK_DELAY_MS; // 可以触发alarm的更新程序了
26+
// 设定更改的话,现时的Alarm需要清除。不判断是否SW启动了,总之就清除一下
27+
chrome.alarms.clear("checkScriptUpdate"); // 如没有可以清除的Alarm,Promise会返回false
28+
// 不需要检查更新。退出操作
29+
return;
30+
}
2431
let when = 0;
2532
const checkupdate_script_lasttime: number = result.checkupdate_script_lasttime || 0;
2633
// 有 checkupdate_script_lasttime 而且是单数值(上次的定时更新检查有完成)
@@ -62,6 +69,7 @@ const setCheckupdateScriptLasttime = async (t: number) => {
6269
}
6370
};
6471

72+
// 只会由系统Alarm事件呼叫
6573
export const onRegularUpdateCheckAlarm = async (
6674
systemConfig: SystemConfig,
6775
script: ScriptService,
@@ -73,7 +81,13 @@ export const onRegularUpdateCheckAlarm = async (
7381
chrome.storage.local.get(["checkupdate_script_lasttime"]),
7482
systemConfig.getCheckScriptUpdateCycle(), // check_script_update_cycle
7583
]);
76-
if (updateCycleSecond === 0) return null; // no regular update check
84+
if (updateCycleSecond === 0) {
85+
// 按道理,不会跑到这个条件
86+
// Alarm应没有触发才对。无论为何,还是清一下alarm吧
87+
chrome.alarms.clear("checkScriptUpdate");
88+
// 不需要检查更新。退出操作
89+
return null;
90+
}
7791
const checkupdate_script_lasttime: number = result.checkupdate_script_lasttime || 0;
7892
const targetWhen = checkupdate_script_lasttime + updateCycleSecond * 1000;
7993
if (targetWhen - ALARM_TRIGGER_WINDOW_MS > now) return null; // 已检查过了(alarm触发了)

0 commit comments

Comments
 (0)