aboutsummaryrefslogtreecommitdiff
path: root/src/background/usecases/SettingUseCase.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/background/usecases/SettingUseCase.ts')
-rw-r--r--src/background/usecases/SettingUseCase.ts23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/background/usecases/SettingUseCase.ts b/src/background/usecases/SettingUseCase.ts
index bd61157..02e1240 100644
--- a/src/background/usecases/SettingUseCase.ts
+++ b/src/background/usecases/SettingUseCase.ts
@@ -1,15 +1,17 @@
import { injectable } from 'tsyringe';
import LocalSettingRepository from '../repositories/LocalSettingRepository';
import CachedSettingRepository from '../repositories/CachedSettingRepository';
-import { DefaultSettingData } from '../../shared/SettingData';
+import SettingData, { DefaultSettingData } from '../../shared/SettingData';
import Settings from '../../shared/settings/Settings';
import NotifyPresenter from '../presenters/NotifyPresenter';
+import SyncSettingRepository from "../repositories/SyncSettingRepository";
@injectable()
export default class SettingUseCase {
constructor(
private localSettingRepository: LocalSettingRepository,
+ private syncSettingRepository: SyncSettingRepository,
private cachedSettingRepository: CachedSettingRepository,
private notifyPresenter: NotifyPresenter,
) {
@@ -20,15 +22,12 @@ export default class SettingUseCase {
}
async reload(): Promise<Settings> {
- let data;
+ let data = DefaultSettingData;
try {
- data = await this.localSettingRepository.load();
+ data = await this.loadSettings();
} catch (e) {
this.showUnableToLoad(e);
}
- if (!data) {
- data = DefaultSettingData;
- }
let value: Settings;
try {
@@ -41,6 +40,18 @@ export default class SettingUseCase {
return value;
}
+ private async loadSettings(): Promise<SettingData> {
+ const sync = await this.syncSettingRepository.load();
+ if (sync) {
+ return sync;
+ }
+ const local = await this.localSettingRepository.load();
+ if (local) {
+ return local;
+ }
+ return DefaultSettingData;
+ }
+
private showUnableToLoad(e: Error) {
console.error('unable to load settings', e);
this.notifyPresenter.notifyInvalidSettings(() => {