aboutsummaryrefslogtreecommitdiff
path: root/src/background
diff options
context:
space:
mode:
Diffstat (limited to 'src/background')
-rw-r--r--src/background/infrastructures/ContentMessageClient.ts8
-rw-r--r--src/background/presenters/NotifyPresenter.ts11
-rw-r--r--src/background/usecases/SettingUseCase.ts16
3 files changed, 28 insertions, 7 deletions
diff --git a/src/background/infrastructures/ContentMessageClient.ts b/src/background/infrastructures/ContentMessageClient.ts
index 2983409..4d2284c 100644
--- a/src/background/infrastructures/ContentMessageClient.ts
+++ b/src/background/infrastructures/ContentMessageClient.ts
@@ -22,14 +22,14 @@ export default class ContentMessageClient {
return enabled as any as boolean;
}
- toggleAddonEnabled(tabId: number): Promise<void> {
- return browser.tabs.sendMessage(tabId, {
+ async toggleAddonEnabled(tabId: number): Promise<void> {
+ await browser.tabs.sendMessage(tabId, {
type: messages.ADDON_TOGGLE_ENABLED,
});
}
- scrollTo(tabId: number, x: number, y: number): Promise<void> {
- return browser.tabs.sendMessage(tabId, {
+ async scrollTo(tabId: number, x: number, y: number): Promise<void> {
+ await browser.tabs.sendMessage(tabId, {
type: messages.TAB_SCROLL_TO,
x,
y,
diff --git a/src/background/presenters/NotifyPresenter.ts b/src/background/presenters/NotifyPresenter.ts
index 9785278..defb601 100644
--- a/src/background/presenters/NotifyPresenter.ts
+++ b/src/background/presenters/NotifyPresenter.ts
@@ -26,11 +26,20 @@ export default class NotifyPresenter {
});
}
- async notifyInvalidSettings(): Promise<void> {
+ async notifyInvalidSettings(onclick: () => void): Promise<void> {
let title = `Loaded settings is invalid`;
// eslint-disable-next-line max-len
let message = 'The default settings is used due to the last saved settings is invalid. Check your current settings from the add-on preference';
+ const listener = (id: string) => {
+ if (id !== NOTIFICATION_ID_INVALID_SETTINGS) {
+ return;
+ }
+ onclick();
+ browser.notifications.onClicked.removeListener(listener);
+ };
+ browser.notifications.onClicked.addListener(listener);
+
await browser.notifications.create(NOTIFICATION_ID_INVALID_SETTINGS, {
'type': 'basic',
'iconUrl': browser.extension.getURL('resources/icon_48x48.png'),
diff --git a/src/background/usecases/SettingUseCase.ts b/src/background/usecases/SettingUseCase.ts
index 53c8f1d..d73521f 100644
--- a/src/background/usecases/SettingUseCase.ts
+++ b/src/background/usecases/SettingUseCase.ts
@@ -21,7 +21,12 @@ export default class SettingUseCase {
}
async reload(): Promise<Settings> {
- let data = await this.persistentSettingRepository.load();
+ let data;
+ try {
+ data = await this.persistentSettingRepository.load();
+ } catch (e) {
+ this.showUnableToLoad(e);
+ }
if (!data) {
data = DefaultSettingData;
}
@@ -30,10 +35,17 @@ export default class SettingUseCase {
try {
value = data.toSettings();
} catch (e) {
- this.notifyPresenter.notifyInvalidSettings();
+ this.showUnableToLoad(e);
value = DefaultSettingData.toSettings();
}
this.settingRepository.update(value!!);
return value;
}
+
+ private showUnableToLoad(e: Error) {
+ console.error('unable to load settings', e);
+ this.notifyPresenter.notifyInvalidSettings(() => {
+ browser.runtime.openOptionsPage();
+ });
+ }
}