Skip to content

Commit

Permalink
fallback default settings if unexpected error occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
bytes-crafter committed Nov 2, 2023
1 parent 1b49e75 commit 9b349ac
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,29 @@ async function fallbackDefaultSettings() {
}
}

let rimeLoaded = false;
self.controller = new InputController();
chrome.storage.sync.get(["settings"]).then(async (obj) => {
// Only load engine if settings exists
if (obj.settings) {
const ok = await self.controller.loadRime(false);
if (!ok) {
await fallbackDefaultSettings();
}
await globalPrepare();
rimeLoaded = ok;
}
})
}).catch((e) => {
console.error('load settings error', e);
}).finally(async () => {
if (!rimeLoaded) {
await fallbackDefaultSettings();
}
await postLoad();
});

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

chrome.runtime.onInstalled.addListener(async (d) => {
if (d.reason == chrome.runtime.OnInstalledReason.INSTALL) {
await fallbackDefaultSettings();
await globalPrepare();
}
})

const globalPrepare = async () => {
const postLoad = async () => {
chrome.input.ime.onFocus.addListener(async (context) => {
// Todo: in incoginto tab, context.shouldDoLearning = false,
// we should disable rime learning in such context
Expand Down

0 comments on commit 9b349ac

Please sign in to comment.