Extension: Make extension global
This commit is contained in:
@@ -9,6 +9,6 @@ rules:
|
||||
argsIgnorePattern: ^(unused|_)
|
||||
object-curly-spacing: off
|
||||
globals:
|
||||
NTSMetadata: writable
|
||||
NTS: writable
|
||||
parserOptions:
|
||||
sourceType: module
|
||||
|
||||
+2
-2
@@ -7,6 +7,6 @@
|
||||
* @param {string} msg Message to print.
|
||||
*/
|
||||
export function message(msg) {
|
||||
if (NTSMetadata['build-type'] === 'debug')
|
||||
console.log(`[${NTSMetadata.name}] ${msg}`);
|
||||
if (NTS.metadata['build-type'] === 'debug')
|
||||
console.log(`[${NTS.metadata.name}] ${msg}`);
|
||||
}
|
||||
|
||||
+6
-10
@@ -16,20 +16,16 @@ export default class NightThemeSwitcher extends Extension {
|
||||
#modules = [];
|
||||
|
||||
enable() {
|
||||
globalThis.NTSMetadata = this.metadata;
|
||||
globalThis.NTS = this;
|
||||
|
||||
debug.message('Enabling extension...');
|
||||
|
||||
const timer = new Timer({
|
||||
settings: this.getSettings(`${this.metadata['settings-schema']}.time`),
|
||||
colorSchemeSettings: this.getSettings(`${this.metadata['settings-schema']}.color-scheme`),
|
||||
openPreferences: this.openPreferences,
|
||||
});
|
||||
this.#modules.push(timer);
|
||||
const timer = new Timer();
|
||||
|
||||
[
|
||||
new ColorSchemeSwitcher({ timer, settings: this.getSettings(`${this.metadata['settings-schema']}.color-scheme`) }),
|
||||
new CommandsSwitcher({ timer, settings: this.getSettings(`${this.metadata['settings-schema']}.commands`) }),
|
||||
timer,
|
||||
new ColorSchemeSwitcher({ timer }),
|
||||
new CommandsSwitcher({ timer }),
|
||||
].forEach(module => this.#modules.push(module));
|
||||
|
||||
this.#modules.forEach(module => module.enable());
|
||||
@@ -48,6 +44,6 @@ export default class NightThemeSwitcher extends Extension {
|
||||
|
||||
debug.message('Extension disabled.');
|
||||
|
||||
delete globalThis.NTSMetadata;
|
||||
delete globalThis.NTS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,12 @@ export class ColorSchemeSwitcher extends Switcher {
|
||||
|
||||
#settingsConnections = [];
|
||||
|
||||
constructor({ timer, settings }) {
|
||||
/**
|
||||
* @param {object} params Params object.
|
||||
* @param {Timer} params.timer Timer to listen to.
|
||||
*/
|
||||
constructor({ timer }) {
|
||||
const settings = NTS.getSettings(`${NTS.metadata['settings-schema']}.color-scheme`);
|
||||
super({
|
||||
name: 'Color Scheme',
|
||||
timer,
|
||||
|
||||
@@ -19,9 +19,9 @@ export class CommandsSwitcher extends Switcher {
|
||||
/**
|
||||
* @param {object} params Params object.
|
||||
* @param {Timer} params.timer Timer to listen to.
|
||||
* @param {Gio.Settings} params.settings Commands settings.
|
||||
*/
|
||||
constructor({ timer, settings }) {
|
||||
constructor({ timer }) {
|
||||
const settings = NTS.getSettings(`${NTS.metadata['settings-schema']}.commands`);
|
||||
super({
|
||||
name: 'Command',
|
||||
timer,
|
||||
|
||||
+9
-17
@@ -32,7 +32,6 @@ export class Timer extends GObject.Object {
|
||||
#colorSchemeSettings;
|
||||
#interfaceSettings;
|
||||
#locationSettings;
|
||||
#openPreferences;
|
||||
#time;
|
||||
|
||||
#cancellable = null;
|
||||
@@ -53,19 +52,12 @@ export class Timer extends GObject.Object {
|
||||
}, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} params Params object.
|
||||
* @param {Gio.Settings} params.settings Timer settings.
|
||||
* @param {Gio.Settings} params.colorSchemeSettings Color Scheme settings.
|
||||
* @param {Function} params.openPreferences Function opening the extension preferences.
|
||||
*/
|
||||
constructor({ settings, colorSchemeSettings, openPreferences }) {
|
||||
constructor() {
|
||||
super();
|
||||
this.#settings = settings;
|
||||
this.#colorSchemeSettings = colorSchemeSettings;
|
||||
this.#settings = NTS.getSettings(`${NTS.metadata['settings-schema']}.time`);
|
||||
this.#colorSchemeSettings = NTS.getSettings(`${NTS.metadata['settings-schema']}.color-scheme`);
|
||||
this.#interfaceSettings = new Gio.Settings({ schema: 'org.gnome.desktop.interface' });
|
||||
this.#locationSettings = new Gio.Settings({ schema: 'org.gnome.system.location' });
|
||||
this.#openPreferences = openPreferences;
|
||||
}
|
||||
|
||||
enable() {
|
||||
@@ -276,14 +268,14 @@ export class Timer extends GObject.Object {
|
||||
} catch (e) {
|
||||
const [latitude, longitude] = this.#settings.get_value('location').deepUnpack();
|
||||
if (latitude >= -90 && latitude <= 90 && longitude >= -180 && longitude <= 180) {
|
||||
console.error(`[${NTSMetadata.name}] Unable to retrieve the location, using the last known location instead.\n${e}`);
|
||||
console.error(`[${NTS.metadata.name}] Unable to retrieve the location, using the last known location instead.\n${e}`);
|
||||
this.#updateSuntimes();
|
||||
} else {
|
||||
console.error(`[${NTSMetadata.name}] Unable to retrieve the location, using the manual schedule times instead.\n${e}`);
|
||||
console.error(`[${NTS.metadata.name}] Unable to retrieve the location, using the manual schedule times instead.\n${e}`);
|
||||
|
||||
const source = new MessageTray.Source({
|
||||
title: NTSMetadata.name,
|
||||
icon: Gio.icon_new_for_string(GLib.build_filenamev([NTSMetadata.path, 'icons', 'nightthemeswitcher-symbolic.svg'])),
|
||||
title: NTS.metadata.name,
|
||||
icon: Gio.icon_new_for_string(GLib.build_filenamev([NTS.metadata.path, 'icons', 'nightthemeswitcher-symbolic.svg'])),
|
||||
});
|
||||
messageTray.add(source);
|
||||
|
||||
@@ -295,9 +287,9 @@ export class Timer extends GObject.Object {
|
||||
'icon-name': 'location-services-disabled-symbolic',
|
||||
}
|
||||
);
|
||||
notification.addAction(_('Edit Manual Schedule'), () => this.#openPreferences());
|
||||
notification.addAction(_('Edit Manual Schedule'), () => NTS.openPreferences());
|
||||
|
||||
notification.connect('activated', () => this.#openPreferences());
|
||||
notification.connect('activated', () => NTS.openPreferences());
|
||||
|
||||
source.addNotification(notification);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user