From 05d0804f21b111b4802e6314bae481123d6ceff5 Mon Sep 17 00:00:00 2001 From: Aaron Yarborough Date: Sat, 11 Apr 2020 20:21:26 +0100 Subject: [PATCH] Abstract preferences into PreferenceManager class. --- src/content.ts | 36 ++++++----------------------------- src/popup.html | 5 +++++ src/{popup.js => popup.ts} | 0 src/preferences-repository.ts | 22 +++++++++++++++++++++ 4 files changed, 33 insertions(+), 30 deletions(-) rename src/{popup.js => popup.ts} (100%) create mode 100644 src/preferences-repository.ts diff --git a/src/content.ts b/src/content.ts index 0843f2c..24a1cd1 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1,5 +1,6 @@ import { TwitterHider } from './hider'; import { Preferences } from './interfaces/preferences'; +import { PreferencesRepository } from './preferences-repository'; class Background { static async init(): Promise { @@ -7,43 +8,18 @@ class Background { await this.setup(); } - this.listen(); - } - - static async listen(): Promise { - const preferences: Preferences = await this.getSavedPreferences(); + const preferences: Preferences = await PreferencesRepository.get(); const hider = new TwitterHider(preferences); hider.init(); } - static setup(): Promise { - const defaults = { - hideLikes: true, - hideRetweets: true, - hideReplies: true, - setup: true - }; - - return new Promise(resolve => { - globalThis.chrome.storage.local.set(defaults, () => resolve()); - }); + private static async setup(): Promise { + await PreferencesRepository.set(PreferencesRepository.DefaultPreferences); } - static checkIfFirstStart(): Promise { - return new Promise(resolve => { - globalThis.chrome.storage.local.get('setup', data => { - resolve(!data.setup); - }); - }); - } - - static getSavedPreferences(): Promise { - return new Promise(resolve => { - globalThis.chrome.storage.local.get(['hideLikes', 'hideReplies', 'hideRetweets'], (data: Preferences) => { - resolve(data); - }); - }) + private static async checkIfFirstStart(): Promise { + return !(await PreferencesRepository.get()); } } diff --git a/src/popup.html b/src/popup.html index 2882288..6d5222c 100644 --- a/src/popup.html +++ b/src/popup.html @@ -26,6 +26,11 @@ + +
+ + +