aboutsummaryrefslogtreecommitdiff
path: root/src/background
diff options
context:
space:
mode:
Diffstat (limited to 'src/background')
-rw-r--r--src/background/Application.ts11
-rw-r--r--src/background/controllers/SettingController.ts2
-rw-r--r--src/background/repositories/CachedSettingRepository.ts (renamed from src/background/repositories/SettingRepository.ts)2
-rw-r--r--src/background/repositories/LocalSettingRepository.ts (renamed from src/background/repositories/PersistentSettingRepository.ts)13
-rw-r--r--src/background/usecases/CommandUseCase.ts4
-rw-r--r--src/background/usecases/CompletionsUseCase.ts4
-rw-r--r--src/background/usecases/SettingUseCase.ts17
7 files changed, 30 insertions, 23 deletions
diff --git a/src/background/Application.ts b/src/background/Application.ts
index 08013cd..d5e7a67 100644
--- a/src/background/Application.ts
+++ b/src/background/Application.ts
@@ -2,6 +2,7 @@ import { injectable } from 'tsyringe';
import ContentMessageListener from './infrastructures/ContentMessageListener';
import SettingController from './controllers/SettingController';
import VersionController from './controllers/VersionController';
+import LocalSettingRepository from "./repositories/LocalSettingRepository";
@injectable()
export default class Application {
@@ -9,6 +10,7 @@ export default class Application {
private contentMessageListener: ContentMessageListener,
private settingController: SettingController,
private versionController: VersionController,
+ private localSettingRepository: LocalSettingRepository
) {
}
@@ -23,13 +25,8 @@ export default class Application {
});
this.contentMessageListener.run();
- browser.storage.onChanged.addListener((changes, area) => {
- if (area !== 'local') {
- return;
- }
- if (changes.settings) {
- this.settingController.reload();
- }
+ this.localSettingRepository.onChange(() => {
+ this.settingController.reload();
});
}
}
diff --git a/src/background/controllers/SettingController.ts b/src/background/controllers/SettingController.ts
index 8d05852..26edc07 100644
--- a/src/background/controllers/SettingController.ts
+++ b/src/background/controllers/SettingController.ts
@@ -12,7 +12,7 @@ export default class SettingController {
}
getSetting(): Promise<Settings> {
- return this.settingUseCase.get();
+ return this.settingUseCase.getCached();
}
async reload(): Promise<any> {
diff --git a/src/background/repositories/SettingRepository.ts b/src/background/repositories/CachedSettingRepository.ts
index ba24e36..b73d94a 100644
--- a/src/background/repositories/SettingRepository.ts
+++ b/src/background/repositories/CachedSettingRepository.ts
@@ -6,7 +6,7 @@ import Properties from '../../shared/settings/Properties';
const CACHED_SETTING_KEY = 'setting';
@injectable()
-export default class SettingRepository {
+export default class CachedSettingRepository {
private cache: MemoryStorage;
constructor() {
diff --git a/src/background/repositories/PersistentSettingRepository.ts b/src/background/repositories/LocalSettingRepository.ts
index c10f2cf..285b207 100644
--- a/src/background/repositories/PersistentSettingRepository.ts
+++ b/src/background/repositories/LocalSettingRepository.ts
@@ -2,7 +2,7 @@ import { injectable } from 'tsyringe';
import SettingData from '../../shared/SettingData';
@injectable()
-export default class SettingRepository {
+export default class LocalSettingRepository {
async load(): Promise<SettingData | null> {
const { settings } = await browser.storage.local.get('settings');
if (!settings) {
@@ -10,5 +10,16 @@ export default class SettingRepository {
}
return SettingData.fromJSON(settings as any);
}
+
+ onChange(callback: () => void) {
+ browser.storage.onChanged.addListener((changes, area) => {
+ if (area !== 'local') {
+ return;
+ }
+ if (changes.settings) {
+ callback();
+ }
+ });
+ }
}
diff --git a/src/background/usecases/CommandUseCase.ts b/src/background/usecases/CommandUseCase.ts
index fcb898d..20ded7e 100644
--- a/src/background/usecases/CommandUseCase.ts
+++ b/src/background/usecases/CommandUseCase.ts
@@ -5,7 +5,7 @@ import * as urls from '../../shared/urls';
import TabPresenter from '../presenters/TabPresenter';
import WindowPresenter from '../presenters/WindowPresenter';
import HelpPresenter from '../presenters/HelpPresenter';
-import SettingRepository from '../repositories/SettingRepository';
+import CachedSettingRepository from '../repositories/CachedSettingRepository';
import BookmarkRepository from '../repositories/BookmarkRepository';
import ConsoleClient from '../infrastructures/ConsoleClient';
import ContentMessageClient from '../infrastructures/ContentMessageClient';
@@ -17,7 +17,7 @@ export default class CommandIndicator {
private tabPresenter: TabPresenter,
private windowPresenter: WindowPresenter,
private helpPresenter: HelpPresenter,
- private settingRepository: SettingRepository,
+ private settingRepository: CachedSettingRepository,
private bookmarkRepository: BookmarkRepository,
private consoleClient: ConsoleClient,
private contentMessageClient: ContentMessageClient,
diff --git a/src/background/usecases/CompletionsUseCase.ts b/src/background/usecases/CompletionsUseCase.ts
index 779c61d..72ba929 100644
--- a/src/background/usecases/CompletionsUseCase.ts
+++ b/src/background/usecases/CompletionsUseCase.ts
@@ -3,7 +3,7 @@ import CompletionGroup from '../domains/CompletionGroup';
import CommandDocs from '../domains/CommandDocs';
import CompletionsRepository from '../repositories/CompletionsRepository';
import * as filters from './filters';
-import SettingRepository from '../repositories/SettingRepository';
+import CachedSettingRepository from '../repositories/CachedSettingRepository';
import TabPresenter from '../presenters/TabPresenter';
import Properties from '../../shared/settings/Properties';
@@ -17,7 +17,7 @@ export default class CompletionsUseCase {
constructor(
private tabPresenter: TabPresenter,
private completionsRepository: CompletionsRepository,
- private settingRepository: SettingRepository,
+ private settingRepository: CachedSettingRepository,
) {
}
diff --git a/src/background/usecases/SettingUseCase.ts b/src/background/usecases/SettingUseCase.ts
index d78d440..bd61157 100644
--- a/src/background/usecases/SettingUseCase.ts
+++ b/src/background/usecases/SettingUseCase.ts
@@ -1,7 +1,6 @@
import { injectable } from 'tsyringe';
-import PersistentSettingRepository
- from '../repositories/PersistentSettingRepository';
-import SettingRepository from '../repositories/SettingRepository';
+import LocalSettingRepository from '../repositories/LocalSettingRepository';
+import CachedSettingRepository from '../repositories/CachedSettingRepository';
import { DefaultSettingData } from '../../shared/SettingData';
import Settings from '../../shared/settings/Settings';
import NotifyPresenter from '../presenters/NotifyPresenter';
@@ -10,20 +9,20 @@ import NotifyPresenter from '../presenters/NotifyPresenter';
export default class SettingUseCase {
constructor(
- private persistentSettingRepository: PersistentSettingRepository,
- private settingRepository: SettingRepository,
+ private localSettingRepository: LocalSettingRepository,
+ private cachedSettingRepository: CachedSettingRepository,
private notifyPresenter: NotifyPresenter,
) {
}
- get(): Promise<Settings> {
- return this.settingRepository.get();
+ getCached(): Promise<Settings> {
+ return this.cachedSettingRepository.get();
}
async reload(): Promise<Settings> {
let data;
try {
- data = await this.persistentSettingRepository.load();
+ data = await this.localSettingRepository.load();
} catch (e) {
this.showUnableToLoad(e);
}
@@ -38,7 +37,7 @@ export default class SettingUseCase {
this.showUnableToLoad(e);
value = DefaultSettingData.toSettings();
}
- this.settingRepository.update(value!!);
+ this.cachedSettingRepository.update(value!!);
return value;
}