Put extension in a class
This commit is contained in:
+55
-64
@@ -17,82 +17,68 @@ const { Timer } = Me.imports.modules.Timer;
|
|||||||
|
|
||||||
|
|
||||||
var enabled = false;
|
var enabled = false;
|
||||||
var timer = null;
|
|
||||||
var switcherThemeGtk = null;
|
|
||||||
var switcherThemeShell = null;
|
|
||||||
var switcherThemeIcon = null;
|
|
||||||
var switcherThemeCursor = null;
|
|
||||||
var switcherCommands = null;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
class NightThemeSwitcher {
|
||||||
* Extension initialization.
|
#timer = null;
|
||||||
*/
|
#switcherThemeGtk = null;
|
||||||
function init() {
|
#switcherThemeShell = null;
|
||||||
|
#switcherThemeIcon = null;
|
||||||
|
#switcherThemeCursor = null;
|
||||||
|
#switcherCommands = null;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
console.debug('Initializing extension...');
|
console.debug('Initializing extension...');
|
||||||
extensionUtils.initTranslations();
|
extensionUtils.initTranslations();
|
||||||
_migrateBackgroundSettings();
|
this.#migrateBackgroundSettings();
|
||||||
console.debug('Extension initialized.');
|
console.debug('Extension initialized.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
enable() {
|
||||||
* When the extension is enabled, we wait for the Extension Manager to be
|
this.#waitForExtensionManager().then(() => this.start());
|
||||||
* initialized before starting.
|
}
|
||||||
*/
|
|
||||||
function enable() {
|
|
||||||
_waitForExtensionManager().then(() => start());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
start() {
|
||||||
* When the extension is started, we create and enable all the modules.
|
console.debug('Starting extension...');
|
||||||
*/
|
this.#timer = new Timer();
|
||||||
function start() {
|
this.#switcherThemeGtk = new SwitcherThemeGtk({ timer: this.#timer });
|
||||||
console.debug('Enabling extension...');
|
this.#switcherThemeIcon = new SwitcherThemeIcon({ timer: this.#timer });
|
||||||
timer = new Timer();
|
this.#switcherThemeShell = new SwitcherThemeShell({ timer: this.#timer });
|
||||||
switcherThemeGtk = new SwitcherThemeGtk({ timer });
|
this.#switcherThemeCursor = new SwitcherThemeCursor({ timer: this.#timer });
|
||||||
switcherThemeIcon = new SwitcherThemeIcon({ timer });
|
this.#switcherCommands = new SwitcherCommands({ timer: this.#timer });
|
||||||
switcherThemeShell = new SwitcherThemeShell({ timer });
|
|
||||||
switcherThemeCursor = new SwitcherThemeCursor({ timer });
|
|
||||||
switcherCommands = new SwitcherCommands({ timer });
|
|
||||||
|
|
||||||
timer.enable();
|
this.#timer.enable();
|
||||||
switcherThemeGtk.enable();
|
this.#switcherThemeGtk.enable();
|
||||||
switcherThemeShell.enable();
|
this.#switcherThemeShell.enable();
|
||||||
switcherThemeIcon.enable();
|
this.#switcherThemeIcon.enable();
|
||||||
switcherThemeCursor.enable();
|
this.#switcherThemeCursor.enable();
|
||||||
switcherCommands.enable();
|
this.#switcherCommands.enable();
|
||||||
|
|
||||||
enabled = true;
|
enabled = true;
|
||||||
console.debug('Extension enabled.');
|
console.debug('Extension started.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
disable() {
|
||||||
* When the extension is disabled, we disable and remove all the modules.
|
|
||||||
*/
|
|
||||||
function disable() {
|
|
||||||
console.debug('Disabling extension...');
|
console.debug('Disabling extension...');
|
||||||
enabled = false;
|
enabled = false;
|
||||||
|
|
||||||
switcherThemeGtk.disable();
|
this.#switcherThemeGtk.disable();
|
||||||
switcherThemeShell.disable();
|
this.#switcherThemeShell.disable();
|
||||||
switcherThemeIcon.disable();
|
this.#switcherThemeIcon.disable();
|
||||||
switcherThemeCursor.disable();
|
this.#switcherThemeCursor.disable();
|
||||||
switcherCommands.disable();
|
this.#switcherCommands.disable();
|
||||||
timer.disable();
|
this.#timer.disable();
|
||||||
|
|
||||||
timer = null;
|
this.#timer = null;
|
||||||
switcherThemeGtk = null;
|
this.#switcherThemeGtk = null;
|
||||||
switcherThemeShell = null;
|
this.#switcherThemeShell = null;
|
||||||
switcherThemeIcon = null;
|
this.#switcherThemeIcon = null;
|
||||||
switcherThemeCursor = null;
|
this.#switcherThemeCursor = null;
|
||||||
switcherCommands = null;
|
this.#switcherCommands = null;
|
||||||
console.debug('Extension disabled.');
|
console.debug('Extension disabled.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
#waitForExtensionManager() {
|
||||||
* Wait for the Extension Manager to be initialized. Returns a Promise.
|
|
||||||
*/
|
|
||||||
function _waitForExtensionManager() {
|
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
console.debug('Waiting for Extension Manager initialization...');
|
console.debug('Waiting for Extension Manager initialization...');
|
||||||
GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
|
GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
|
||||||
@@ -103,12 +89,9 @@ function _waitForExtensionManager() {
|
|||||||
console.debug('Extension Manager initialized.');
|
console.debug('Extension Manager initialized.');
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
#migrateBackgroundSettings() {
|
||||||
* Migrate background settings from the extension to the system.
|
|
||||||
*/
|
|
||||||
function _migrateBackgroundSettings() {
|
|
||||||
const systemSettings = new Gio.Settings({ schema: 'org.gnome.desktop.background' });
|
const systemSettings = new Gio.Settings({ schema: 'org.gnome.desktop.background' });
|
||||||
const extensionSettings = extensionUtils.getSettings(utils.getSettingsSchema('backgrounds'));
|
const extensionSettings = extensionUtils.getSettings(utils.getSettingsSchema('backgrounds'));
|
||||||
|
|
||||||
@@ -122,4 +105,12 @@ function _migrateBackgroundSettings() {
|
|||||||
systemSettings.set_string('picture-uri-dark', extensionSettings.get_string('night'));
|
systemSettings.set_string('picture-uri-dark', extensionSettings.get_string('night'));
|
||||||
extensionSettings.set_string('night', '');
|
extensionSettings.set_string('night', '');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extension initialization.
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
return new NightThemeSwitcher();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user