Extension: Simplify enabling and disabling

This commit is contained in:
Romain Vigier
2022-09-08 09:51:23 +02:00
parent 2576db4ea0
commit 4f24db17cf
+15 -42
View File
@@ -16,12 +16,7 @@ const { Timer } = Me.imports.modules.Timer;
class NightThemeSwitcher { class NightThemeSwitcher {
#timer = null; #modules = [];
#switcherThemeGtk = null;
#switcherThemeShell = null;
#switcherThemeIcon = null;
#switcherThemeCursor = null;
#switcherCommands = null;
constructor() { constructor() {
debug.message('Initializing extension...'); debug.message('Initializing extension...');
@@ -31,19 +26,19 @@ class NightThemeSwitcher {
enable() { enable() {
debug.message('Enabling extension...'); debug.message('Enabling extension...');
this.#timer = new Timer();
this.#switcherThemeGtk = new SwitcherThemeGtk({ timer: this.#timer });
this.#switcherThemeIcon = new SwitcherThemeIcon({ timer: this.#timer });
this.#switcherThemeShell = new SwitcherThemeShell({ timer: this.#timer });
this.#switcherThemeCursor = new SwitcherThemeCursor({ timer: this.#timer });
this.#switcherCommands = new SwitcherCommands({ timer: this.#timer });
this.#timer.enable(); const timer = new Timer();
this.#switcherThemeGtk.enable(); this.#modules.push(timer);
this.#switcherThemeShell.enable();
this.#switcherThemeIcon.enable(); [
this.#switcherThemeCursor.enable(); SwitcherThemeGtk,
this.#switcherCommands.enable(); SwitcherThemeIcon,
SwitcherThemeShell,
SwitcherThemeCursor,
SwitcherCommands,
].forEach(SwitcherModule => this.#modules.push(new SwitcherModule({ timer })));
this.#modules.forEach(module => module.enable());
debug.message('Extension enabled.'); debug.message('Extension enabled.');
} }
@@ -54,30 +49,8 @@ class NightThemeSwitcher {
// as the background image and the shell theme are visible in this mode. // as the background image and the shell theme are visible in this mode.
debug.message('Disabling extension...'); debug.message('Disabling extension...');
if (this.#switcherThemeGtk) { this.#modules.forEach(module => module.disable());
this.#switcherThemeGtk.disable(); this.#modules = [];
this.#switcherThemeGtk = null;
}
if (this.#switcherThemeShell) {
this.#switcherThemeShell.disable();
this.#switcherThemeShell = null;
}
if (this.#switcherThemeIcon) {
this.#switcherThemeIcon.disable();
this.#switcherThemeIcon = null;
}
if (this.#switcherThemeCursor) {
this.#switcherThemeCursor.disable();
this.#switcherThemeCursor = null;
}
if (this.#switcherCommands) {
this.#switcherCommands.disable();
this.#switcherCommands = null;
}
if (this.#timer) {
this.#timer.disable();
this.#timer = null;
}
debug.message('Extension disabled.'); debug.message('Extension disabled.');
} }