Skip to content

Commit 9b349ac

Browse files
committed
fallback default settings if unexpected error occurs
1 parent 1b49e75 commit 9b349ac

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

background/index.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,29 @@ async function fallbackDefaultSettings() {
1919
}
2020
}
2121

22+
let rimeLoaded = false;
2223
self.controller = new InputController();
2324
chrome.storage.sync.get(["settings"]).then(async (obj) => {
2425
// Only load engine if settings exists
2526
if (obj.settings) {
2627
const ok = await self.controller.loadRime(false);
27-
if (!ok) {
28-
await fallbackDefaultSettings();
29-
}
30-
await globalPrepare();
28+
rimeLoaded = ok;
3129
}
32-
})
30+
}).catch((e) => {
31+
console.error('load settings error', e);
32+
}).finally(async () => {
33+
if (!rimeLoaded) {
34+
await fallbackDefaultSettings();
35+
}
36+
await postLoad();
37+
});
3338

3439
chrome.input.ime.onActivate.addListener(async (engineId, screen) => {
3540
self.controller.engineId = engineId;
3641
serviceWorkerKeepalive();
3742
});
3843

39-
chrome.runtime.onInstalled.addListener(async (d) => {
40-
if (d.reason == chrome.runtime.OnInstalledReason.INSTALL) {
41-
await fallbackDefaultSettings();
42-
await globalPrepare();
43-
}
44-
})
45-
46-
const globalPrepare = async () => {
44+
const postLoad = async () => {
4745
chrome.input.ime.onFocus.addListener(async (context) => {
4846
// Todo: in incoginto tab, context.shouldDoLearning = false,
4947
// we should disable rime learning in such context

0 commit comments

Comments
 (0)