From 818ba9ea1a6c46036a7ed448861217e63d3aa5be Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 3 Feb 2020 19:07:55 +0900 Subject: Synchronize settings via Firefox Sync --- .../repositories/LocalSettingRepository.ts | 3 +-- .../repositories/SyncSettingRepository.ts | 25 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/background/repositories/SyncSettingRepository.ts (limited to 'src/background/repositories') diff --git a/src/background/repositories/LocalSettingRepository.ts b/src/background/repositories/LocalSettingRepository.ts index 285b207..0c9ef3b 100644 --- a/src/background/repositories/LocalSettingRepository.ts +++ b/src/background/repositories/LocalSettingRepository.ts @@ -4,7 +4,7 @@ import SettingData from '../../shared/SettingData'; @injectable() export default class LocalSettingRepository { async load(): Promise { - const { settings } = await browser.storage.local.get('settings'); + const {settings} = await browser.storage.local.get('settings'); if (!settings) { return null; } @@ -22,4 +22,3 @@ export default class LocalSettingRepository { }); } } - diff --git a/src/background/repositories/SyncSettingRepository.ts b/src/background/repositories/SyncSettingRepository.ts new file mode 100644 index 0000000..9f59e61 --- /dev/null +++ b/src/background/repositories/SyncSettingRepository.ts @@ -0,0 +1,25 @@ +import { injectable } from 'tsyringe'; +import SettingData from '../../shared/SettingData'; + +@injectable() +export default class SyncSettingRepository { + async load(): Promise { + const { settings } = await browser.storage.sync.get('settings'); + if (!settings) { + return null; + } + return SettingData.fromJSON(settings as any); + } + + onChange(callback: () => void) { + browser.storage.onChanged.addListener((changes, area) => { + if (area !== 'sync') { + return; + } + if (changes.settings) { + callback(); + } + }); + } +} + -- cgit v1.2.3