aboutsummaryrefslogtreecommitdiff
path: root/src/content/usecases
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/usecases')
-rw-r--r--src/content/usecases/AddonEnabledUseCase.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/content/usecases/AddonEnabledUseCase.ts b/src/content/usecases/AddonEnabledUseCase.ts
new file mode 100644
index 0000000..e9ce0a6
--- /dev/null
+++ b/src/content/usecases/AddonEnabledUseCase.ts
@@ -0,0 +1,40 @@
+import AddonIndicatorClient, { AddonIndicatorClientImpl }
+ from '../client/AddonIndicatorClient';
+import AddonEnabledRepository, { AddonEnabledRepositoryImpl }
+ from '../repositories/AddonEnabledRepository';
+
+export default class AddonEnabledUseCase {
+ private indicator: AddonIndicatorClient;
+
+ private repository: AddonEnabledRepository;
+
+ constructor({
+ indicator = new AddonIndicatorClientImpl(),
+ repository = new AddonEnabledRepositoryImpl(),
+ } = {}) {
+ this.indicator = indicator;
+ this.repository = repository;
+ }
+
+ async enable(): Promise<void> {
+ await this.setEnabled(true);
+ }
+
+ async disable(): Promise<void> {
+ await this.setEnabled(false);
+ }
+
+ async toggle(): Promise<void> {
+ let current = this.repository.get();
+ await this.setEnabled(!current);
+ }
+
+ getEnabled(): boolean {
+ return this.repository.get();
+ }
+
+ private async setEnabled(on: boolean): Promise<void> {
+ this.repository.set(on);
+ await this.indicator.setEnabled(on);
+ }
+}