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