diff options
Diffstat (limited to 'src/background/usecases/SettingUseCase.ts')
-rw-r--r-- | src/background/usecases/SettingUseCase.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/background/usecases/SettingUseCase.ts b/src/background/usecases/SettingUseCase.ts new file mode 100644 index 0000000..aa3b534 --- /dev/null +++ b/src/background/usecases/SettingUseCase.ts @@ -0,0 +1,31 @@ +// eslint-disable-next-line max-len +import PersistentSettingRepository from '../repositories/PersistentSettingRepository'; +import SettingRepository from '../repositories/SettingRepository'; +import { DefaultSettingData } from '../../shared/SettingData'; +import Settings from '../../shared/Settings'; + +export default class SettingUseCase { + private persistentSettingRepository: PersistentSettingRepository; + + private settingRepository: SettingRepository; + + constructor() { + this.persistentSettingRepository = new PersistentSettingRepository(); + this.settingRepository = new SettingRepository(); + } + + get(): Promise<Settings> { + return this.settingRepository.get(); + } + + async reload(): Promise<Settings> { + let data = await this.persistentSettingRepository.load(); + if (!data) { + data = DefaultSettingData; + } + + let value = data.toSettings(); + this.settingRepository.update(value); + return value; + } +} |