aboutsummaryrefslogtreecommitdiff
path: root/src/background/repositories/LocalSettingRepository.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/background/repositories/LocalSettingRepository.ts')
-rw-r--r--src/background/repositories/LocalSettingRepository.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/background/repositories/LocalSettingRepository.ts b/src/background/repositories/LocalSettingRepository.ts
new file mode 100644
index 0000000..285b207
--- /dev/null
+++ b/src/background/repositories/LocalSettingRepository.ts
@@ -0,0 +1,25 @@
+import { injectable } from 'tsyringe';
+import SettingData from '../../shared/SettingData';
+
+@injectable()
+export default class LocalSettingRepository {
+ async load(): Promise<SettingData | null> {
+ const { settings } = await browser.storage.local.get('settings');
+ if (!settings) {
+ return null;
+ }
+ return SettingData.fromJSON(settings as any);
+ }
+
+ onChange(callback: () => void) {
+ browser.storage.onChanged.addListener((changes, area) => {
+ if (area !== 'local') {
+ return;
+ }
+ if (changes.settings) {
+ callback();
+ }
+ });
+ }
+}
+