Use ESLint and reformat code
This commit is contained in:
+86
-81
@@ -16,13 +16,12 @@ You should have received a copy of the GNU General Public License along with
|
||||
this program. If not, see <http s ://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const { GLib } = imports.gi;
|
||||
const { extensionUtils } = imports.misc;
|
||||
|
||||
const Me = extensionUtils.getCurrentExtension();
|
||||
|
||||
const e = Me.imports.extension;
|
||||
const { log_debug } = Me.imports.utils;
|
||||
const { logDebug } = Me.imports.utils;
|
||||
|
||||
/**
|
||||
* The Backgrounder is responsible for changing the desktop background
|
||||
@@ -33,98 +32,104 @@ const { log_debug } = Me.imports.utils;
|
||||
*/
|
||||
var Backgrounder = class {
|
||||
|
||||
enable() {
|
||||
log_debug('Enabling Backgrounder...');
|
||||
this._watch_status();
|
||||
if ( e.settingsManager.backgrounds_enabled ) {
|
||||
this._connect_settings();
|
||||
this._connect_timer();
|
||||
}
|
||||
log_debug('Backgrounder enabled.');
|
||||
}
|
||||
constructor() {
|
||||
this._backgroundsStatusChangedConnect = null;
|
||||
this._backgroundTimeChangedConnect = null;
|
||||
this._backgroundChangedConnect = null;
|
||||
this._timeChangedConnect = null;
|
||||
}
|
||||
|
||||
disable() {
|
||||
log_debug('Disabling Backgrounder...');
|
||||
this._disconnect_timer();
|
||||
this._disconnect_settings();
|
||||
this._unwatch_status();
|
||||
log_debug('Backgrounder disabled.');
|
||||
}
|
||||
enable() {
|
||||
logDebug('Enabling Backgrounder...');
|
||||
this._watchStatus();
|
||||
if (e.settingsManager.backgroundsEnabled) {
|
||||
this._connectSettings();
|
||||
this._connectTimer();
|
||||
}
|
||||
logDebug('Backgrounder enabled.');
|
||||
}
|
||||
|
||||
disable() {
|
||||
logDebug('Disabling Backgrounder...');
|
||||
this._disconnectTimer();
|
||||
this._disconnectSettings();
|
||||
this._unwatchStatus();
|
||||
logDebug('Backgrounder disabled.');
|
||||
}
|
||||
|
||||
|
||||
_watch_status() {
|
||||
log_debug('Watching backgrounds status...');
|
||||
this._backgrounds_status_changed_connect = e.settingsManager.connect('backgrounds-status-changed', this._on_backgrounds_status_changed.bind(this));
|
||||
}
|
||||
_watchStatus() {
|
||||
logDebug('Watching backgrounds status...');
|
||||
this._backgroundsStatusChangedConnect = e.settingsManager.connect('backgrounds-status-changed', this._onBackgroundsStatusChanged.bind(this));
|
||||
}
|
||||
|
||||
_unwatch_status() {
|
||||
if ( this._backgrounds_status_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._backgrounds_status_changed_connect);
|
||||
this._backgrounds_status_changed_connect = null;
|
||||
}
|
||||
log_debug('Stopped watching backgrounds status.');
|
||||
}
|
||||
_unwatchStatus() {
|
||||
if (this._backgroundsStatusChangedConnect) {
|
||||
e.settingsManager.disconnect(this._backgroundsStatusChangedConnect);
|
||||
this._backgroundsStatusChangedConnect = null;
|
||||
}
|
||||
logDebug('Stopped watching backgrounds status.');
|
||||
}
|
||||
|
||||
_connect_settings() {
|
||||
log_debug('Connecting Backgrounder to settings...');
|
||||
this._background_time_changed_connect = e.settingsManager.connect('background-time-changed', this._on_background_time_changed.bind(this));
|
||||
this._background_changed_connect = e.settingsManager.connect('background-changed', this._on_background_changed.bind(this));
|
||||
}
|
||||
_connectSettings() {
|
||||
logDebug('Connecting Backgrounder to settings...');
|
||||
this._backgroundTimeChangedConnect = e.settingsManager.connect('background-time-changed', this._onBackgroundTimeChanged.bind(this));
|
||||
this._backgroundChangedConnect = e.settingsManager.connect('background-changed', this._onBackgroundChanged.bind(this));
|
||||
}
|
||||
|
||||
_disconnect_settings() {
|
||||
if ( this._background_time_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._background_time_changed_connect);
|
||||
this._background_time_changed_connect = null;
|
||||
}
|
||||
if ( this._background_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._background_changed_connect);
|
||||
this._background_changed_connect = null;
|
||||
}
|
||||
log_debug('Disconnected Backgrounder from settings.');
|
||||
}
|
||||
_disconnectSettings() {
|
||||
if (this._backgroundTimeChangedConnect) {
|
||||
e.settingsManager.disconnect(this._backgroundTimeChangedConnect);
|
||||
this._backgroundTimeChangedConnect = null;
|
||||
}
|
||||
if (this._backgroundChangedConnect) {
|
||||
e.settingsManager.disconnect(this._backgroundChangedConnect);
|
||||
this._backgroundChangedConnect = null;
|
||||
}
|
||||
logDebug('Disconnected Backgrounder from settings.');
|
||||
}
|
||||
|
||||
_connect_timer() {
|
||||
log_debug('Connecting Backgrounder to Timer...');
|
||||
this._time_changed_connect = e.timer.connect('time-changed', this._on_time_changed.bind(this));
|
||||
}
|
||||
_connectTimer() {
|
||||
logDebug('Connecting Backgrounder to Timer...');
|
||||
this._timeChangedConnect = e.timer.connect('time-changed', this._onTimeChanged.bind(this));
|
||||
}
|
||||
|
||||
_disconnect_timer() {
|
||||
if ( this._time_changed_connect ) {
|
||||
e.timer.disconnect(this._time_changed_connect);
|
||||
this._time_changed_connect = null;
|
||||
}
|
||||
log_debug('Disconnected Backgrounder from Timer.');
|
||||
}
|
||||
_disconnectTimer() {
|
||||
if (this._timeChangedConnect) {
|
||||
e.timer.disconnect(this._timeChangedConnect);
|
||||
this._timeChangedConnect = null;
|
||||
}
|
||||
logDebug('Disconnected Backgrounder from Timer.');
|
||||
}
|
||||
|
||||
|
||||
_on_backgrounds_status_changed(settings, enabled) {
|
||||
this.disable();
|
||||
this.enable();
|
||||
}
|
||||
_onBackgroundsStatusChanged(_settings, _enabled) {
|
||||
this.disable();
|
||||
this.enable();
|
||||
}
|
||||
|
||||
_on_background_time_changed(settings, changed_background_time) {
|
||||
if ( changed_background_time === e.timer.time ) {
|
||||
this._change_background(changed_background_time);
|
||||
}
|
||||
}
|
||||
_onBackgroundTimeChanged(_settings, changedBackgroundTime) {
|
||||
if (changedBackgroundTime === e.timer.time)
|
||||
this._changeBackground(changedBackgroundTime);
|
||||
}
|
||||
|
||||
_on_background_changed(settings, new_background) {
|
||||
switch (e.timer.time) {
|
||||
case 'day':
|
||||
e.settingsManager.background_day = new_background;
|
||||
break;
|
||||
case 'night':
|
||||
e.settingsManager.background_night = new_background;
|
||||
}
|
||||
}
|
||||
_onBackgroundChanged(_settings, newBackground) {
|
||||
switch (e.timer.time) {
|
||||
case 'day':
|
||||
e.settingsManager.backgroundDay = newBackground;
|
||||
break;
|
||||
case 'night':
|
||||
e.settingsManager.backgroundNight = newBackground;
|
||||
}
|
||||
}
|
||||
|
||||
_on_time_changed(timer, new_time) {
|
||||
this._change_background(new_time);
|
||||
}
|
||||
_onTimeChanged(_timer, newTime) {
|
||||
this._changeBackground(newTime);
|
||||
}
|
||||
|
||||
|
||||
_change_background(time) {
|
||||
e.settingsManager.background = time === 'day' ? e.settingsManager.background_day : e.settingsManager.background_night;
|
||||
}
|
||||
_changeBackground(time) {
|
||||
e.settingsManager.background = time === 'day' ? e.settingsManager.backgroundDay : e.settingsManager.backgroundNight;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
+54
-50
@@ -22,7 +22,7 @@ const { extensionUtils } = imports.misc;
|
||||
const Me = extensionUtils.getCurrentExtension();
|
||||
|
||||
const e = Me.imports.extension;
|
||||
const { log_debug } = Me.imports.utils;
|
||||
const { logDebug } = Me.imports.utils;
|
||||
|
||||
|
||||
/**
|
||||
@@ -30,64 +30,68 @@ const { log_debug } = Me.imports.utils;
|
||||
*/
|
||||
var Commander = class {
|
||||
|
||||
enable() {
|
||||
log_debug('Enabling Commander...');
|
||||
this._watch_status();
|
||||
if ( e.settingsManager.commands_enabled ) {
|
||||
this._connect_timer();
|
||||
}
|
||||
log_debug('Commander enabled.');
|
||||
}
|
||||
constructor() {
|
||||
this._commandsStatusChangedConnect = null;
|
||||
this._timeChangedConnect = null;
|
||||
}
|
||||
|
||||
disable() {
|
||||
log_debug('Disabling Commander...');
|
||||
this._disconnect_timer();
|
||||
this._unwatch_status();
|
||||
log_debug('Commander disabled.');
|
||||
}
|
||||
enable() {
|
||||
logDebug('Enabling Commander...');
|
||||
this._watchStatus();
|
||||
if (e.settingsManager.commandsEnabled)
|
||||
this._connectTimer();
|
||||
logDebug('Commander enabled.');
|
||||
}
|
||||
|
||||
disable() {
|
||||
logDebug('Disabling Commander...');
|
||||
this._disconnectTimer();
|
||||
this._unwatchStatus();
|
||||
logDebug('Commander disabled.');
|
||||
}
|
||||
|
||||
|
||||
_watch_status() {
|
||||
log_debug('Watching commands status...');
|
||||
this._commands_status_changed_connect = e.settingsManager.connect('commands-status-changed', this._on_commands_status_changed.bind(this));
|
||||
}
|
||||
_watchStatus() {
|
||||
logDebug('Watching commands status...');
|
||||
this._commandsStatusChangedConnect = e.settingsManager.connect('commands-status-changed', this._onCommandsStatusChanged.bind(this));
|
||||
}
|
||||
|
||||
_unwatch_status() {
|
||||
if ( this._commands_status_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._commands_status_changed_connect);
|
||||
this._commands_status_changed_connect = null;
|
||||
}
|
||||
log_debug('Stopped watching commands status.');
|
||||
}
|
||||
_unwatchStatus() {
|
||||
if (this._commandsStatusChangedConnect) {
|
||||
e.settingsManager.disconnect(this._commandsStatusChangedConnect);
|
||||
this._commandsStatusChangedConnect = null;
|
||||
}
|
||||
logDebug('Stopped watching commands status.');
|
||||
}
|
||||
|
||||
_connect_timer() {
|
||||
log_debug('Connecting Commander to Timer...');
|
||||
this._time_changed_connect = e.timer.connect('time-changed', this._on_time_changed.bind(this));
|
||||
}
|
||||
_connectTimer() {
|
||||
logDebug('Connecting Commander to Timer...');
|
||||
this._timeChangedConnect = e.timer.connect('time-changed', this._onTimeChanged.bind(this));
|
||||
}
|
||||
|
||||
_disconnect_timer() {
|
||||
if ( this._time_changed_connect ) {
|
||||
e.timer.disconnect(this._time_changed_connect);
|
||||
this._time_changed_connect = null;
|
||||
}
|
||||
log_debug('Disconnecting Commander from Timer.');
|
||||
}
|
||||
_disconnectTimer() {
|
||||
if (this._timeChangedConnect) {
|
||||
e.timer.disconnect(this._timeChangedConnect);
|
||||
this._timeChangedConnect = null;
|
||||
}
|
||||
logDebug('Disconnecting Commander from Timer.');
|
||||
}
|
||||
|
||||
|
||||
_on_commands_status_changed(settings, enabled) {
|
||||
this.disable();
|
||||
this.enable();
|
||||
}
|
||||
_onCommandsStatusChanged(_settings, _enabled) {
|
||||
this.disable();
|
||||
this.enable();
|
||||
}
|
||||
|
||||
_on_time_changed(timer, new_time) {
|
||||
this._spawn_command(new_time);
|
||||
}
|
||||
_onTimeChanged(_timer, newTime) {
|
||||
this._spawnCommand(newTime);
|
||||
}
|
||||
|
||||
|
||||
_spawn_command(time) {
|
||||
const command = time === 'day' ? e.settingsManager.command_sunrise : e.settingsManager.command_sunset;
|
||||
GLib.spawn_async(null, ['sh', '-c', command], null, GLib.SpawnFlags.SEARCH_PATH, null);
|
||||
log_debug(`Spawned ${time} command.`);
|
||||
}
|
||||
_spawnCommand(time) {
|
||||
const command = time === 'day' ? e.settingsManager.commandSunrise : e.settingsManager.commandSunset;
|
||||
GLib.spawn_async(null, ['sh', '-c', command], null, GLib.SpawnFlags.SEARCH_PATH, null);
|
||||
logDebug(`Spawned ${time} command.`);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
+111
-105
@@ -22,7 +22,7 @@ const { main } = imports.ui;
|
||||
const Me = extensionUtils.getCurrentExtension();
|
||||
|
||||
const e = Me.imports.extension;
|
||||
const { log_debug } = Me.imports.utils;
|
||||
const { logDebug } = Me.imports.utils;
|
||||
|
||||
|
||||
/**
|
||||
@@ -31,125 +31,131 @@ const { log_debug } = Me.imports.utils;
|
||||
*/
|
||||
var CursorThemer = class {
|
||||
|
||||
enable() {
|
||||
log_debug('Enabling Cursor Themer...');
|
||||
this._watch_status();
|
||||
this._save_original_theme();
|
||||
if ( e.settingsManager.cursor_variants_enabled ) {
|
||||
this._connect_settings();
|
||||
this._connect_timer();
|
||||
}
|
||||
log_debug('Cursor Themer enabled.');
|
||||
}
|
||||
constructor() {
|
||||
this._cursorVariantsStatusChangedConnect = null;
|
||||
this._cursorVariantChangedConnect = null;
|
||||
this._cursorThemeChangedConnect = null;
|
||||
this._timeChangedConnect = null;
|
||||
}
|
||||
|
||||
disable() {
|
||||
log_debug('Disabling Cursor Themer...');
|
||||
this._disconnect_timer();
|
||||
this._disconnect_settings();
|
||||
this._reset_original_theme();
|
||||
this._unwatch_status();
|
||||
log_debug('Cursor Themer disabled.');
|
||||
}
|
||||
enable() {
|
||||
logDebug('Enabling Cursor Themer...');
|
||||
this._watchStatus();
|
||||
this._saveOriginalTheme();
|
||||
if (e.settingsManager.cursorVariantsEnabled) {
|
||||
this._connectSettings();
|
||||
this._connectTimer();
|
||||
}
|
||||
logDebug('Cursor Themer enabled.');
|
||||
}
|
||||
|
||||
disable() {
|
||||
logDebug('Disabling Cursor Themer...');
|
||||
this._disconnectTimer();
|
||||
this._disconnectSettings();
|
||||
this._resetOriginalTheme();
|
||||
this._unwatchStatus();
|
||||
logDebug('Cursor Themer disabled.');
|
||||
}
|
||||
|
||||
|
||||
_watch_status() {
|
||||
log_debug('Watching cursor variants status...');
|
||||
this._cursor_variants_status_changed_connect = e.settingsManager.connect('cursor-variants-status-changed', this._on_cursor_variants_status_changed.bind(this));
|
||||
}
|
||||
_watchStatus() {
|
||||
logDebug('Watching cursor variants status...');
|
||||
this._cursorVariantsStatusChangedConnect = e.settingsManager.connect('cursor-variants-status-changed', this._onCursorVariantsStatusChanged.bind(this));
|
||||
}
|
||||
|
||||
_unwatch_status() {
|
||||
if ( this._cursor_variants_status_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._cursor_variants_status_changed_connect);
|
||||
this._cursor_variants_status_changed_connect = null;
|
||||
}
|
||||
log_debug('Stopped watching cursor variants status.');
|
||||
}
|
||||
_unwatchStatus() {
|
||||
if (this._cursorVariantsStatusChangedConnect) {
|
||||
e.settingsManager.disconnect(this._cursorVariantsStatusChangedConnect);
|
||||
this._cursorVariantsStatusChangedConnect = null;
|
||||
}
|
||||
logDebug('Stopped watching cursor variants status.');
|
||||
}
|
||||
|
||||
_connect_settings() {
|
||||
log_debug('Connecting Cursor Themer to settings...');
|
||||
this._cursor_variant_changed_connect = e.settingsManager.connect('cursor-variant-changed', this._on_cursor_variant_changed.bind(this));
|
||||
this._cursor_theme_changed_connect = e.settingsManager.connect('cursor-theme-changed', this._on_cursor_theme_changed.bind(this));
|
||||
}
|
||||
_connectSettings() {
|
||||
logDebug('Connecting Cursor Themer to settings...');
|
||||
this._cursorVariantChangedConnect = e.settingsManager.connect('cursor-variant-changed', this._onCursorVariantChanged.bind(this));
|
||||
this._cursorThemeChangedConnect = e.settingsManager.connect('cursor-theme-changed', this._onCursorThemeChanged.bind(this));
|
||||
}
|
||||
|
||||
_disconnect_settings() {
|
||||
if ( this._cursor_variant_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._cursor_variant_changed_connect);
|
||||
this._cursor_variant_changed_connect = null;
|
||||
}
|
||||
if ( this._cursor_theme_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._cursor_theme_changed_connect);
|
||||
this._cursor_theme_changed_connect = null;
|
||||
}
|
||||
log_debug('Disconnected Cursor Themer from settings.');
|
||||
}
|
||||
_disconnectSettings() {
|
||||
if (this._cursorVariantChangedConnect) {
|
||||
e.settingsManager.disconnect(this._cursorVariantChangedConnect);
|
||||
this._cursorVariantChangedConnect = null;
|
||||
}
|
||||
if (this._cursorThemeChangedConnect) {
|
||||
e.settingsManager.disconnect(this._cursorThemeChangedConnect);
|
||||
this._cursorThemeChangedConnect = null;
|
||||
}
|
||||
logDebug('Disconnected Cursor Themer from settings.');
|
||||
}
|
||||
|
||||
_connect_timer() {
|
||||
log_debug('Connecting Cursor Themer to Timer...');
|
||||
this._time_changed_connect = e.timer.connect('time-changed', this._on_time_changed.bind(this));
|
||||
}
|
||||
_connectTimer() {
|
||||
logDebug('Connecting Cursor Themer to Timer...');
|
||||
this._timeChangedConnect = e.timer.connect('time-changed', this._onTimeChanged.bind(this));
|
||||
}
|
||||
|
||||
_disconnect_timer() {
|
||||
if ( this._time_changed_connect ) {
|
||||
e.timer.disconnect(this._time_changed_connect);
|
||||
this._time_changed_connect = null;
|
||||
}
|
||||
log_debug('Disconnected Cursor Themer from Timer.');
|
||||
}
|
||||
_disconnectTimer() {
|
||||
if (this._timeChangedConnect) {
|
||||
e.timer.disconnect(this._timeChangedConnect);
|
||||
this._timeChangedConnect = null;
|
||||
}
|
||||
logDebug('Disconnected Cursor Themer from Timer.');
|
||||
}
|
||||
|
||||
|
||||
_on_cursor_variants_status_changed(settings, enabled) {
|
||||
this.disable();
|
||||
this.enable();
|
||||
}
|
||||
_onCursorVariantsStatusChanged(_settings, _enabled) {
|
||||
this.disable();
|
||||
this.enable();
|
||||
}
|
||||
|
||||
_on_cursor_variant_changed(settings, changed_variant_time) {
|
||||
if ( changed_variant_time === e.timer.time ) {
|
||||
this._set_variant(changed_variant_time);
|
||||
}
|
||||
}
|
||||
_onCursorVariantChanged(_settings, changedVariantTime) {
|
||||
if (changedVariantTime === e.timer.time)
|
||||
this._setVariant(changedVariantTime);
|
||||
}
|
||||
|
||||
_on_cursor_theme_changed(settings, new_theme) {
|
||||
switch (e.timer.time) {
|
||||
case 'day':
|
||||
e.settingsManager.cursor_variant_day = new_theme;
|
||||
break;
|
||||
case 'night':
|
||||
e.settingsManager.cursor_variant_night = new_theme;
|
||||
}
|
||||
this._set_variant(e.timer.time);
|
||||
}
|
||||
_onCursorThemeChanged(_settings, newTheme) {
|
||||
switch (e.timer.time) {
|
||||
case 'day':
|
||||
e.settingsManager.cursorVariantDay = newTheme;
|
||||
break;
|
||||
case 'night':
|
||||
e.settingsManager.cursorVariantNight = newTheme;
|
||||
}
|
||||
this._setVariant(e.timer.time);
|
||||
}
|
||||
|
||||
_on_time_changed(timer, new_time) {
|
||||
this._set_variant(new_time);
|
||||
}
|
||||
_onTimeChanged(_timer, newTime) {
|
||||
this._setVariant(newTime);
|
||||
}
|
||||
|
||||
|
||||
_set_variant(time) {
|
||||
log_debug(`Setting the cursor ${time} variant...`);
|
||||
switch (time) {
|
||||
case 'day':
|
||||
e.settingsManager.cursor_theme = e.settingsManager.cursor_variant_day;
|
||||
break;
|
||||
case 'night':
|
||||
e.settingsManager.cursor_theme = e.settingsManager.cursor_variant_night;
|
||||
break;
|
||||
case 'original':
|
||||
e.settingsManager.cursor_theme = e.settingsManager.cursor_variant_original;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_setVariant(time) {
|
||||
logDebug(`Setting the cursor ${time} variant...`);
|
||||
switch (time) {
|
||||
case 'day':
|
||||
e.settingsManager.cursorTheme = e.settingsManager.cursorVariantDay;
|
||||
break;
|
||||
case 'night':
|
||||
e.settingsManager.cursorTheme = e.settingsManager.cursorVariantNight;
|
||||
break;
|
||||
case 'original':
|
||||
e.settingsManager.cursorTheme = e.settingsManager.cursorVariantOriginal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_save_original_theme() {
|
||||
e.settingsManager.cursor_variant_original = e.settingsManager.cursor_theme;
|
||||
}
|
||||
_saveOriginalTheme() {
|
||||
e.settingsManager.cursorVariantOriginal = e.settingsManager.cursorTheme;
|
||||
}
|
||||
|
||||
_reset_original_theme() {
|
||||
// We don't reset the theme when locking the session to prevent
|
||||
// flicker on unlocking
|
||||
if ( !main.screenShield.locked ) {
|
||||
log_debug('Resetting to the user\'s original cursor theme...');
|
||||
this._set_variant('original');
|
||||
}
|
||||
}
|
||||
_resetOriginalTheme() {
|
||||
// We don't reset the theme when locking the session to prevent
|
||||
// flicker on unlocking
|
||||
if (!main.screenShield.locked) {
|
||||
logDebug('Resetting to the user\'s original cursor theme...');
|
||||
this._setVariant('original');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
+133
-131
@@ -16,14 +16,13 @@ You should have received a copy of the GNU General Public License along with
|
||||
this program. If not, see <http s ://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const { Gio, GLib, Gtk } = imports.gi;
|
||||
const { extensionUtils } = imports.misc;
|
||||
const { main } = imports.ui;
|
||||
|
||||
const Me = extensionUtils.getCurrentExtension();
|
||||
|
||||
const e = Me.imports.extension;
|
||||
const { log_debug, log_error, get_installed_gtk_themes } = Me.imports.utils;
|
||||
const { logDebug, notifyError, getInstalledGtkThemes } = Me.imports.utils;
|
||||
const { GtkVariants } = Me.imports.modules.GtkVariants;
|
||||
|
||||
const Gettext = imports.gettext.domain(Me.metadata.uuid);
|
||||
@@ -43,155 +42,158 @@ const _ = Gettext.gettext;
|
||||
*/
|
||||
var GtkThemer = class {
|
||||
|
||||
enable() {
|
||||
log_debug('Enabling GTK Themer...');
|
||||
try {
|
||||
this._watch_status();
|
||||
this._save_original_theme();
|
||||
if ( e.settingsManager.gtk_variants_enabled ) {
|
||||
this._update_variants();
|
||||
this._connect_settings();
|
||||
this._connect_timer();
|
||||
}
|
||||
}
|
||||
catch(e) {
|
||||
log_error(e);
|
||||
}
|
||||
log_debug('GTK Themer enabled.');
|
||||
}
|
||||
constructor() {
|
||||
this._gtkVariantsStatusChangedConnect = null;
|
||||
this._gtkVariantChangedConnect = null;
|
||||
this._gtkThemeChangedConnect = null;
|
||||
this._timeChangedConnect = null;
|
||||
}
|
||||
|
||||
disable() {
|
||||
log_debug('Disabling GTK Themer...');
|
||||
this._disconnect_timer();
|
||||
this._disconnect_settings();
|
||||
this._reset_original_theme();
|
||||
this._unwatch_status();
|
||||
log_debug('GTK Themer disabled.');
|
||||
}
|
||||
enable() {
|
||||
logDebug('Enabling GTK Themer...');
|
||||
try {
|
||||
this._watchStatus();
|
||||
this._saveOriginalTheme();
|
||||
if (e.settingsManager.gtkVariantsEnabled) {
|
||||
this._updateVariants();
|
||||
this._connectSettings();
|
||||
this._connectTimer();
|
||||
}
|
||||
} catch (error) {
|
||||
notifyError(error);
|
||||
}
|
||||
logDebug('GTK Themer enabled.');
|
||||
}
|
||||
|
||||
disable() {
|
||||
logDebug('Disabling GTK Themer...');
|
||||
this._disconnectTimer();
|
||||
this._disconnectSettings();
|
||||
this._resetOriginalTheme();
|
||||
this._unwatchStatus();
|
||||
logDebug('GTK Themer disabled.');
|
||||
}
|
||||
|
||||
|
||||
_watch_status() {
|
||||
log_debug('Watching GTK variants status...');
|
||||
this._gtk_variants_status_changed_connect = e.settingsManager.connect('gtk-variants-status-changed', this._on_gtk_variants_status_changed.bind(this));
|
||||
}
|
||||
_watchStatus() {
|
||||
logDebug('Watching GTK variants status...');
|
||||
this._gtkVariantsStatusChangedConnect = e.settingsManager.connect('gtk-variants-status-changed', this._onGtkVariantsStatusChanged.bind(this));
|
||||
}
|
||||
|
||||
_unwatch_status() {
|
||||
if ( this._gtk_variants_status_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._gtk_variants_status_changed_connect);
|
||||
this._gtk_variants_status_changed_connect = null;
|
||||
}
|
||||
log_debug('Stopped watching GTK variants status.');
|
||||
}
|
||||
_unwatchStatus() {
|
||||
if (this._gtkVariantsStatusChangedConnect) {
|
||||
e.settingsManager.disconnect(this._gtkVariantsStatusChangedConnect);
|
||||
this._gtkVariantsStatusChangedConnect = null;
|
||||
}
|
||||
logDebug('Stopped watching GTK variants status.');
|
||||
}
|
||||
|
||||
_connect_settings() {
|
||||
log_debug('Connecting GTK Themer to settings...');
|
||||
this._gtk_variant_changed_connect = e.settingsManager.connect('gtk-variant-changed', this._on_gtk_variant_changed.bind(this));
|
||||
this._gtk_theme_changed_connect = e.settingsManager.connect('gtk-theme-changed', this._on_gtk_theme_changed.bind(this));
|
||||
}
|
||||
_connectSettings() {
|
||||
logDebug('Connecting GTK Themer to settings...');
|
||||
this._gtkVariantChangedConnect = e.settingsManager.connect('gtk-variant-changed', this._onGtkVariantChanged.bind(this));
|
||||
this._gtkThemeChangedConnect = e.settingsManager.connect('gtk-theme-changed', this._onGtkThemeChanged.bind(this));
|
||||
}
|
||||
|
||||
_disconnect_settings() {
|
||||
if ( this._gtk_variant_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._gtk_variant_changed_connect);
|
||||
this._gtk_variant_changed_connect = null;
|
||||
}
|
||||
if ( this._gtk_theme_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._gtk_theme_changed_connect);
|
||||
this._gtk_theme_changed_connect = null;
|
||||
}
|
||||
log_debug('Disconnected GTK Themer from settings.');
|
||||
}
|
||||
_disconnectSettings() {
|
||||
if (this._gtkVariantChangedConnect) {
|
||||
e.settingsManager.disconnect(this._gtkVariantChangedConnect);
|
||||
this._gtkVariantChangedConnect = null;
|
||||
}
|
||||
if (this._gtkThemeChangedConnect) {
|
||||
e.settingsManager.disconnect(this._gtkThemeChangedConnect);
|
||||
this._gtkThemeChangedConnect = null;
|
||||
}
|
||||
logDebug('Disconnected GTK Themer from settings.');
|
||||
}
|
||||
|
||||
_connect_timer() {
|
||||
log_debug('Connecting GTK Themer to Timer...');
|
||||
this._time_changed_connect = e.timer.connect('time-changed', this._on_time_changed.bind(this));
|
||||
}
|
||||
_connectTimer() {
|
||||
logDebug('Connecting GTK Themer to Timer...');
|
||||
this._timeChangedConnect = e.timer.connect('time-changed', this._onTimeChanged.bind(this));
|
||||
}
|
||||
|
||||
_disconnect_timer() {
|
||||
if ( this._time_changed_connect ) {
|
||||
e.timer.disconnect(this._time_changed_connect);
|
||||
this._time_changed_connect = null;
|
||||
}
|
||||
log_debug('Disconnected GTK Themer from Timer.');
|
||||
}
|
||||
_disconnectTimer() {
|
||||
if (this._timeChangedConnect) {
|
||||
e.timer.disconnect(this._timeChangedConnect);
|
||||
this._timeChangedConnect = null;
|
||||
}
|
||||
logDebug('Disconnected GTK Themer from Timer.');
|
||||
}
|
||||
|
||||
|
||||
_on_gtk_variants_status_changed(settings, enabled) {
|
||||
this.disable();
|
||||
this.enable();
|
||||
}
|
||||
_onGtkVariantsStatusChanged(_settings, _enabled) {
|
||||
this.disable();
|
||||
this.enable();
|
||||
}
|
||||
|
||||
_on_gtk_variant_changed(settings, changed_variant_time) {
|
||||
if ( changed_variant_time === e.timer.time ) {
|
||||
this._set_variant(changed_variant_time);
|
||||
}
|
||||
}
|
||||
_onGtkVariantChanged(_settings, changedVariantTime) {
|
||||
if (changedVariantTime === e.timer.time)
|
||||
this._setVariant(changedVariantTime);
|
||||
}
|
||||
|
||||
_on_gtk_theme_changed(settings, new_theme) {
|
||||
try {
|
||||
this._update_variants();
|
||||
this._set_variant(e.timer.time);
|
||||
}
|
||||
catch(e) {
|
||||
log_error(e);
|
||||
}
|
||||
}
|
||||
_onGtkThemeChanged(_settings, _newTheme) {
|
||||
try {
|
||||
this._updateVariants();
|
||||
this._setVariant(e.timer.time);
|
||||
} catch (error) {
|
||||
notifyError(error);
|
||||
}
|
||||
}
|
||||
|
||||
_on_time_changed(timer, new_time) {
|
||||
this._set_variant(new_time);
|
||||
}
|
||||
_onTimeChanged(_timer, newTime) {
|
||||
this._setVariant(newTime);
|
||||
}
|
||||
|
||||
|
||||
_are_variants_up_to_date() {
|
||||
return ( e.settingsManager.gtk_theme === e.settingsManager.gtk_variant_day || e.settingsManager.gtk_theme === e.settingsManager.gtk_variant_night );
|
||||
}
|
||||
_areVariantsUpToDate() {
|
||||
return e.settingsManager.gtkTheme === e.settingsManager.gtkVariantDay || e.settingsManager.gtkTheme === e.settingsManager.gtkVariantNight;
|
||||
}
|
||||
|
||||
_set_variant(time) {
|
||||
log_debug(`Setting the GTK ${time} variant...`);
|
||||
switch (time) {
|
||||
case 'day':
|
||||
e.settingsManager.gtk_theme = e.settingsManager.gtk_variant_day;
|
||||
break;
|
||||
case 'night':
|
||||
e.settingsManager.gtk_theme = e.settingsManager.gtk_variant_night;
|
||||
break;
|
||||
case 'original':
|
||||
e.settingsManager.gtk_theme = e.settingsManager.gtk_variant_original;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_setVariant(time) {
|
||||
logDebug(`Setting the GTK ${time} variant...`);
|
||||
switch (time) {
|
||||
case 'day':
|
||||
e.settingsManager.gtkTheme = e.settingsManager.gtkVariantDay;
|
||||
break;
|
||||
case 'night':
|
||||
e.settingsManager.gtkTheme = e.settingsManager.gtkVariantNight;
|
||||
break;
|
||||
case 'original':
|
||||
e.settingsManager.gtkTheme = e.settingsManager.gtkVariantOriginal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_update_variants() {
|
||||
if ( e.settingsManager.manual_gtk_variants || this._are_variants_up_to_date() ) {
|
||||
return;
|
||||
}
|
||||
_updateVariants() {
|
||||
if (e.settingsManager.manualGtkVariants || this._areVariantsUpToDate())
|
||||
return;
|
||||
|
||||
log_debug('Updating GTK variants...');
|
||||
const variants = GtkVariants.guess_from(e.settingsManager.gtk_theme);
|
||||
const installed_themes = get_installed_gtk_themes();
|
||||
logDebug('Updating GTK variants...');
|
||||
const variants = GtkVariants.guessFrom(e.settingsManager.gtkTheme);
|
||||
const installedThemes = getInstalledGtkThemes();
|
||||
|
||||
if ( !installed_themes.has(variants.get('day')) || !installed_themes.has(variants.get('night')) ) {
|
||||
e.settingsManager.gtk_variant_original = variants.get('original');
|
||||
const message = _('Unable to automatically detect the day and night variants for the "%s" GTK theme. Please manually choose them in the extension\'s preferences.').format(variants.get('original'));
|
||||
throw new Error(message);
|
||||
}
|
||||
if (!installedThemes.has(variants.get('day')) || !installedThemes.has(variants.get('night'))) {
|
||||
e.settingsManager.gtkVariantOriginal = variants.get('original');
|
||||
const message = _('Unable to automatically detect the day and night variants for the "%s" GTK theme. Please manually choose them in the extension\'s preferences.').format(variants.get('original'));
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
e.settingsManager.gtk_variant_day = variants.get('day');
|
||||
e.settingsManager.gtk_variant_night = variants.get('night');
|
||||
e.settingsManager.gtk_variant_original = variants.get('original');
|
||||
log_debug(`New GTK variants. { day: '${variants.get('day')}'; night: '${variants.get('night')}' }`);
|
||||
}
|
||||
e.settingsManager.gtkVariantDay = variants.get('day');
|
||||
e.settingsManager.gtkVariantNight = variants.get('night');
|
||||
e.settingsManager.gtkVariantOriginal = variants.get('original');
|
||||
logDebug(`New GTK variants. { day: '${variants.get('day')}'; night: '${variants.get('night')}' }`);
|
||||
}
|
||||
|
||||
_save_original_theme() {
|
||||
e.settingsManager.gtk_variant_original = e.settingsManager.gtk_theme;
|
||||
}
|
||||
_saveOriginalTheme() {
|
||||
e.settingsManager.gtkVariantOriginal = e.settingsManager.gtkTheme;
|
||||
}
|
||||
|
||||
_reset_original_theme() {
|
||||
// We don't reset the theme when locking the session to prevent
|
||||
// flicker on unlocking
|
||||
if ( !main.screenShield.locked ) {
|
||||
log_debug('Resetting to the user\'s original GTK theme...');
|
||||
this._set_variant('original');
|
||||
}
|
||||
}
|
||||
_resetOriginalTheme() {
|
||||
// We don't reset the theme when locking the session to prevent
|
||||
// flicker on unlocking
|
||||
if (!main.screenShield.locked) {
|
||||
logDebug('Resetting to the user\'s original GTK theme...');
|
||||
this._setVariant('original');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
+63
-77
@@ -21,10 +21,10 @@ this program. If not, see <http s ://www.gnu.org/licenses/>.
|
||||
* The magic of guessing theme variants happens here.
|
||||
*
|
||||
* If the theme doesn't fit a particular case, we'll do the following:
|
||||
* - Remove any signs of a dark variant to the theme name to get the day
|
||||
* variant
|
||||
* - Remove any signs of a light variant to the day variant and add '-dark' to
|
||||
* get the night variant
|
||||
* - Remove any signs of a dark variant to the theme name to get the day
|
||||
* variant
|
||||
* - Remove any signs of a light variant to the day variant and add '-dark' to
|
||||
* get the night variant
|
||||
*
|
||||
* For themes that don't work with the general rule, a particular case must be
|
||||
* written. Day and night variants should be guessed with the most generic light
|
||||
@@ -32,84 +32,70 @@ this program. If not, see <http s ://www.gnu.org/licenses/>.
|
||||
* specific variant.
|
||||
*
|
||||
* Light variants, from the most to the least generic:
|
||||
* - ''
|
||||
* - '-light'
|
||||
* - '-darker'
|
||||
* - ''
|
||||
* - '-light'
|
||||
* - '-darker'
|
||||
*
|
||||
* Dark variants, from the most the least generic:
|
||||
* - '-dark'
|
||||
* - '-darkest'
|
||||
* - '-dark'
|
||||
* - '-darkest'
|
||||
*/
|
||||
var GtkVariants = class {
|
||||
|
||||
static guess_from(name) {
|
||||
const variants = new Map();
|
||||
variants.set('original', name);
|
||||
static guessFrom(name) {
|
||||
const variants = new Map();
|
||||
variants.set('original', name);
|
||||
|
||||
if ( name.includes('Adapta') ) {
|
||||
variants.set('day', name.replace('-Nokto', ''));
|
||||
variants.set('night', variants.get('day').replace('Adapta', 'Adapta-Nokto'));
|
||||
}
|
||||
else if ( name.includes('Arc') ) {
|
||||
const basename = name.split('-')[0];
|
||||
variants.set('day', name.replace(/-Dark(?!er)/, ''));
|
||||
variants.set('night', variants.get('day').replace(/Arc(-Darker)?/, 'Arc-Dark'));
|
||||
}
|
||||
else if ( name.match('Cabinet') ) {
|
||||
variants.set('day', name.replace(/-Dark(?!er)/, '-Light'));
|
||||
variants.set('night', variants.get('day').replace(/(-Light|-Darker)/, '-Dark'))
|
||||
}
|
||||
else if ( name.match(/^(Canta|ChromeOS|Materia|Orchis).*-compact/) ) {
|
||||
variants.set('day', name.replace('-dark', ''));
|
||||
variants.set('night', variants.get('day').replace(/(-light)?-compact/, '-dark-compact'));
|
||||
}
|
||||
else if ( name.includes('Flat-Remix-GTK') ) {
|
||||
const isSolid = name.includes('-Solid');
|
||||
const withoutBorder = name.includes('-NoBorder');
|
||||
const basename = name.split('-').slice(0, 4).join('-');
|
||||
variants.set('day', basename + (name.includes('-Darker') ? '-Darker' : '') + (isSolid ? '-Solid' : ''));
|
||||
variants.set('night', basename + (name.includes('-Darkest') ? '-Darkest' : '-Dark') + (isSolid ? '-Solid' : '') + (withoutBorder ? '-NoBorder' : ''));
|
||||
}
|
||||
else if ( name.includes('HighContrast') ) {
|
||||
variants.set('day', 'HighContrast');
|
||||
variants.set('night', 'HighContrastInverse');
|
||||
}
|
||||
else if ( name.match(/^(Layan|Macwaita|Matcha|Nextwaita)/) ) {
|
||||
const basename = name.split('-')[0];
|
||||
variants.set('day', name.replace('-dark', ''));
|
||||
variants.set('night', variants.get('day').replace(new RegExp(`${basename}(-light)?`), `${basename}-dark`));
|
||||
}
|
||||
else if ( name.includes('Mojave') ) {
|
||||
variants.set('day', name.replace('-dark', '-light'));
|
||||
variants.set('night', variants.get('day').replace('-light', '-dark'));
|
||||
}
|
||||
else if ( name.includes('Plata') ) {
|
||||
variants.set('day', name.replace('-Noir', ''));
|
||||
variants.set('night', variants.get('day').replace(/Plata(-Lumine)?/, 'Plata-Noir'));
|
||||
}
|
||||
else if ( name.match(/^Prof-Gnome-(.+)-3(.*)/) ) {
|
||||
variants.set('day', name.replace(/-Dark(?!er)/, '-Light'));
|
||||
variants.set('night', variants.get('day').replace(/(-Light(-DS)?|-Darker)/, '-Dark'))
|
||||
}
|
||||
else if ( name.includes('Simply_Circles') ) {
|
||||
variants.set('day', name.replace('_Dark', '_Light'));
|
||||
variants.set('night', name.replace('_Light', '_Dark'));
|
||||
}
|
||||
else if ( name.includes('Teja') ) {
|
||||
const dark_variant = '_' + (name.replace('_Light').split('_')[1] || 'Dark');
|
||||
variants.set('day', name.replace(/(_Dark(est)?|_Black)/, ''));
|
||||
variants.set('night', variants.get('day').replace('_Light', '') + dark_variant);
|
||||
}
|
||||
else if ( name.includes('vimix') ) {
|
||||
variants.set('day', name.replace('-dark', ''));
|
||||
variants.set('night', variants.get('day').replace(/vimix(-light)?/, 'vimix-dark'));
|
||||
}
|
||||
else {
|
||||
variants.set('day', name.replace(/-dark(?!er)(est)?/, ''));
|
||||
variants.set('night', variants.get('day').replace(/(-light|-darker)/, '') + (name.includes('-darkest') ? '-darkest' : '-dark'));
|
||||
}
|
||||
if (name.includes('Adapta')) {
|
||||
variants.set('day', name.replace('-Nokto', ''));
|
||||
variants.set('night', variants.get('day').replace('Adapta', 'Adapta-Nokto'));
|
||||
} else if (name.includes('Arc')) {
|
||||
variants.set('day', name.replace(/-Dark(?!er)/, ''));
|
||||
variants.set('night', variants.get('day').replace(/Arc(-Darker)?/, 'Arc-Dark'));
|
||||
} else if (name.match('Cabinet')) {
|
||||
variants.set('day', name.replace(/-Dark(?!er)/, '-Light'));
|
||||
variants.set('night', variants.get('day').replace(/(-Light|-Darker)/, '-Dark'));
|
||||
} else if (name.match(/^(Canta|ChromeOS|Materia|Orchis).*-compact/)) {
|
||||
variants.set('day', name.replace('-dark', ''));
|
||||
variants.set('night', variants.get('day').replace(/(-light)?-compact/, '-dark-compact'));
|
||||
} else if (name.includes('Flat-Remix-GTK')) {
|
||||
const isSolid = name.includes('-Solid');
|
||||
const withoutBorder = name.includes('-NoBorder');
|
||||
const basename = name.split('-').slice(0, 4).join('-');
|
||||
variants.set('day', basename + (name.includes('-Darker') ? '-Darker' : '') + (isSolid ? '-Solid' : ''));
|
||||
variants.set('night', basename + (name.includes('-Darkest') ? '-Darkest' : '-Dark') + (isSolid ? '-Solid' : '') + (withoutBorder ? '-NoBorder' : ''));
|
||||
} else if (name.includes('HighContrast')) {
|
||||
variants.set('day', 'HighContrast');
|
||||
variants.set('night', 'HighContrastInverse');
|
||||
} else if (name.match(/^(Layan|Macwaita|Matcha|Nextwaita)/)) {
|
||||
const basename = name.split('-')[0];
|
||||
variants.set('day', name.replace('-dark', ''));
|
||||
variants.set('night', variants.get('day').replace(new RegExp(`${basename}(-light)?`), `${basename}-dark`));
|
||||
} else if (name.includes('Mojave')) {
|
||||
variants.set('day', name.replace('-dark', '-light'));
|
||||
variants.set('night', variants.get('day').replace('-light', '-dark'));
|
||||
} else if (name.includes('Plata')) {
|
||||
variants.set('day', name.replace('-Noir', ''));
|
||||
variants.set('night', variants.get('day').replace(/Plata(-Lumine)?/, 'Plata-Noir'));
|
||||
} else if (name.match(/^Prof-Gnome-(.+)-3(.*)/)) {
|
||||
variants.set('day', name.replace(/-Dark(?!er)/, '-Light'));
|
||||
variants.set('night', variants.get('day').replace(/(-Light(-DS)?|-Darker)/, '-Dark'));
|
||||
} else if (name.includes('Simply_Circles')) {
|
||||
variants.set('day', name.replace('_Dark', '_Light'));
|
||||
variants.set('night', name.replace('_Light', '_Dark'));
|
||||
} else if (name.includes('Teja')) {
|
||||
const darkVariant = `_${name.replace('_Light').split('_')[1] || 'Dark'}`;
|
||||
variants.set('day', name.replace(/(_Dark(est)?|_Black)/, ''));
|
||||
variants.set('night', variants.get('day').replace('_Light', '') + darkVariant);
|
||||
} else if (name.includes('vimix')) {
|
||||
variants.set('day', name.replace('-dark', ''));
|
||||
variants.set('night', variants.get('day').replace(/vimix(-light)?/, 'vimix-dark'));
|
||||
} else {
|
||||
variants.set('day', name.replace(/-dark(?!er)(est)?/, ''));
|
||||
variants.set('night', variants.get('day').replace(/(-light|-darker)/, '') + (name.includes('-darkest') ? '-darkest' : '-dark'));
|
||||
}
|
||||
|
||||
return variants;
|
||||
}
|
||||
return variants;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
+111
-105
@@ -22,7 +22,7 @@ const { main } = imports.ui;
|
||||
const Me = extensionUtils.getCurrentExtension();
|
||||
|
||||
const e = Me.imports.extension;
|
||||
const { log_debug } = Me.imports.utils;
|
||||
const { logDebug } = Me.imports.utils;
|
||||
|
||||
|
||||
/**
|
||||
@@ -31,125 +31,131 @@ const { log_debug } = Me.imports.utils;
|
||||
*/
|
||||
var IconThemer = class {
|
||||
|
||||
enable() {
|
||||
log_debug('Enabling Icon Themer...');
|
||||
this._watch_status();
|
||||
this._save_original_theme();
|
||||
if ( e.settingsManager.icon_variants_enabled ) {
|
||||
this._connect_settings();
|
||||
this._connect_timer();
|
||||
}
|
||||
log_debug('Icon Themer enabled.');
|
||||
}
|
||||
constructor() {
|
||||
this._iconVariantsStatusChangedConnect = null;
|
||||
this._iconVariantChangedConnect = null;
|
||||
this._iconThemeChangedConnect = null;
|
||||
this._timeChangedConnect = null;
|
||||
}
|
||||
|
||||
disable() {
|
||||
log_debug('Disabling Icon Themer...');
|
||||
this._disconnect_timer();
|
||||
this._disconnect_settings();
|
||||
this._reset_original_theme();
|
||||
this._unwatch_status();
|
||||
log_debug('Icon Themer disabled.');
|
||||
}
|
||||
enable() {
|
||||
logDebug('Enabling Icon Themer...');
|
||||
this._watchStatus();
|
||||
this._saveOriginalTheme();
|
||||
if (e.settingsManager.iconVariantsEnabled) {
|
||||
this._connectSettings();
|
||||
this._connectTimer();
|
||||
}
|
||||
logDebug('Icon Themer enabled.');
|
||||
}
|
||||
|
||||
disable() {
|
||||
logDebug('Disabling Icon Themer...');
|
||||
this._disconnectTimer();
|
||||
this._disconnectSettings();
|
||||
this._resetOriginalTheme();
|
||||
this._unwatchStatus();
|
||||
logDebug('Icon Themer disabled.');
|
||||
}
|
||||
|
||||
|
||||
_watch_status() {
|
||||
log_debug('Watching icon variants status...');
|
||||
this._icon_variants_status_changed_connect = e.settingsManager.connect('icon-variants-status-changed', this._on_icon_variants_status_changed.bind(this));
|
||||
}
|
||||
_watchStatus() {
|
||||
logDebug('Watching icon variants status...');
|
||||
this._iconVariantsStatusChangedConnect = e.settingsManager.connect('icon-variants-status-changed', this._onIconVariantsStatusChanged.bind(this));
|
||||
}
|
||||
|
||||
_unwatch_status() {
|
||||
if ( this._icon_variants_status_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._icon_variants_status_changed_connect);
|
||||
this._icon_variants_status_changed_connect = null;
|
||||
}
|
||||
log_debug('Stopped watching icon variants status.');
|
||||
}
|
||||
_unwatchStatus() {
|
||||
if (this._iconVariantsStatusChangedConnect) {
|
||||
e.settingsManager.disconnect(this._iconVariantsStatusChangedConnect);
|
||||
this._iconVariantsStatusChangedConnect = null;
|
||||
}
|
||||
logDebug('Stopped watching icon variants status.');
|
||||
}
|
||||
|
||||
_connect_settings() {
|
||||
log_debug('Connecting Icon Themer to settings...');
|
||||
this._icon_variant_changed_connect = e.settingsManager.connect('icon-variant-changed', this._on_icon_variant_changed.bind(this));
|
||||
this._icon_theme_changed_connect = e.settingsManager.connect('icon-theme-changed', this._on_icon_theme_changed.bind(this));
|
||||
}
|
||||
_connectSettings() {
|
||||
logDebug('Connecting Icon Themer to settings...');
|
||||
this._iconVariantChangedConnect = e.settingsManager.connect('icon-variant-changed', this._onIconVariantChanged.bind(this));
|
||||
this._iconThemeChangedConnect = e.settingsManager.connect('icon-theme-changed', this._onIconThemeChanged.bind(this));
|
||||
}
|
||||
|
||||
_disconnect_settings() {
|
||||
if ( this._icon_variant_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._icon_variant_changed_connect);
|
||||
this._icon_variant_changed_connect = null;
|
||||
}
|
||||
if ( this._icon_theme_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._icon_theme_changed_connect);
|
||||
this._icon_theme_changed_connect = null;
|
||||
}
|
||||
log_debug('Disconnected Icon Themer from settings.');
|
||||
}
|
||||
_disconnectSettings() {
|
||||
if (this._iconVariantChangedConnect) {
|
||||
e.settingsManager.disconnect(this._iconVariantChangedConnect);
|
||||
this._iconVariantChangedConnect = null;
|
||||
}
|
||||
if (this._iconThemeChangedConnect) {
|
||||
e.settingsManager.disconnect(this._iconThemeChangedConnect);
|
||||
this._iconThemeChangedConnect = null;
|
||||
}
|
||||
logDebug('Disconnected Icon Themer from settings.');
|
||||
}
|
||||
|
||||
_connect_timer() {
|
||||
log_debug('Connecting Icon Themer to Timer...');
|
||||
this._time_changed_connect = e.timer.connect('time-changed', this._on_time_changed.bind(this));
|
||||
}
|
||||
_connectTimer() {
|
||||
logDebug('Connecting Icon Themer to Timer...');
|
||||
this._timeChangedConnect = e.timer.connect('time-changed', this._onTimeChanged.bind(this));
|
||||
}
|
||||
|
||||
_disconnect_timer() {
|
||||
if ( this._time_changed_connect ) {
|
||||
e.timer.disconnect(this._time_changed_connect);
|
||||
this._time_changed_connect = null;
|
||||
}
|
||||
log_debug('Disconnected Icon Themer from Timer.');
|
||||
}
|
||||
_disconnectTimer() {
|
||||
if (this._timeChangedConnect) {
|
||||
e.timer.disconnect(this._timeChangedConnect);
|
||||
this._timeChangedConnect = null;
|
||||
}
|
||||
logDebug('Disconnected Icon Themer from Timer.');
|
||||
}
|
||||
|
||||
|
||||
_on_icon_variants_status_changed(settings, enabled) {
|
||||
this.disable();
|
||||
this.enable();
|
||||
}
|
||||
_onIconVariantsStatusChanged(_settings, _enabled) {
|
||||
this.disable();
|
||||
this.enable();
|
||||
}
|
||||
|
||||
_on_icon_variant_changed(settings, changed_variant_time) {
|
||||
if ( changed_variant_time === e.timer.time ) {
|
||||
this._set_variant(changed_variant_time);
|
||||
}
|
||||
}
|
||||
_onIconVariantChanged(_settings, changedVariantTime) {
|
||||
if (changedVariantTime === e.timer.time)
|
||||
this._setVariant(changedVariantTime);
|
||||
}
|
||||
|
||||
_on_icon_theme_changed(settings, new_theme) {
|
||||
switch (e.timer.time) {
|
||||
case 'day':
|
||||
e.settingsManager.icon_variant_day = new_theme;
|
||||
break;
|
||||
case 'night':
|
||||
e.settingsManager.icon_variant_night = new_theme;
|
||||
}
|
||||
this._set_variant(e.timer.time);
|
||||
}
|
||||
_onIconThemeChanged(_settings, newTheme) {
|
||||
switch (e.timer.time) {
|
||||
case 'day':
|
||||
e.settingsManager.iconVariantDay = newTheme;
|
||||
break;
|
||||
case 'night':
|
||||
e.settingsManager.iconVariantNight = newTheme;
|
||||
}
|
||||
this._setVariant(e.timer.time);
|
||||
}
|
||||
|
||||
_on_time_changed(timer, new_time) {
|
||||
this._set_variant(new_time);
|
||||
}
|
||||
_onTimeChanged(_timer, newTime) {
|
||||
this._setVariant(newTime);
|
||||
}
|
||||
|
||||
|
||||
_set_variant(time) {
|
||||
log_debug(`Setting the icon ${time} variant...`);
|
||||
switch (time) {
|
||||
case 'day':
|
||||
e.settingsManager.icon_theme = e.settingsManager.icon_variant_day;
|
||||
break;
|
||||
case 'night':
|
||||
e.settingsManager.icon_theme = e.settingsManager.icon_variant_night;
|
||||
break;
|
||||
case 'original':
|
||||
e.settingsManager.icon_theme = e.settingsManager.icon_variant_original;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_setVariant(time) {
|
||||
logDebug(`Setting the icon ${time} variant...`);
|
||||
switch (time) {
|
||||
case 'day':
|
||||
e.settingsManager.iconTheme = e.settingsManager.iconVariantDay;
|
||||
break;
|
||||
case 'night':
|
||||
e.settingsManager.iconTheme = e.settingsManager.iconVariantNight;
|
||||
break;
|
||||
case 'original':
|
||||
e.settingsManager.iconTheme = e.settingsManager.iconVariantOriginal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_save_original_theme() {
|
||||
e.settingsManager.icon_variant_original = e.settingsManager.icon_theme;
|
||||
}
|
||||
_saveOriginalTheme() {
|
||||
e.settingsManager.iconVariantOriginal = e.settingsManager.iconTheme;
|
||||
}
|
||||
|
||||
_reset_original_theme() {
|
||||
// We don't reset the theme when locking the session to prevent
|
||||
// flicker on unlocking
|
||||
if ( !main.screenShield.locked ) {
|
||||
log_debug('Resetting to the user\'s original icon theme...');
|
||||
this._set_variant('original');
|
||||
}
|
||||
}
|
||||
_resetOriginalTheme() {
|
||||
// We don't reset the theme when locking the session to prevent
|
||||
// flicker on unlocking
|
||||
if (!main.screenShield.locked) {
|
||||
logDebug('Resetting to the user\'s original icon theme...');
|
||||
this._setVariant('original');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
+497
-508
File diff suppressed because it is too large
Load Diff
+140
-138
@@ -23,7 +23,7 @@ const { main } = imports.ui;
|
||||
const Me = extensionUtils.getCurrentExtension();
|
||||
|
||||
const e = Me.imports.extension;
|
||||
const { log_debug, log_error, get_installed_shell_themes, get_shell_theme_stylesheet, apply_shell_stylesheet } = Me.imports.utils;
|
||||
const { logDebug, notifyError, getInstalledShellThemes, getShellThemeStylesheet, applyShellStylesheet } = Me.imports.utils;
|
||||
const { ShellVariants } = Me.imports.modules.ShellVariants;
|
||||
|
||||
const Gettext = imports.gettext.domain(Me.metadata.uuid);
|
||||
@@ -42,164 +42,166 @@ const _ = Gettext.gettext;
|
||||
*/
|
||||
var ShellThemer = class {
|
||||
|
||||
enable() {
|
||||
log_debug('Enabling Shell Themer...');
|
||||
try {
|
||||
this._watch_status();
|
||||
this._save_original_theme();
|
||||
if ( e.settingsManager.shell_variants_enabled ) {
|
||||
this._update_variants();
|
||||
this._connect_settings();
|
||||
this._connect_timer();
|
||||
}
|
||||
}
|
||||
catch(e) {
|
||||
log_error(e);
|
||||
}
|
||||
log_debug('Shell Themer enabled.');
|
||||
}
|
||||
constructor() {
|
||||
this._shellVariantsStatusChangedConnect = null;
|
||||
this._shellVariantChangedConnect = null;
|
||||
this._shellThemeChangedConnect = null;
|
||||
this._timeChangedConnect = null;
|
||||
}
|
||||
|
||||
disable() {
|
||||
log_debug('Disabling Shell Themer...');
|
||||
this._disconnect_timer();
|
||||
this._disconnect_settings();
|
||||
this._reset_original_theme();
|
||||
this._unwatch_status();
|
||||
log_debug('Shell Themer disabled.');
|
||||
}
|
||||
enable() {
|
||||
logDebug('Enabling Shell Themer...');
|
||||
try {
|
||||
this._watchStatus();
|
||||
this._saveOriginalTheme();
|
||||
if (e.settingsManager.shellVariantsEnabled) {
|
||||
this._updateVariants();
|
||||
this._connectSettings();
|
||||
this._connectTimer();
|
||||
}
|
||||
} catch (error) {
|
||||
notifyError(error);
|
||||
}
|
||||
logDebug('Shell Themer enabled.');
|
||||
}
|
||||
|
||||
disable() {
|
||||
logDebug('Disabling Shell Themer...');
|
||||
this._disconnectTimer();
|
||||
this._disconnectSettings();
|
||||
this._resetOriginalTheme();
|
||||
this._unwatchStatus();
|
||||
logDebug('Shell Themer disabled.');
|
||||
}
|
||||
|
||||
|
||||
_watch_status() {
|
||||
log_debug('Watching shell variants status...');
|
||||
this._shell_variants_status_changed_connect = e.settingsManager.connect('shell-variants-status-changed', this._on_shell_variants_status_changed.bind(this));
|
||||
}
|
||||
_watchStatus() {
|
||||
logDebug('Watching shell variants status...');
|
||||
this._shellVariantsStatusChangedConnect = e.settingsManager.connect('shell-variants-status-changed', this._onShellVariantsStatusChanged.bind(this));
|
||||
}
|
||||
|
||||
_unwatch_status() {
|
||||
if ( this._shell_variants_status_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._shell_variants_status_changed_connect);
|
||||
this._shell_variants_status_changed_connect = null;
|
||||
}
|
||||
log_debug('Stopped watching shell variants status.');
|
||||
}
|
||||
_unwatchStatus() {
|
||||
if (this._shellVariantsStatusChangedConnect) {
|
||||
e.settingsManager.disconnect(this._shellVariantsStatusChangedConnect);
|
||||
this._shellVariantsStatusChangedConnect = null;
|
||||
}
|
||||
logDebug('Stopped watching shell variants status.');
|
||||
}
|
||||
|
||||
_connect_settings() {
|
||||
log_debug('Connecting Shell Themer to settings...');
|
||||
this._shell_variant_changed_connect = e.settingsManager.connect('shell-variant-changed', this._on_shell_variant_changed.bind(this));
|
||||
this._shell_theme_changed_connect = e.settingsManager.connect('shell-theme-changed', this._on_shell_theme_changed.bind(this));
|
||||
}
|
||||
_connectSettings() {
|
||||
logDebug('Connecting Shell Themer to settings...');
|
||||
this._shellVariantChangedConnect = e.settingsManager.connect('shell-variant-changed', this._onShellVariantChanged.bind(this));
|
||||
this._shellThemeChangedConnect = e.settingsManager.connect('shell-theme-changed', this._onShellThemeChanged.bind(this));
|
||||
}
|
||||
|
||||
_disconnect_settings() {
|
||||
if ( this._shell_variant_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._shell_variant_changed_connect);
|
||||
this._shell_variant_changed_connect = null;
|
||||
}
|
||||
if ( this._shell_theme_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._shell_theme_changed_connect);
|
||||
this._shell_theme_changed_connect = null;
|
||||
}
|
||||
log_debug('Disconnected Shell Themer from settings.');
|
||||
}
|
||||
_disconnectSettings() {
|
||||
if (this._shellVariantChangedConnect) {
|
||||
e.settingsManager.disconnect(this._shellVariantChangedConnect);
|
||||
this._shellVariantChangedConnect = null;
|
||||
}
|
||||
if (this._shellThemeChangedConnect) {
|
||||
e.settingsManager.disconnect(this._shellThemeChangedConnect);
|
||||
this._shellThemeChangedConnect = null;
|
||||
}
|
||||
logDebug('Disconnected Shell Themer from settings.');
|
||||
}
|
||||
|
||||
_connect_timer() {
|
||||
log_debug('Connecting Shell Themer to Timer...');
|
||||
this._time_changed_connect = e.timer.connect('time-changed', this._on_time_changed.bind(this));
|
||||
}
|
||||
_connectTimer() {
|
||||
logDebug('Connecting Shell Themer to Timer...');
|
||||
this._timeChangedConnect = e.timer.connect('time-changed', this._onTimeChanged.bind(this));
|
||||
}
|
||||
|
||||
_disconnect_timer() {
|
||||
if ( this._time_changed_connect ) {
|
||||
e.timer.disconnect(this._time_changed_connect);
|
||||
this._time_changed_connect = null;
|
||||
}
|
||||
log_debug('Disconnected Shell Themer from Timer.');
|
||||
}
|
||||
_disconnectTimer() {
|
||||
if (this._timeChangedConnect) {
|
||||
e.timer.disconnect(this._timeChangedConnect);
|
||||
this._timeChangedConnect = null;
|
||||
}
|
||||
logDebug('Disconnected Shell Themer from Timer.');
|
||||
}
|
||||
|
||||
|
||||
_on_shell_variants_status_changed(settings, enabled) {
|
||||
this.disable();
|
||||
this.enable();
|
||||
}
|
||||
_onShellVariantsStatusChanged(_settings, _enabled) {
|
||||
this.disable();
|
||||
this.enable();
|
||||
}
|
||||
|
||||
_on_shell_variant_changed(settings, changed_variant_time) {
|
||||
if ( changed_variant_time === e.timer.time ) {
|
||||
this._set_variant(e.timer.time);
|
||||
}
|
||||
}
|
||||
_onShellVariantChanged(_settings, changedVariantTime) {
|
||||
if (changedVariantTime === e.timer.time)
|
||||
this._setVariant(e.timer.time);
|
||||
}
|
||||
|
||||
_on_shell_theme_changed(settings, new_theme) {
|
||||
try {
|
||||
this._update_variants();
|
||||
this._set_variant(e.timer.time);
|
||||
}
|
||||
catch(e) {
|
||||
log_error(e);
|
||||
}
|
||||
}
|
||||
_onShellThemeChanged(_settings, _newTheme) {
|
||||
try {
|
||||
this._updateVariants();
|
||||
this._setVariant(e.timer.time);
|
||||
} catch (error) {
|
||||
notifyError(error);
|
||||
}
|
||||
}
|
||||
|
||||
_on_time_changed(timer, new_time) {
|
||||
this._set_variant(new_time);
|
||||
}
|
||||
_onTimeChanged(_timer, newTime) {
|
||||
this._setVariant(newTime);
|
||||
}
|
||||
|
||||
|
||||
_are_variants_up_to_date() {
|
||||
return ( e.settingsManager.shell_theme === e.settingsManager.shell_variant_day || e.settingsManager.shell_theme === e.settingsManager.shell_variant_night );
|
||||
}
|
||||
_areVariantsUpToDate() {
|
||||
return e.settingsManager.shellTheme === e.settingsManager.shellVariantDay || e.settingsManager.shellTheme === e.settingsManager.shellVariantNight;
|
||||
}
|
||||
|
||||
_set_variant(time) {
|
||||
log_debug(`Setting the shell ${time} variant...`);
|
||||
let shell_theme;
|
||||
switch (time) {
|
||||
case 'day':
|
||||
shell_theme = e.settingsManager.shell_variant_day;
|
||||
break;
|
||||
case 'night':
|
||||
shell_theme = e.settingsManager.shell_variant_night;
|
||||
break;
|
||||
case 'original':
|
||||
shell_theme = e.settingsManager.shell_variant_original;
|
||||
break;
|
||||
}
|
||||
if ( e.settingsManager.use_userthemes ) {
|
||||
e.settingsManager.shell_theme = shell_theme;
|
||||
}
|
||||
else {
|
||||
const stylesheet = get_shell_theme_stylesheet(shell_theme);
|
||||
apply_shell_stylesheet(stylesheet);
|
||||
}
|
||||
}
|
||||
_setVariant(time) {
|
||||
logDebug(`Setting the shell ${time} variant...`);
|
||||
let shellTheme;
|
||||
switch (time) {
|
||||
case 'day':
|
||||
shellTheme = e.settingsManager.shellVariantDay;
|
||||
break;
|
||||
case 'night':
|
||||
shellTheme = e.settingsManager.shellVariantNight;
|
||||
break;
|
||||
case 'original':
|
||||
shellTheme = e.settingsManager.shellVariantOriginal;
|
||||
break;
|
||||
}
|
||||
if (e.settingsManager.useUserthemes) {
|
||||
e.settingsManager.shellTheme = shellTheme;
|
||||
} else {
|
||||
const stylesheet = getShellThemeStylesheet(shellTheme);
|
||||
applyShellStylesheet(stylesheet);
|
||||
}
|
||||
}
|
||||
|
||||
_update_variants() {
|
||||
if ( !e.settingsManager.use_userthemes || e.settingsManager.manual_shell_variants || this._are_variants_up_to_date() ) {
|
||||
return;
|
||||
}
|
||||
_updateVariants() {
|
||||
if (!e.settingsManager.useUserthemes || e.settingsManager.manualShellVariants || this._areVariantsUpToDate())
|
||||
return;
|
||||
|
||||
log_debug('Updating Shell variants...');
|
||||
const variants = ShellVariants.guess_from(e.settingsManager.shell_theme);
|
||||
const installed_themes = get_installed_shell_themes();
|
||||
logDebug('Updating Shell variants...');
|
||||
const variants = ShellVariants.guessFrom(e.settingsManager.shellTheme);
|
||||
const installedThemes = getInstalledShellThemes();
|
||||
|
||||
if ( !installed_themes.has(variants.get('day')) || !installed_themes.has(variants.get('night')) ) {
|
||||
e.settingsManager.shell_variant_original = variants.get('original');
|
||||
const message = _('Unable to automatically detect the day and night variants for the "%s" GNOME Shell theme. Please manually choose them in the extension\'s preferences.').format(variants.get('original'));
|
||||
throw new Error(message);
|
||||
}
|
||||
if (!installedThemes.has(variants.get('day')) || !installedThemes.has(variants.get('night'))) {
|
||||
e.settingsManager.shellVariantOriginal = variants.get('original');
|
||||
const message = _('Unable to automatically detect the day and night variants for the "%s" GNOME Shell theme. Please manually choose them in the extension\'s preferences.').format(variants.get('original'));
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
e.settingsManager.shell_variant_day = variants.get('day');
|
||||
e.settingsManager.shell_variant_night = variants.get('night');
|
||||
e.settingsManager.shell_variant_original = variants.get('original');
|
||||
log_debug(`New Shell variants. { day: '${variants.get('day')}'; night: '${variants.get('night')}' }`);
|
||||
}
|
||||
e.settingsManager.shellVariantDay = variants.get('day');
|
||||
e.settingsManager.shellVariantNight = variants.get('night');
|
||||
e.settingsManager.shellVariantOriginal = variants.get('original');
|
||||
logDebug(`New Shell variants. { day: '${variants.get('day')}'; night: '${variants.get('night')}' }`);
|
||||
}
|
||||
|
||||
_save_original_theme() {
|
||||
e.settingsManager.shell_variant_original = e.settingsManager.shell_theme;
|
||||
}
|
||||
_saveOriginalTheme() {
|
||||
e.settingsManager.shellVariantOriginal = e.settingsManager.shellTheme;
|
||||
}
|
||||
|
||||
_reset_original_theme() {
|
||||
// We don't reset the theme when locking the session to prevent
|
||||
// flicker on unlocking
|
||||
if ( !main.screenShield.locked ) {
|
||||
log_debug('Resetting to the user\'s original Shell theme...');
|
||||
this._set_variant('original');
|
||||
}
|
||||
}
|
||||
_resetOriginalTheme() {
|
||||
// We don't reset the theme when locking the session to prevent
|
||||
// flicker on unlocking
|
||||
if (!main.screenShield.locked) {
|
||||
logDebug('Resetting to the user\'s original Shell theme...');
|
||||
this._setVariant('original');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
Signals.addSignalMethods(ShellThemer.prototype);
|
||||
|
||||
@@ -17,15 +17,14 @@ You should have received a copy of the GNU General Public License along with
|
||||
this program. If not, see <http s ://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* The magic of guessing theme variants happens here.
|
||||
*
|
||||
* If the theme doesn't fit a particular case, we'll do the following:
|
||||
* - Remove any signs of a dark variant to the theme name to get the day
|
||||
* variant
|
||||
* - Remove any signs of a light variant to the day variant and add '-dark' to
|
||||
* get the night variant
|
||||
* - Remove any signs of a dark variant to the theme name to get the day
|
||||
* variant
|
||||
* - Remove any signs of a light variant to the day variant and add '-dark' to
|
||||
* get the night variant
|
||||
*
|
||||
* For themes that don't work with the general rule, a particular case must be
|
||||
* written. Day and night variants should be guessed with the most generic light
|
||||
@@ -33,75 +32,64 @@ this program. If not, see <http s ://www.gnu.org/licenses/>.
|
||||
* specific variant.
|
||||
*
|
||||
* Light variants, from the most to the least generic:
|
||||
* - ''
|
||||
* - '-light'
|
||||
* - '-darker'
|
||||
* - ''
|
||||
* - '-light'
|
||||
* - '-darker'
|
||||
*
|
||||
* Dark variants, from the most the least generic:
|
||||
* - '-dark'
|
||||
* - '-darkest'
|
||||
* - '-dark'
|
||||
* - '-darkest'
|
||||
*/
|
||||
var ShellVariants = class {
|
||||
|
||||
static guess_from(name) {
|
||||
const variants = new Map();
|
||||
variants.set('original', name);
|
||||
static guessFrom(name) {
|
||||
const variants = new Map();
|
||||
variants.set('original', name);
|
||||
|
||||
if ( name === '' ) {
|
||||
variants.set('day', '');
|
||||
variants.set('night', '');
|
||||
}
|
||||
else if ( name.includes('Adapta') ) {
|
||||
variants.set('day', name.replace('-Nokto', ''));
|
||||
variants.set('night', variants.get('day').replace('Adapta', 'Adapta-Nokto'));
|
||||
}
|
||||
else if ( name.includes('Arc') ) {
|
||||
variants.set('day', name.replace('-Dark', ''));
|
||||
variants.set('night', variants.get('day').replace('Arc', 'Arc-Dark'));
|
||||
}
|
||||
else if ( name.match(/^(Canta|ChromeOS|Materia|Orchis).*-compact/) ) {
|
||||
variants.set('day', name.replace('-dark', ''));
|
||||
variants.set('night', variants.get('day').replace(/(-light)?-compact/, '-dark-compact'));
|
||||
}
|
||||
else if ( name.includes('Flat-Remix') ) {
|
||||
const color = ( name.split('-')[2] && !['Dark', 'Darkest', 'fullPanel'].includes(name.split('-')[2]) ) ? '-' + name.split('-')[2] : '';
|
||||
const dark_variant = name.includes('Darkest') ? '-Darkest' : '-Dark';
|
||||
const size = name.includes('fullPanel')? '-fullPanel' : '';
|
||||
variants.set('day', name.replace(/-Dark(est)?/, ''));
|
||||
variants.set('night', `Flat-Remix${color}${dark_variant}${size}`);
|
||||
}
|
||||
else if ( name.match(/^(Layan|Matcha)/) ) {
|
||||
const basename = name.split('-')[0];
|
||||
variants.set('day', name.replace('-dark', ''));
|
||||
variants.set('night', variants.get('day').replace(new RegExp(`${basename}(-light)?`), `${basename}-dark`));
|
||||
}
|
||||
else if ( name.includes('Mojave') ) {
|
||||
variants.set('day', name.replace('-dark', '-light'));
|
||||
variants.set('night', variants.get('day').replace('-light', '-dark'));
|
||||
}
|
||||
else if ( name.includes('Plata') ) {
|
||||
variants.set('day', name.replace('-Noir', ''));
|
||||
variants.set('night', variants.get('day').replace(/Plata(-Lumine)?/, 'Plata-Noir'));
|
||||
}
|
||||
else if ( name.includes('Simply_Circles') ) {
|
||||
variants.set('day', name.replace('_Dark', '_Light'));
|
||||
variants.set('night', name.replace('_Light', '_Dark'));
|
||||
}
|
||||
else if ( name.includes('Teja') ) {
|
||||
const dark_variant = '_' + (name.replace('_Light').split('_')[1] || 'Dark');
|
||||
variants.set('day', name.replace(/(_Dark(est)?|_Black)/, ''));
|
||||
variants.set('night', variants.get('day').replace('_Light', '') + dark_variant);
|
||||
}
|
||||
else if ( name.includes('vimix') ) {
|
||||
variants.set('day', name.replace('-dark', ''));
|
||||
variants.set('night', variants.get('day').replace(/vimix(-light)?/, 'vimix-dark'));
|
||||
}
|
||||
else {
|
||||
variants.set('day', name.replace(/-dark(?!er)(est)?/, ''));
|
||||
variants.set('night', variants.get('day').replace(/(-light|-darker)/, '') + (name.includes('-darkest') ? '-darkest' : '-dark'));
|
||||
}
|
||||
if (name === '') {
|
||||
variants.set('day', '');
|
||||
variants.set('night', '');
|
||||
} else if (name.includes('Adapta')) {
|
||||
variants.set('day', name.replace('-Nokto', ''));
|
||||
variants.set('night', variants.get('day').replace('Adapta', 'Adapta-Nokto'));
|
||||
} else if (name.includes('Arc')) {
|
||||
variants.set('day', name.replace('-Dark', ''));
|
||||
variants.set('night', variants.get('day').replace('Arc', 'Arc-Dark'));
|
||||
} else if (name.match(/^(Canta|ChromeOS|Materia|Orchis).*-compact/)) {
|
||||
variants.set('day', name.replace('-dark', ''));
|
||||
variants.set('night', variants.get('day').replace(/(-light)?-compact/, '-dark-compact'));
|
||||
} else if (name.includes('Flat-Remix')) {
|
||||
const color = name.split('-')[2] && !['Dark', 'Darkest', 'fullPanel'].includes(name.split('-')[2]) ? `-${name.split('-')[2]}` : '';
|
||||
const darkVariant = name.includes('Darkest') ? '-Darkest' : '-Dark';
|
||||
const size = name.includes('fullPanel') ? '-fullPanel' : '';
|
||||
variants.set('day', name.replace(/-Dark(est)?/, ''));
|
||||
variants.set('night', `Flat-Remix${color}${darkVariant}${size}`);
|
||||
} else if (name.match(/^(Layan|Matcha)/)) {
|
||||
const basename = name.split('-')[0];
|
||||
variants.set('day', name.replace('-dark', ''));
|
||||
variants.set('night', variants.get('day').replace(new RegExp(`${basename}(-light)?`), `${basename}-dark`));
|
||||
} else if (name.includes('Mojave')) {
|
||||
variants.set('day', name.replace('-dark', '-light'));
|
||||
variants.set('night', variants.get('day').replace('-light', '-dark'));
|
||||
} else if (name.includes('Plata')) {
|
||||
variants.set('day', name.replace('-Noir', ''));
|
||||
variants.set('night', variants.get('day').replace(/Plata(-Lumine)?/, 'Plata-Noir'));
|
||||
} else if (name.includes('Simply_Circles')) {
|
||||
variants.set('day', name.replace('_Dark', '_Light'));
|
||||
variants.set('night', name.replace('_Light', '_Dark'));
|
||||
} else if (name.includes('Teja')) {
|
||||
const darkVariant = `_${name.replace('_Light').split('_')[1] || 'Dark'}`;
|
||||
variants.set('day', name.replace(/(_Dark(est)?|_Black)/, ''));
|
||||
variants.set('night', variants.get('day').replace('_Light', '') + darkVariant);
|
||||
} else if (name.includes('vimix')) {
|
||||
variants.set('day', name.replace('-dark', ''));
|
||||
variants.set('night', variants.get('day').replace(/vimix(-light)?/, 'vimix-dark'));
|
||||
} else {
|
||||
variants.set('day', name.replace(/-dark(?!er)(est)?/, ''));
|
||||
variants.set('night', variants.get('day').replace(/(-light|-darker)/, '') + (name.includes('-darkest') ? '-darkest' : '-dark'));
|
||||
}
|
||||
|
||||
return variants;
|
||||
}
|
||||
return variants;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
+126
-125
@@ -22,7 +22,7 @@ const Signals = imports.signals;
|
||||
const Me = extensionUtils.getCurrentExtension();
|
||||
|
||||
const e = Me.imports.extension;
|
||||
const { log_debug } = Me.imports.utils;
|
||||
const { logDebug } = Me.imports.utils;
|
||||
const { TimerNightlight } = Me.imports.modules.TimerNightlight;
|
||||
const { TimerLocation } = Me.imports.modules.TimerLocation;
|
||||
const { TimerSchedule } = Me.imports.modules.TimerSchedule;
|
||||
@@ -37,156 +37,157 @@ const { TimerOndemand } = Me.imports.modules.TimerOndemand;
|
||||
*
|
||||
* It will try to use one of this three different time sources, in this order of
|
||||
* preference:
|
||||
* - Night Light
|
||||
* - Location Services
|
||||
* - Manual schedule
|
||||
* - Night Light
|
||||
* - Location Services
|
||||
* - Manual schedule
|
||||
*
|
||||
* The user can manually force a specific time source and set the manual
|
||||
* schedule in the extensions's preferences.
|
||||
*/
|
||||
var Timer = class {
|
||||
|
||||
constructor() {
|
||||
this._source = null;
|
||||
this._previous_time = null;
|
||||
}
|
||||
constructor() {
|
||||
this._source = null;
|
||||
this._previousTime = null;
|
||||
this._nightlightStatusChangedConnect = null;
|
||||
this._locationStatusChangedConnect = null;
|
||||
this._manualTimeSourceChangedConnect = null;
|
||||
this._timeSourceChangedConnect = null;
|
||||
this._timeChangedConnect = null;
|
||||
}
|
||||
|
||||
enable() {
|
||||
log_debug('Enabling Timer...');
|
||||
this._connect_settings();
|
||||
this._create_source();
|
||||
this._connect_source();
|
||||
this._enable_source();
|
||||
log_debug('Timer enabled.');
|
||||
}
|
||||
enable() {
|
||||
logDebug('Enabling Timer...');
|
||||
this._connectSettings();
|
||||
this._createSource();
|
||||
this._connectSource();
|
||||
this._enableSource();
|
||||
logDebug('Timer enabled.');
|
||||
}
|
||||
|
||||
disable() {
|
||||
log_debug('Disabling Timer...');
|
||||
this._disconnect_source();
|
||||
this._disable_source();
|
||||
this._disconnect_settings();
|
||||
log_debug('Timer disabled.');
|
||||
}
|
||||
disable() {
|
||||
logDebug('Disabling Timer...');
|
||||
this._disconnectSource();
|
||||
this._disableSource();
|
||||
this._disconnectSettings();
|
||||
logDebug('Timer disabled.');
|
||||
}
|
||||
|
||||
|
||||
get time() {
|
||||
return this._source.time;
|
||||
}
|
||||
get time() {
|
||||
return this._source.time;
|
||||
}
|
||||
|
||||
|
||||
_connect_settings() {
|
||||
log_debug('Connecting Timer to settings...');
|
||||
this._nightlight_status_changed_connect = e.settingsManager.connect('nightlight-status-changed', this._on_source_changed.bind(this));
|
||||
this._location_status_changed_connect = e.settingsManager.connect('location-status-changed', this._on_source_changed.bind(this));
|
||||
this._manual_time_source_changed_connect = e.settingsManager.connect('manual-time-source-changed', this._on_source_changed.bind(this));
|
||||
this._time_source_changed_connect = e.settingsManager.connect('time-source-changed', this._on_time_source_changed.bind(this));
|
||||
}
|
||||
_connectSettings() {
|
||||
logDebug('Connecting Timer to settings...');
|
||||
this._nightlightStatusChangedConnect = e.settingsManager.connect('nightlight-status-changed', this._onSourceChanged.bind(this));
|
||||
this._locationStatusChangedConnect = e.settingsManager.connect('location-status-changed', this._onSourceChanged.bind(this));
|
||||
this._manualTimeSourceChangedConnect = e.settingsManager.connect('manual-time-source-changed', this._onSourceChanged.bind(this));
|
||||
this._timeSourceChangedConnect = e.settingsManager.connect('time-source-changed', this._onTimeSourceChanged.bind(this));
|
||||
}
|
||||
|
||||
_disconnect_settings() {
|
||||
if ( this._nightlight_status_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._nightlight_status_changed_connect);
|
||||
this._nightlight_status_changed_connect = null;
|
||||
}
|
||||
if ( this._location_status_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._location_status_changed_connect);
|
||||
this._location_status_changed_connect = null;
|
||||
}
|
||||
if ( this._manual_time_source_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._manual_time_source_changed_connect);
|
||||
this._manual_time_source_changed_connect = null;
|
||||
}
|
||||
if ( this._time_source_changed_connect ) {
|
||||
e.settingsManager.disconnect(this._time_source_changed_connect);
|
||||
this._time_source_changed_connect = null;
|
||||
}
|
||||
log_debug('Disconnected Timer from settings.');
|
||||
}
|
||||
_disconnectSettings() {
|
||||
if (this._nightlightStatusChangedConnect) {
|
||||
e.settingsManager.disconnect(this._nightlightStatusChangedConnect);
|
||||
this._nightlightStatusChangedConnect = null;
|
||||
}
|
||||
if (this._locationStatusChangedConnect) {
|
||||
e.settingsManager.disconnect(this._locationStatusChangedConnect);
|
||||
this._locationStatusChangedConnect = null;
|
||||
}
|
||||
if (this._manualTimeSourceChangedConnect) {
|
||||
e.settingsManager.disconnect(this._manualTimeSourceChangedConnect);
|
||||
this._manualTimeSourceChangedConnect = null;
|
||||
}
|
||||
if (this._timeSourceChangedConnect) {
|
||||
e.settingsManager.disconnect(this._timeSourceChangedConnect);
|
||||
this._timeSourceChangedConnect = null;
|
||||
}
|
||||
logDebug('Disconnected Timer from settings.');
|
||||
}
|
||||
|
||||
_create_source() {
|
||||
switch ( this._get_source() ) {
|
||||
case 'nightlight':
|
||||
this._source = new TimerNightlight();
|
||||
break;
|
||||
case 'location':
|
||||
this._source = new TimerLocation();
|
||||
break;
|
||||
case 'schedule':
|
||||
this._source = new TimerSchedule();
|
||||
break;
|
||||
case 'ondemand':
|
||||
this._source = new TimerOndemand();
|
||||
break;
|
||||
}
|
||||
}
|
||||
_createSource() {
|
||||
switch (this._getSource()) {
|
||||
case 'nightlight':
|
||||
this._source = new TimerNightlight();
|
||||
break;
|
||||
case 'location':
|
||||
this._source = new TimerLocation();
|
||||
break;
|
||||
case 'schedule':
|
||||
this._source = new TimerSchedule();
|
||||
break;
|
||||
case 'ondemand':
|
||||
this._source = new TimerOndemand();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_enable_source() {
|
||||
this._source.enable();
|
||||
}
|
||||
_enableSource() {
|
||||
this._source.enable();
|
||||
}
|
||||
|
||||
_disable_source() {
|
||||
if ( this._source ) {
|
||||
this._source.disable();
|
||||
this._source = null;
|
||||
}
|
||||
}
|
||||
_disableSource() {
|
||||
if (this._source) {
|
||||
this._source.disable();
|
||||
this._source = null;
|
||||
}
|
||||
}
|
||||
|
||||
_connect_source() {
|
||||
log_debug('Connecting to time source...');
|
||||
this._time_changed_connect = this._source.connect('time-changed', this._on_time_changed.bind(this));
|
||||
}
|
||||
_connectSource() {
|
||||
logDebug('Connecting to time source...');
|
||||
this._timeChangedConnect = this._source.connect('time-changed', this._onTimeChanged.bind(this));
|
||||
}
|
||||
|
||||
_disconnect_source() {
|
||||
if ( this._time_changed_connect ) {
|
||||
this._source.disconnect(this._time_changed_connect);
|
||||
this._time_changed_connect = null;
|
||||
}
|
||||
log_debug('Disconnected from time source.');
|
||||
}
|
||||
_disconnectSource() {
|
||||
if (this._timeChangedConnect) {
|
||||
this._source.disconnect(this._timeChangedConnect);
|
||||
this._timeChangedConnect = null;
|
||||
}
|
||||
logDebug('Disconnected from time source.');
|
||||
}
|
||||
|
||||
|
||||
_on_source_changed() {
|
||||
this.disable();
|
||||
this.enable();
|
||||
}
|
||||
_onSourceChanged() {
|
||||
this.disable();
|
||||
this.enable();
|
||||
}
|
||||
|
||||
_on_time_source_changed(settings, new_source) {
|
||||
if ( e.settingsManager.manual_time_source ) {
|
||||
this._on_source_changed();
|
||||
}
|
||||
}
|
||||
_onTimeSourceChanged(_settings, _newSource) {
|
||||
if (e.settingsManager.manualTimeSource)
|
||||
this._onSourceChanged();
|
||||
}
|
||||
|
||||
_on_time_changed(source, new_time) {
|
||||
if ( new_time !== this._previous_time) {
|
||||
log_debug(`Time has changed to ${new_time}.`);
|
||||
this.emit('time-changed', new_time);
|
||||
this._previous_time = new_time;
|
||||
}
|
||||
}
|
||||
_onTimeChanged(_source, newTime) {
|
||||
if (newTime !== this._previousTime) {
|
||||
logDebug(`Time has changed to ${newTime}.`);
|
||||
this.emit('time-changed', newTime);
|
||||
this._previousTime = newTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_get_source() {
|
||||
log_debug('Getting time source...');
|
||||
_getSource() {
|
||||
logDebug('Getting time source...');
|
||||
|
||||
if ( e.settingsManager.manual_time_source ) {
|
||||
log_debug(`Time source is forced to ${e.settingsManager.time_source}.`);
|
||||
return e.settingsManager.time_source;
|
||||
}
|
||||
if (e.settingsManager.manualTimeSource) {
|
||||
logDebug(`Time source is forced to ${e.settingsManager.timeSource}.`);
|
||||
return e.settingsManager.timeSource;
|
||||
}
|
||||
|
||||
let source;
|
||||
if ( e.settingsManager.nightlight_enabled ) {
|
||||
source = 'nightlight';
|
||||
}
|
||||
else if ( e.settingsManager.location_enabled ) {
|
||||
source = 'location';
|
||||
}
|
||||
else {
|
||||
source = 'schedule';
|
||||
}
|
||||
let source;
|
||||
if (e.settingsManager.nightlightEnabled)
|
||||
source = 'nightlight';
|
||||
else if (e.settingsManager.locationEnabled)
|
||||
source = 'location';
|
||||
else
|
||||
source = 'schedule';
|
||||
|
||||
log_debug(`Time source is ${source}.`);
|
||||
e.settingsManager.time_source = source;
|
||||
return source;
|
||||
}
|
||||
logDebug(`Time source is ${source}.`);
|
||||
e.settingsManager.timeSource = source;
|
||||
return source;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
Signals.addSignalMethods(Timer.prototype);
|
||||
|
||||
+238
-233
@@ -23,64 +23,64 @@ const Signals = imports.signals;
|
||||
const Me = extensionUtils.getCurrentExtension();
|
||||
|
||||
const e = Me.imports.extension;
|
||||
const { log_debug } = Me.imports.utils;
|
||||
const { logDebug } = Me.imports.utils;
|
||||
|
||||
|
||||
// GeoClue2 interfaces from https://gitlab.freedesktop.org/geoclue/geoclue/
|
||||
const GEOCLUE_MANAGER_INTERFACE = `
|
||||
<node>
|
||||
<interface name="org.freedesktop.GeoClue2.Manager">
|
||||
<property name="InUse" type="b" access="read"/>
|
||||
<property name="AvailableAccuracyLevel" type="u" access="read"/>
|
||||
<method name="GetClient">
|
||||
<arg name="client" type="o" direction="out"/>
|
||||
</method>
|
||||
<method name="CreateClient">
|
||||
<arg name="client" type="o" direction="out"/>
|
||||
</method>
|
||||
<method name="DeleteClient">
|
||||
<arg name="client" type="o" direction="in"/>
|
||||
</method>
|
||||
<method name="AddAgent">
|
||||
<arg name="id" type="s" direction="in"/>
|
||||
</method>
|
||||
</interface>
|
||||
<interface name="org.freedesktop.GeoClue2.Manager">
|
||||
<property name="InUse" type="b" access="read"/>
|
||||
<property name="AvailableAccuracyLevel" type="u" access="read"/>
|
||||
<method name="GetClient">
|
||||
<arg name="client" type="o" direction="out"/>
|
||||
</method>
|
||||
<method name="CreateClient">
|
||||
<arg name="client" type="o" direction="out"/>
|
||||
</method>
|
||||
<method name="DeleteClient">
|
||||
<arg name="client" type="o" direction="in"/>
|
||||
</method>
|
||||
<method name="AddAgent">
|
||||
<arg name="id" type="s" direction="in"/>
|
||||
</method>
|
||||
</interface>
|
||||
</node>`;
|
||||
|
||||
const GEOCLUE_CLIENT_INTERFACE = `
|
||||
<node>
|
||||
<interface name="org.freedesktop.GeoClue2.Client">
|
||||
<property name="Location" type="o" access="read"/>
|
||||
<property name="DistanceThreshold" type="u" access="readwrite">
|
||||
<annotation name="org.freedesktop.Accounts.DefaultValue" value="0"/>
|
||||
</property>
|
||||
<property name="TimeThreshold" type="u" access="readwrite">
|
||||
<annotation name="org.freedesktop.Accounts.DefaultValue" value="0"/>
|
||||
</property>
|
||||
<property name="DesktopId" type="s" access="readwrite"/>
|
||||
<property name="RequestedAccuracyLevel" type="u" access="readwrite"/>
|
||||
<property name="Active" type="b" access="read"/>
|
||||
<method name="Start"/>
|
||||
<method name="Stop"/>
|
||||
<signal name="LocationUpdated">
|
||||
<arg name="old" type="o"/>
|
||||
<arg name="new" type="o"/>
|
||||
</signal>
|
||||
</interface>
|
||||
<interface name="org.freedesktop.GeoClue2.Client">
|
||||
<property name="Location" type="o" access="read"/>
|
||||
<property name="DistanceThreshold" type="u" access="readwrite">
|
||||
<annotation name="org.freedesktop.Accounts.DefaultValue" value="0"/>
|
||||
</property>
|
||||
<property name="TimeThreshold" type="u" access="readwrite">
|
||||
<annotation name="org.freedesktop.Accounts.DefaultValue" value="0"/>
|
||||
</property>
|
||||
<property name="DesktopId" type="s" access="readwrite"/>
|
||||
<property name="RequestedAccuracyLevel" type="u" access="readwrite"/>
|
||||
<property name="Active" type="b" access="read"/>
|
||||
<method name="Start"/>
|
||||
<method name="Stop"/>
|
||||
<signal name="LocationUpdated">
|
||||
<arg name="old" type="o"/>
|
||||
<arg name="new" type="o"/>
|
||||
</signal>
|
||||
</interface>
|
||||
</node>`;
|
||||
|
||||
const GEOCLUE_LOCATION_INTERFACE = `
|
||||
<node>
|
||||
<interface name="org.freedesktop.GeoClue2.Location">
|
||||
<property name="Latitude" type="d" access="read"/>
|
||||
<property name="Longitude" type="d" access="read"/>
|
||||
<property name="Accuracy" type="d" access="read"/>
|
||||
<property name="Altitude" type="d" access="read"/>
|
||||
<property name="Speed" type="d" access="read"/>
|
||||
<property name="Heading" type="d" access="read"/>
|
||||
<property name="Description" type="s" access="read"/>
|
||||
<property name="Timestamp" type="(tt)" access="read"/>
|
||||
</interface>
|
||||
<interface name="org.freedesktop.GeoClue2.Location">
|
||||
<property name="Latitude" type="d" access="read"/>
|
||||
<property name="Longitude" type="d" access="read"/>
|
||||
<property name="Accuracy" type="d" access="read"/>
|
||||
<property name="Altitude" type="d" access="read"/>
|
||||
<property name="Speed" type="d" access="read"/>
|
||||
<property name="Heading" type="d" access="read"/>
|
||||
<property name="Description" type="s" access="read"/>
|
||||
<property name="Timestamp" type="(tt)" access="read"/>
|
||||
</interface>
|
||||
</node>`;
|
||||
|
||||
|
||||
@@ -99,224 +99,229 @@ const GEOCLUE_LOCATION_INTERFACE = `
|
||||
*/
|
||||
var TimerLocation = class {
|
||||
|
||||
constructor() {
|
||||
this._previously_daytime = null;
|
||||
// Before we have the location suntimes, we'll use the manual schedule
|
||||
// times
|
||||
this._suntimes = new Map([
|
||||
['sunrise', e.settingsManager.schedule_sunrise],
|
||||
['sunset', e.settingsManager.schedule_sunrise]
|
||||
]);
|
||||
}
|
||||
constructor() {
|
||||
this._previouslyDaytime = null;
|
||||
// Before we have the location suntimes, we'll use the manual schedule
|
||||
// times
|
||||
this._suntimes = new Map([
|
||||
['sunrise', e.settingsManager.scheduleSunrise],
|
||||
['sunset', e.settingsManager.scheduleSunrise],
|
||||
]);
|
||||
this._geoclueClient = null;
|
||||
this._geoclueClientDbusProxy = null;
|
||||
this._geoclueManagerDbusProxy = null;
|
||||
this._geoclueLocationDbusProxy = null;
|
||||
this._locationUpdatesConnect = null;
|
||||
this._timeChangeTimer = null;
|
||||
this._regularlyUpdateSuntimesTimer = null;
|
||||
}
|
||||
|
||||
enable() {
|
||||
log_debug('Enabling Location Timer...');
|
||||
this._connect_to_geoclue_dbus_proxy();
|
||||
this._listen_to_location_updates();
|
||||
this._connect_to_geoclue_location_dbus_proxy();
|
||||
this._update_location();
|
||||
this._update_suntimes();
|
||||
this._watch_for_time_change();
|
||||
this._regularly_update_suntimes();
|
||||
log_debug('Location Timer enabled.');
|
||||
}
|
||||
enable() {
|
||||
logDebug('Enabling Location Timer...');
|
||||
this._connectToGeoclueDbusProxy();
|
||||
this._listenToLocationUpdates();
|
||||
this._connectToGeoclueLocationDbusProxy();
|
||||
this._updateLocation();
|
||||
this._updateSuntimes();
|
||||
this._watchForTimeChange();
|
||||
this._regularlyUpdateSuntimes();
|
||||
logDebug('Location Timer enabled.');
|
||||
}
|
||||
|
||||
disable() {
|
||||
log_debug('Disabling Location Timer...');
|
||||
this._stop_regularly_updating_suntimes();
|
||||
this._stop_watching_for_time_change();
|
||||
this._stop_listening_to_location_updates();
|
||||
this._disconnect_from_geoclue_location_dbus_proxy();
|
||||
this._disconnect_from_geoclue_dbus_proxy();
|
||||
log_debug('Location Timer disabled.');
|
||||
}
|
||||
disable() {
|
||||
logDebug('Disabling Location Timer...');
|
||||
this._stopRegularlyUpdatingSuntimes();
|
||||
this._stopWatchingForTimeChange();
|
||||
this._stopListeningToLocationUpdates();
|
||||
this._disconnectFromGeoclueLocationDbusProxy();
|
||||
this._disconnectFromGeoclueDbusProxy();
|
||||
logDebug('Location Timer disabled.');
|
||||
}
|
||||
|
||||
|
||||
get time() {
|
||||
return this._is_daytime() ? 'day' : 'night';
|
||||
}
|
||||
get time() {
|
||||
return this._isDaytime() ? 'day' : 'night';
|
||||
}
|
||||
|
||||
_connect_to_geoclue_dbus_proxy() {
|
||||
log_debug('Connecting to GeoClue manager DBus proxy...');
|
||||
const GeoClueManagerProxy = Gio.DBusProxy.makeProxyWrapper(GEOCLUE_MANAGER_INTERFACE);
|
||||
this._geoclue_manager_dbus_proxy = new GeoClueManagerProxy(
|
||||
Gio.DBus.system,
|
||||
'org.freedesktop.GeoClue2',
|
||||
'/org/freedesktop/GeoClue2/Manager'
|
||||
);
|
||||
log_debug('Connected to GeoClue manager DBus proxy.');
|
||||
_connectToGeoclueDbusProxy() {
|
||||
logDebug('Connecting to GeoClue manager DBus proxy...');
|
||||
const GeoClueManagerProxy = Gio.DBusProxy.makeProxyWrapper(GEOCLUE_MANAGER_INTERFACE);
|
||||
this._geoclueManagerDbusProxy = new GeoClueManagerProxy(
|
||||
Gio.DBus.system,
|
||||
'org.freedesktop.GeoClue2',
|
||||
'/org/freedesktop/GeoClue2/Manager'
|
||||
);
|
||||
logDebug('Connected to GeoClue manager DBus proxy.');
|
||||
|
||||
log_debug('Getting a GeoClue client...');
|
||||
this._geoclue_client = this._geoclue_manager_dbus_proxy.GetClientSync()[0];
|
||||
log_debug(`Got a GeoClue client at ${this._geoclue_client}`);
|
||||
logDebug('Getting a GeoClue client...');
|
||||
this._geoclueClient = this._geoclueManagerDbusProxy.GetClientSync()[0];
|
||||
logDebug(`Got a GeoClue client at ${this._geoclueClient}`);
|
||||
|
||||
log_debug('Connecting to GeoClue client DBus proxy...');
|
||||
const GeoClueClientProxy = Gio.DBusProxy.makeProxyWrapper(GEOCLUE_CLIENT_INTERFACE);
|
||||
this._geoclue_client_dbus_proxy = new GeoClueClientProxy(
|
||||
Gio.DBus.system,
|
||||
'org.freedesktop.GeoClue2',
|
||||
this._geoclue_client
|
||||
);
|
||||
this._geoclue_client_dbus_proxy.DesktopId = Me.metadata.uuid;
|
||||
this._geoclue_client_dbus_proxy.DistanceThreshold = 10000;
|
||||
this._geoclue_client_dbus_proxy.RequestedAccuracyLevel = 4;
|
||||
log_debug('Connected to GeoClue client DBus proxy.');
|
||||
}
|
||||
logDebug('Connecting to GeoClue client DBus proxy...');
|
||||
const GeoClueClientProxy = Gio.DBusProxy.makeProxyWrapper(GEOCLUE_CLIENT_INTERFACE);
|
||||
this._geoclueClientDbusProxy = new GeoClueClientProxy(
|
||||
Gio.DBus.system,
|
||||
'org.freedesktop.GeoClue2',
|
||||
this._geoclueClient
|
||||
);
|
||||
this._geoclueClientDbusProxy.DesktopId = Me.metadata.uuid;
|
||||
this._geoclueClientDbusProxy.DistanceThreshold = 10000;
|
||||
this._geoclueClientDbusProxy.RequestedAccuracyLevel = 4;
|
||||
logDebug('Connected to GeoClue client DBus proxy.');
|
||||
}
|
||||
|
||||
_disconnect_from_geoclue_dbus_proxy() {
|
||||
log_debug('Disconnecting from GeoClue DBus proxy...')
|
||||
this._geoclue_manager_dbus_proxy.DeleteClientSync(this._geoclue_client);
|
||||
this._geoclue_client = null;
|
||||
this._geoclue_client_dbus_proxy = null;
|
||||
this._geoclue_manager_dbus_proxy = null;
|
||||
log_debug('Disconnected from GeoClue DBus proxy.')
|
||||
}
|
||||
_disconnectFromGeoclueDbusProxy() {
|
||||
logDebug('Disconnecting from GeoClue DBus proxy...');
|
||||
this._geoclueManagerDbusProxy.DeleteClientSync(this._geoclueClient);
|
||||
this._geoclueClient = null;
|
||||
this._geoclueClientDbusProxy = null;
|
||||
this._geoclueManagerDbusProxy = null;
|
||||
logDebug('Disconnected from GeoClue DBus proxy.');
|
||||
}
|
||||
|
||||
_listen_to_location_updates() {
|
||||
log_debug('Listening to location updates...');
|
||||
this._location_updates_connect = this._geoclue_client_dbus_proxy.connectSignal('LocationUpdated', this._on_location_updated.bind(this));
|
||||
this._geoclue_client_dbus_proxy.StartSync();
|
||||
}
|
||||
_listenToLocationUpdates() {
|
||||
logDebug('Listening to location updates...');
|
||||
this._locationUpdatesConnect = this._geoclueClientDbusProxy.connectSignal('LocationUpdated', this._onLocationUpdated.bind(this));
|
||||
this._geoclueClientDbusProxy.StartSync();
|
||||
}
|
||||
|
||||
_stop_listening_to_location_updates() {
|
||||
this._geoclue_client_dbus_proxy.disconnectSignal(this._location_updates_connect);
|
||||
this._location_updates_connect = null;
|
||||
this._geoclue_client_dbus_proxy.StopSync();
|
||||
log_debug('Stopped listening to location updates.');
|
||||
}
|
||||
_stopListeningToLocationUpdates() {
|
||||
this._geoclueClientDbusProxy.disconnectSignal(this._locationUpdatesConnect);
|
||||
this._locationUpdatesConnect = null;
|
||||
this._geoclueClientDbusProxy.StopSync();
|
||||
logDebug('Stopped listening to location updates.');
|
||||
}
|
||||
|
||||
_on_location_updated(proxy, sender, [old_location_path, new_location_path]) {
|
||||
log_debug('Location has changed.');
|
||||
this._connect_to_geoclue_location_dbus_proxy(new_location_path);
|
||||
this._update_location();
|
||||
this._update_suntimes();
|
||||
}
|
||||
_onLocationUpdated(_proxy, _sender, [_oldLocationPath, newLocationPath]) {
|
||||
logDebug('Location has changed.');
|
||||
this._connectToGeoclueLocationDbusProxy(newLocationPath);
|
||||
this._updateLocation();
|
||||
this._updateSuntimes();
|
||||
}
|
||||
|
||||
_connect_to_geoclue_location_dbus_proxy(path) {
|
||||
if ( !path ) {
|
||||
path = this._geoclue_client_dbus_proxy.Location;
|
||||
}
|
||||
if ( path !== '/' ) {
|
||||
log_debug('Connecting to GeoClue location DBus proxy...');
|
||||
const GeoClueLocationProxy = Gio.DBusProxy.makeProxyWrapper(GEOCLUE_LOCATION_INTERFACE);
|
||||
this._geoclue_location_dbus_proxy = new GeoClueLocationProxy(
|
||||
Gio.DBus.system,
|
||||
'org.freedesktop.GeoClue2',
|
||||
path
|
||||
);
|
||||
log_debug('Connected to GeoClue location DBus proxy.');
|
||||
}
|
||||
}
|
||||
_connectToGeoclueLocationDbusProxy(path) {
|
||||
if (!path)
|
||||
path = this._geoclueClientDbusProxy.Location;
|
||||
if (path !== '/') {
|
||||
logDebug('Connecting to GeoClue location DBus proxy...');
|
||||
const GeoClueLocationProxy = Gio.DBusProxy.makeProxyWrapper(GEOCLUE_LOCATION_INTERFACE);
|
||||
this._geoclueLocationDbusProxy = new GeoClueLocationProxy(
|
||||
Gio.DBus.system,
|
||||
'org.freedesktop.GeoClue2',
|
||||
path
|
||||
);
|
||||
logDebug('Connected to GeoClue location DBus proxy.');
|
||||
}
|
||||
}
|
||||
|
||||
_disconnect_from_geoclue_location_dbus_proxy() {
|
||||
log_debug('Disconnecting from GeoClue location DBus proxy...');
|
||||
this._geoclue_location_dbus_proxy = null;
|
||||
log_debug('Disconnected from GeoClue location DBus proxy.');
|
||||
}
|
||||
_disconnectFromGeoclueLocationDbusProxy() {
|
||||
logDebug('Disconnecting from GeoClue location DBus proxy...');
|
||||
this._geoclueLocationDbusProxy = null;
|
||||
logDebug('Disconnected from GeoClue location DBus proxy.');
|
||||
}
|
||||
|
||||
_update_location() {
|
||||
if ( this._geoclue_location_dbus_proxy ) {
|
||||
log_debug('Updating location...');
|
||||
const latitude = this._geoclue_location_dbus_proxy.Latitude;
|
||||
const longitude = this._geoclue_location_dbus_proxy.Longitude;
|
||||
_updateLocation() {
|
||||
if (this._geoclueLocationDbusProxy) {
|
||||
logDebug('Updating location...');
|
||||
const latitude = this._geoclueLocationDbusProxy.Latitude;
|
||||
const longitude = this._geoclueLocationDbusProxy.Longitude;
|
||||
|
||||
this.location = new Map([
|
||||
['latitude', latitude],
|
||||
['longitude', longitude]
|
||||
]);
|
||||
log_debug(`Current location: (${latitude};${longitude})`);
|
||||
}
|
||||
}
|
||||
this.location = new Map([
|
||||
['latitude', latitude],
|
||||
['longitude', longitude],
|
||||
]);
|
||||
logDebug(`Current location: (${latitude};${longitude})`);
|
||||
}
|
||||
}
|
||||
|
||||
_update_suntimes() {
|
||||
if ( !this.location ) {
|
||||
return;
|
||||
}
|
||||
_updateSuntimes() {
|
||||
if (!this.location)
|
||||
return;
|
||||
|
||||
log_debug('Updating sun times...');
|
||||
logDebug('Updating sun times...');
|
||||
|
||||
Math.rad = degrees => degrees * Math.PI / 180;
|
||||
Math.deg = radians => radians * 180 / Math.PI;
|
||||
Math.rad = degrees => degrees * Math.PI / 180;
|
||||
Math.deg = radians => radians * 180 / Math.PI;
|
||||
|
||||
// Calculations from https://www.esrl.noaa.gov/gmd/grad/solcalc/calcdetails.html
|
||||
const latitude = this.location.get('latitude');
|
||||
const longitude = this.location.get('longitude');
|
||||
// Calculations from https://www.esrl.noaa.gov/gmd/grad/solcalc/calcdetails.html
|
||||
const latitude = this.location.get('latitude');
|
||||
const longitude = this.location.get('longitude');
|
||||
|
||||
const dt_now = GLib.DateTime.new_now_local();
|
||||
const dt_zero = GLib.DateTime.new_utc(1900, 1, 1, 0, 0, 0);
|
||||
const dtNow = GLib.DateTime.new_now_local();
|
||||
const dtZero = GLib.DateTime.new_utc(1900, 1, 1, 0, 0, 0);
|
||||
|
||||
const time_span = dt_now.difference(dt_zero);
|
||||
const timeSpan = dtNow.difference(dtZero);
|
||||
|
||||
const date = time_span / 1000 / 1000 / 60 / 60 / 24 + 2;
|
||||
const tz_offset = dt_now.get_utc_offset() / 1000 / 1000 / 60 / 60;
|
||||
const time_past_local_midnight = 0;
|
||||
const date = timeSpan / 1000 / 1000 / 60 / 60 / 24 + 2;
|
||||
const tzOffset = dtNow.get_utc_offset() / 1000 / 1000 / 60 / 60;
|
||||
const timePastLocalMidnight = 0;
|
||||
|
||||
const julian_day = date + 2415018.5 + time_past_local_midnight - tz_offset / 24;
|
||||
const julian_century = (julian_day - 2451545) / 36525;
|
||||
const geom_mean_long_sun = (280.46646 + julian_century * (36000.76983 + julian_century * 0.0003032)) % 360;
|
||||
const geom_mean_anom_sun = 357.52911 + julian_century * (35999.05029 - 0.0001537 * julian_century);
|
||||
const eccent_earth_orbit = 0.016708634 - julian_century * (0.000042037 + 0.0000001267 * julian_century);
|
||||
const sun_eq_of_ctr = Math.sin(Math.rad(geom_mean_anom_sun)) * (1.914602 - julian_century * (0.004817 + 0.000014 * julian_century)) + Math.sin(Math.rad(2 * geom_mean_anom_sun)) * (0.019993 - 0.000101 * julian_century) + Math.sin(Math.rad(3 * geom_mean_anom_sun)) * 0.000289;
|
||||
const sun_true_long = geom_mean_long_sun + sun_eq_of_ctr;
|
||||
const sun_app_long = sun_true_long - 0.00569 - 0.00478 * Math.sin(Math.rad(125.04 - 1934.136 * julian_century));
|
||||
const mean_obliq_ecliptic = 23 + (26 + ((21.448 - julian_century * (46.815 + julian_century * (0.00059 - julian_century * 0.001813)))) / 60) / 60;
|
||||
const obliq_corr = mean_obliq_ecliptic + 0.00256 * Math.cos(Math.rad(125.04 - 1934.136 * julian_century));
|
||||
const sun_declin = Math.deg(Math.asin(Math.sin(Math.rad(obliq_corr)) * Math.sin(Math.rad(sun_app_long))));
|
||||
const var_y = Math.tan(Math.rad(obliq_corr / 2)) * Math.tan(Math.rad(obliq_corr / 2));
|
||||
const eq_of_time = 4 * Math.deg(var_y * Math.sin(2 * Math.rad(geom_mean_long_sun)) - 2 * eccent_earth_orbit * Math.sin(Math.rad(geom_mean_anom_sun)) + 4 * eccent_earth_orbit * var_y * Math.sin(Math.rad(geom_mean_anom_sun)) * Math.cos(2 * Math.rad(geom_mean_long_sun)) - 0.5 * var_y * var_y * Math.sin(4 * Math.rad(geom_mean_long_sun)) - 1.25 * eccent_earth_orbit * eccent_earth_orbit * Math.sin(2 * Math.rad(geom_mean_anom_sun)));
|
||||
const ha_sunrise = Math.deg(Math.acos(Math.cos(Math.rad(90.833)) / (Math.cos(Math.rad(latitude)) * Math.cos(Math.rad(sun_declin))) - Math.tan(Math.rad(latitude)) * Math.tan(Math.rad(sun_declin))));
|
||||
const solar_noon = (720 - 4 * longitude - eq_of_time + tz_offset * 60) / 1440;
|
||||
const julianDay = date + 2415018.5 + timePastLocalMidnight - tzOffset / 24;
|
||||
const julianCentury = (julianDay - 2451545) / 36525;
|
||||
const geomMeanLongSun = (280.46646 + julianCentury * (36000.76983 + julianCentury * 0.0003032)) % 360;
|
||||
const geomMeanAnomSun = 357.52911 + julianCentury * (35999.05029 - 0.0001537 * julianCentury);
|
||||
const eccentEarthOrbit = 0.016708634 - julianCentury * (0.000042037 + 0.0000001267 * julianCentury);
|
||||
const sunEqOfCtr = Math.sin(Math.rad(geomMeanAnomSun)) * (1.914602 - julianCentury * (0.004817 + 0.000014 * julianCentury)) + Math.sin(Math.rad(2 * geomMeanAnomSun)) * (0.019993 - 0.000101 * julianCentury) + Math.sin(Math.rad(3 * geomMeanAnomSun)) * 0.000289;
|
||||
const sunTrueLong = geomMeanLongSun + sunEqOfCtr;
|
||||
const sunAppLong = sunTrueLong - 0.00569 - 0.00478 * Math.sin(Math.rad(125.04 - 1934.136 * julianCentury));
|
||||
const meanObliqEcliptic = 23 + (26 + ((21.448 - julianCentury * (46.815 + julianCentury * (0.00059 - julianCentury * 0.001813)))) / 60) / 60;
|
||||
const obliqCorr = meanObliqEcliptic + 0.00256 * Math.cos(Math.rad(125.04 - 1934.136 * julianCentury));
|
||||
const sunDeclin = Math.deg(Math.asin(Math.sin(Math.rad(obliqCorr)) * Math.sin(Math.rad(sunAppLong))));
|
||||
const varY = Math.tan(Math.rad(obliqCorr / 2)) * Math.tan(Math.rad(obliqCorr / 2));
|
||||
const eqOfTime = 4 * Math.deg(varY * Math.sin(2 * Math.rad(geomMeanLongSun)) - 2 * eccentEarthOrbit * Math.sin(Math.rad(geomMeanAnomSun)) + 4 * eccentEarthOrbit * varY * Math.sin(Math.rad(geomMeanAnomSun)) * Math.cos(2 * Math.rad(geomMeanLongSun)) - 0.5 * varY * varY * Math.sin(4 * Math.rad(geomMeanLongSun)) - 1.25 * eccentEarthOrbit * eccentEarthOrbit * Math.sin(2 * Math.rad(geomMeanAnomSun)));
|
||||
const haSunrise = Math.deg(Math.acos(Math.cos(Math.rad(90.833)) / (Math.cos(Math.rad(latitude)) * Math.cos(Math.rad(sunDeclin))) - Math.tan(Math.rad(latitude)) * Math.tan(Math.rad(sunDeclin))));
|
||||
const solarNoon = (720 - 4 * longitude - eqOfTime + tzOffset * 60) / 1440;
|
||||
|
||||
const sunrise_time = solar_noon - ha_sunrise * 4 / 1440;
|
||||
const sunset_time = solar_noon + ha_sunrise * 4 / 1440;
|
||||
const timeSunrise = solarNoon - haSunrise * 4 / 1440;
|
||||
const timeSunset = solarNoon + haSunrise * 4 / 1440;
|
||||
|
||||
const sunrise = sunrise_time * 24;
|
||||
const sunset = sunset_time * 24;
|
||||
const sunrise = timeSunrise * 24;
|
||||
const sunset = timeSunset * 24;
|
||||
|
||||
this._suntimes.set('sunrise', sunrise);
|
||||
this._suntimes.set('sunset', sunset);
|
||||
log_debug(`New sun times: (sunrise: ${sunrise}; sunset: ${sunset})`);
|
||||
}
|
||||
this._suntimes.set('sunrise', sunrise);
|
||||
this._suntimes.set('sunset', sunset);
|
||||
logDebug(`New sun times: (sunrise: ${sunrise}; sunset: ${sunset})`);
|
||||
}
|
||||
|
||||
_regularly_update_suntimes() {
|
||||
log_debug('Regularly updating sun times...');
|
||||
this._regularly_update_suntimes_timer = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 3600, () => {
|
||||
this._update_suntimes();
|
||||
return true; // Repeat the loop
|
||||
});
|
||||
}
|
||||
_regularlyUpdateSuntimes() {
|
||||
logDebug('Regularly updating sun times...');
|
||||
this._regularlyUpdateSuntimesTimer = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 3600, () => {
|
||||
this._updateSuntimes();
|
||||
return true; // Repeat the loop
|
||||
});
|
||||
}
|
||||
|
||||
_stop_regularly_updating_suntimes() {
|
||||
GLib.Source.remove(this._regularly_update_suntimes_timer);
|
||||
this._regularly_update_suntimes_timer = null;
|
||||
log_debug('Stopped regularly updating sun times.');
|
||||
}
|
||||
_stopRegularlyUpdatingSuntimes() {
|
||||
GLib.Source.remove(this._regularlyUpdateSuntimesTimer);
|
||||
this._regularlyUpdateSuntimesTimer = null;
|
||||
logDebug('Stopped regularly updating sun times.');
|
||||
}
|
||||
|
||||
_is_daytime() {
|
||||
const time = GLib.DateTime.new_now_local();
|
||||
const hour = time.get_hour() + time.get_minute() / 60 + time.get_second() / 3600;
|
||||
return ( hour >= this._suntimes.get('sunrise') && hour <= this._suntimes.get('sunset') );
|
||||
}
|
||||
_isDaytime() {
|
||||
const time = GLib.DateTime.new_now_local();
|
||||
const hour = time.get_hour() + time.get_minute() / 60 + time.get_second() / 3600;
|
||||
return hour >= this._suntimes.get('sunrise') && hour <= this._suntimes.get('sunset');
|
||||
}
|
||||
|
||||
_watch_for_time_change() {
|
||||
log_debug('Watching for time change...');
|
||||
this._time_change_timer = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1, () => {
|
||||
if ( !Me.imports.extension.enabled ) {
|
||||
// The extension doesn't exist anymore, quit the loop
|
||||
return false;
|
||||
}
|
||||
if ( this._previously_daytime !== this._is_daytime() ) {
|
||||
this._previously_daytime = this._is_daytime();
|
||||
this.emit('time-changed', this.time);
|
||||
}
|
||||
return true; // Repeat the loop
|
||||
});
|
||||
}
|
||||
_watchForTimeChange() {
|
||||
logDebug('Watching for time change...');
|
||||
this._timeChangeTimer = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1, () => {
|
||||
if (!Me.imports.extension.enabled) {
|
||||
// The extension doesn't exist anymore, quit the loop
|
||||
return false;
|
||||
}
|
||||
if (this._previouslyDaytime !== this._isDaytime()) {
|
||||
this._previouslyDaytime = this._isDaytime();
|
||||
this.emit('time-changed', this.time);
|
||||
}
|
||||
return true; // Repeat the loop
|
||||
});
|
||||
}
|
||||
|
||||
_stop_watching_for_time_change() {
|
||||
GLib.Source.remove(this._time_change_timer);
|
||||
log_debug('Stopped watching for time change.');
|
||||
}
|
||||
_stopWatchingForTimeChange() {
|
||||
GLib.Source.remove(this._timeChangeTimer);
|
||||
logDebug('Stopped watching for time change.');
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
Signals.addSignalMethods(TimerLocation.prototype);
|
||||
|
||||
@@ -16,20 +16,20 @@ You should have received a copy of the GNU General Public License along with
|
||||
this program. If not, see <http s ://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const { Gio, GLib } = imports.gi;
|
||||
const { Gio } = imports.gi;
|
||||
const { extensionUtils } = imports.misc;
|
||||
const Signals = imports.signals;
|
||||
|
||||
const Me = extensionUtils.getCurrentExtension();
|
||||
|
||||
const { log_debug } = Me.imports.utils;
|
||||
const { logDebug } = Me.imports.utils;
|
||||
|
||||
|
||||
const COLOR_INTERFACE = `
|
||||
<node>
|
||||
<interface name="org.gnome.SettingsDaemon.Color">
|
||||
<property name="NightLightActive" type="b" access="read"/>
|
||||
</interface>
|
||||
<interface name="org.gnome.SettingsDaemon.Color">
|
||||
<property name="NightLightActive" type="b" access="read"/>
|
||||
</interface>
|
||||
</node>`;
|
||||
|
||||
|
||||
@@ -41,68 +41,73 @@ const COLOR_INTERFACE = `
|
||||
*/
|
||||
var TimerNightlight = class {
|
||||
|
||||
enable() {
|
||||
log_debug('Enabling Night Light Timer...');
|
||||
this._connect_to_color_dbus_proxy();
|
||||
this._listen_to_nightlight_state();
|
||||
this.emit('time-changed', this.time);
|
||||
log_debug('Night Light Timer enabled.');
|
||||
}
|
||||
constructor() {
|
||||
this._colorDbusProxy = null;
|
||||
this._nightlightStateConnect = null;
|
||||
}
|
||||
|
||||
disable() {
|
||||
log_debug('Disabling Night Light Timer...');
|
||||
this._stop_listening_to_nightlight_state();
|
||||
this._disconnect_from_color_dbus_proxy();
|
||||
log_debug('Night Light Timer disabled.');
|
||||
}
|
||||
enable() {
|
||||
logDebug('Enabling Night Light Timer...');
|
||||
this._connectToColorDbusProxy();
|
||||
this._listenToNightlightState();
|
||||
this.emit('time-changed', this.time);
|
||||
logDebug('Night Light Timer enabled.');
|
||||
}
|
||||
|
||||
disable() {
|
||||
logDebug('Disabling Night Light Timer...');
|
||||
this._stopListeningToNightlightState();
|
||||
this._disconnectFromColorDbusProxy();
|
||||
logDebug('Night Light Timer disabled.');
|
||||
}
|
||||
|
||||
|
||||
get time() {
|
||||
return this._is_nightlight_active() ? 'night' : 'day';
|
||||
}
|
||||
get time() {
|
||||
return this._isNightlightActive() ? 'night' : 'day';
|
||||
}
|
||||
|
||||
|
||||
_connect_to_color_dbus_proxy() {
|
||||
log_debug('Connecting to Color DBus proxy...');
|
||||
const ColorProxy = Gio.DBusProxy.makeProxyWrapper(COLOR_INTERFACE);
|
||||
this._color_dbus_proxy = new ColorProxy(
|
||||
Gio.DBus.session,
|
||||
'org.gnome.SettingsDaemon.Color',
|
||||
'/org/gnome/SettingsDaemon/Color'
|
||||
);
|
||||
log_debug('Connected to Color DBus proxy.');
|
||||
}
|
||||
_connectToColorDbusProxy() {
|
||||
logDebug('Connecting to Color DBus proxy...');
|
||||
const ColorProxy = Gio.DBusProxy.makeProxyWrapper(COLOR_INTERFACE);
|
||||
this._colorDbusProxy = new ColorProxy(
|
||||
Gio.DBus.session,
|
||||
'org.gnome.SettingsDaemon.Color',
|
||||
'/org/gnome/SettingsDaemon/Color'
|
||||
);
|
||||
logDebug('Connected to Color DBus proxy.');
|
||||
}
|
||||
|
||||
_disconnect_from_color_dbus_proxy() {
|
||||
log_debug('Disconnecting from Color DBus proxy...');
|
||||
this._color_dbus_proxy = null;
|
||||
log_debug('Disconnected from Color DBus proxy.');
|
||||
}
|
||||
_disconnectFromColorDbusProxy() {
|
||||
logDebug('Disconnecting from Color DBus proxy...');
|
||||
this._colorDbusProxy = null;
|
||||
logDebug('Disconnected from Color DBus proxy.');
|
||||
}
|
||||
|
||||
_listen_to_nightlight_state() {
|
||||
log_debug('Listening to Night Light state...');
|
||||
this._nightlight_state_connect = this._color_dbus_proxy.connect(
|
||||
'g-properties-changed',
|
||||
this._on_nightlight_state_changed.bind(this)
|
||||
);
|
||||
}
|
||||
_listenToNightlightState() {
|
||||
logDebug('Listening to Night Light state...');
|
||||
this._nightlightStateConnect = this._colorDbusProxy.connect(
|
||||
'g-properties-changed',
|
||||
this._onNightlightStateChanged.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
_stop_listening_to_nightlight_state() {
|
||||
this._color_dbus_proxy.disconnect(this._nightlight_state_connect);
|
||||
log_debug('Stopped listening to Night Light state.');
|
||||
}
|
||||
_stopListeningToNightlightState() {
|
||||
this._colorDbusProxy.disconnect(this._nightlightStateConnect);
|
||||
logDebug('Stopped listening to Night Light state.');
|
||||
}
|
||||
|
||||
_on_nightlight_state_changed(sender, dbus_properties) {
|
||||
const properties = dbus_properties.deep_unpack();
|
||||
if ( properties.NightLightActive ) {
|
||||
log_debug('Night Light has become ' + (properties.NightLightActive.unpack() ? '' : 'in') + 'active.');
|
||||
this.emit('time-changed', this.time);
|
||||
}
|
||||
}
|
||||
_onNightlightStateChanged(_sender, dbusProperties) {
|
||||
const properties = dbusProperties.deep_unpack();
|
||||
if (properties.NightLightActive) {
|
||||
logDebug(`Night Light has become ${properties.NightLightActive.unpack() ? '' : 'in'}active.`);
|
||||
this.emit('time-changed', this.time);
|
||||
}
|
||||
}
|
||||
|
||||
_is_nightlight_active() {
|
||||
return this._color_dbus_proxy.NightLightActive;
|
||||
}
|
||||
_isNightlightActive() {
|
||||
return this._colorDbusProxy.NightLightActive;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
Signals.addSignalMethods(TimerNightlight.prototype);
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with
|
||||
this program. If not, see <http s ://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const { GLib, Shell, St } = imports.gi;
|
||||
const { Shell, St } = imports.gi;
|
||||
const { extensionUtils } = imports.misc;
|
||||
const Signals = imports.signals;
|
||||
|
||||
@@ -25,8 +25,8 @@ const { main, panelMenu } = imports.ui;
|
||||
const Me = extensionUtils.getCurrentExtension();
|
||||
|
||||
const e = Me.imports.extension;
|
||||
const { log_debug } = Me.imports.utils;
|
||||
const { key_binding_auto_repeat, get_actor } = Me.imports.compat;
|
||||
const { logDebug } = Me.imports.utils;
|
||||
const { keyBindingAutoRepeat, getActor } = Me.imports.compat;
|
||||
|
||||
/**
|
||||
* The On-demand Timer allows the user to manually switch between the day and
|
||||
@@ -36,85 +36,85 @@ const { key_binding_auto_repeat, get_actor } = Me.imports.compat;
|
||||
*/
|
||||
var TimerOndemand = class {
|
||||
|
||||
constructor() {
|
||||
this._button = null;
|
||||
this._icon = null;
|
||||
}
|
||||
constructor() {
|
||||
this._button = null;
|
||||
this._icon = null;
|
||||
}
|
||||
|
||||
enable() {
|
||||
log_debug('Enabling On-demand Timer ...');
|
||||
this._add_keybinding();
|
||||
this._add_button();
|
||||
log_debug('On-demand Timer enabled.');
|
||||
}
|
||||
enable() {
|
||||
logDebug('Enabling On-demand Timer ...');
|
||||
this._addKeybinding();
|
||||
this._addButton();
|
||||
logDebug('On-demand Timer enabled.');
|
||||
}
|
||||
|
||||
disable() {
|
||||
log_debug('Disabling On-demand Timer ...');
|
||||
this._remove_keybinding();
|
||||
this._remove_button();
|
||||
log_debug('On-demand Timer disabled.');
|
||||
}
|
||||
disable() {
|
||||
logDebug('Disabling On-demand Timer ...');
|
||||
this._removeKeybinding();
|
||||
this._removeButton();
|
||||
logDebug('On-demand Timer disabled.');
|
||||
}
|
||||
|
||||
|
||||
get time() {
|
||||
return e.settingsManager.ondemand_time;
|
||||
}
|
||||
get time() {
|
||||
return e.settingsManager.ondemandTime;
|
||||
}
|
||||
|
||||
_add_keybinding() {
|
||||
log_debug('Adding On-demand Timer keybinding...');
|
||||
// add our own keydinging handler
|
||||
main.wm.addKeybinding(
|
||||
'nightthemeswitcher-ondemand-keybinding',
|
||||
e.settingsManager._extensionsSettings,
|
||||
key_binding_auto_repeat(),
|
||||
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW,
|
||||
this._toggle_time.bind(this)
|
||||
);
|
||||
log_debug('Added On-demand Timer keybinding.');
|
||||
}
|
||||
_addKeybinding() {
|
||||
logDebug('Adding On-demand Timer keybinding...');
|
||||
// add our own keydinging handler
|
||||
main.wm.addKeybinding(
|
||||
'nightthemeswitcher-ondemand-keybinding',
|
||||
e.settingsManager._extensionsSettings,
|
||||
keyBindingAutoRepeat(),
|
||||
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW,
|
||||
this._toggleTime.bind(this)
|
||||
);
|
||||
logDebug('Added On-demand Timer keybinding.');
|
||||
}
|
||||
|
||||
_remove_keybinding() {
|
||||
log_debug('Removing On-demand Timer keybinding...');
|
||||
main.wm.removeKeybinding('nightthemeswitcher-ondemand-keybinding');
|
||||
log_debug('Removed On-demand Timer keybinding.');
|
||||
}
|
||||
_removeKeybinding() {
|
||||
logDebug('Removing On-demand Timer keybinding...');
|
||||
main.wm.removeKeybinding('nightthemeswitcher-ondemand-keybinding');
|
||||
logDebug('Removed On-demand Timer keybinding.');
|
||||
}
|
||||
|
||||
_add_button() {
|
||||
log_debug('Adding On-demand Timer button...');
|
||||
_addButton() {
|
||||
logDebug('Adding On-demand Timer button...');
|
||||
|
||||
this._icon = new St.Icon({
|
||||
icon_name: this._get_icon_name_for_current_time(),
|
||||
style_class: 'system-status-icon'
|
||||
});
|
||||
this._icon = new St.Icon({
|
||||
icon_name: this._getIconNameForCurrentTime(),
|
||||
style_class: 'system-status-icon',
|
||||
});
|
||||
|
||||
this._button = new panelMenu.Button(0.0);
|
||||
const button_actor = get_actor(this._button);
|
||||
button_actor.add_actor(this._icon);
|
||||
button_actor.connect(
|
||||
'button-press-event',
|
||||
this._toggle_time.bind(this)
|
||||
);
|
||||
main.panel.addToStatusArea('NightThemeSwitcherButton', this._button);
|
||||
this._button = new panelMenu.Button(0.0);
|
||||
const buttonActor = getActor(this._button);
|
||||
buttonActor.add_actor(this._icon);
|
||||
buttonActor.connect(
|
||||
'button-press-event',
|
||||
this._toggleTime.bind(this)
|
||||
);
|
||||
main.panel.addToStatusArea('NightThemeSwitcherButton', this._button);
|
||||
|
||||
log_debug('Added On-demand Timer button.');
|
||||
}
|
||||
logDebug('Added On-demand Timer button.');
|
||||
}
|
||||
|
||||
_remove_button() {
|
||||
log_debug('Removing On-demand Timer button...');
|
||||
this._button.destroy();
|
||||
log_debug('Removed On-demand Timer button.');
|
||||
}
|
||||
_removeButton() {
|
||||
logDebug('Removing On-demand Timer button...');
|
||||
this._button.destroy();
|
||||
logDebug('Removed On-demand Timer button.');
|
||||
}
|
||||
|
||||
_toggle_time() {
|
||||
e.settingsManager.ondemand_time = e.timer.time === 'day' ? 'night' : 'day';
|
||||
this.emit('time-changed', this.time);
|
||||
this._icon.icon_name = this._get_icon_name_for_current_time();
|
||||
_toggleTime() {
|
||||
e.settingsManager.ondemandTime = e.timer.time === 'day' ? 'night' : 'day';
|
||||
this.emit('time-changed', this.time);
|
||||
this._icon.icon_name = this._getIconNameForCurrentTime();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
_get_icon_name_for_current_time() {
|
||||
return e.timer.time === 'day' ? 'weather-clear-symbolic' : 'weather-clear-night-symbolic';
|
||||
}
|
||||
_getIconNameForCurrentTime() {
|
||||
return e.timer.time === 'day' ? 'weather-clear-symbolic' : 'weather-clear-night-symbolic';
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
Signals.addSignalMethods(TimerOndemand.prototype);
|
||||
|
||||
@@ -23,7 +23,7 @@ const Signals = imports.signals;
|
||||
const Me = extensionUtils.getCurrentExtension();
|
||||
|
||||
const e = Me.imports.extension;
|
||||
const { log_debug } = Me.imports.utils;
|
||||
const { logDebug } = Me.imports.utils;
|
||||
|
||||
|
||||
/**
|
||||
@@ -36,53 +36,54 @@ const { log_debug } = Me.imports.utils;
|
||||
*/
|
||||
var TimerSchedule = class {
|
||||
|
||||
constructor() {
|
||||
this._previously_daytime = null;
|
||||
}
|
||||
constructor() {
|
||||
this._previouslyDaytime = null;
|
||||
this._timeChangeTimer = null;
|
||||
}
|
||||
|
||||
enable() {
|
||||
log_debug('Enabling Schedule Timer...');
|
||||
this._watch_for_time_change();
|
||||
log_debug('Schedule Timer enabled.');
|
||||
}
|
||||
enable() {
|
||||
logDebug('Enabling Schedule Timer...');
|
||||
this._watchForTimeChange();
|
||||
logDebug('Schedule Timer enabled.');
|
||||
}
|
||||
|
||||
disable() {
|
||||
log_debug('Disabling Schedule Timer...');
|
||||
this._stop_watching_for_time_change();
|
||||
log_debug('Schedule Timer disabled.');
|
||||
}
|
||||
disable() {
|
||||
logDebug('Disabling Schedule Timer...');
|
||||
this._stopWatchingForTimeChange();
|
||||
logDebug('Schedule Timer disabled.');
|
||||
}
|
||||
|
||||
|
||||
get time() {
|
||||
return this._is_daytime() ? 'day' : 'night';
|
||||
}
|
||||
get time() {
|
||||
return this._isDaytime() ? 'day' : 'night';
|
||||
}
|
||||
|
||||
|
||||
_is_daytime() {
|
||||
const time = GLib.DateTime.new_now_local();
|
||||
const hour = time.get_hour() + time.get_minute() / 60 + time.get_second() / 3600;
|
||||
return ( hour >= e.settingsManager.schedule_sunrise && hour <= e.settingsManager.schedule_sunset );
|
||||
}
|
||||
_isDaytime() {
|
||||
const time = GLib.DateTime.new_now_local();
|
||||
const hour = time.get_hour() + time.get_minute() / 60 + time.get_second() / 3600;
|
||||
return hour >= e.settingsManager.scheduleSunrise && hour <= e.settingsManager.scheduleSunset;
|
||||
}
|
||||
|
||||
_watch_for_time_change() {
|
||||
log_debug('Watching for time change...');
|
||||
this._time_change_timer = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1, () => {
|
||||
if ( !Me.imports.extension.enabled ) {
|
||||
// The extension doesn't exist anymore, quit the loop
|
||||
return false;
|
||||
}
|
||||
if ( this._previously_daytime !== this._is_daytime() ) {
|
||||
this._previously_daytime = this._is_daytime();
|
||||
this.emit('time-changed', this.time);
|
||||
}
|
||||
return true; // Repeat the loop
|
||||
});
|
||||
}
|
||||
_watchForTimeChange() {
|
||||
logDebug('Watching for time change...');
|
||||
this._timeChangeTimer = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1, () => {
|
||||
if (!Me.imports.extension.enabled) {
|
||||
// The extension doesn't exist anymore, quit the loop
|
||||
return false;
|
||||
}
|
||||
if (this._previouslyDaytime !== this._isDaytime()) {
|
||||
this._previouslyDaytime = this._isDaytime();
|
||||
this.emit('time-changed', this.time);
|
||||
}
|
||||
return true; // Repeat the loop
|
||||
});
|
||||
}
|
||||
|
||||
_stop_watching_for_time_change() {
|
||||
GLib.Source.remove(this._time_change_timer);
|
||||
log_debug('Stopped watching for time change.');
|
||||
}
|
||||
_stopWatchingForTimeChange() {
|
||||
GLib.Source.remove(this._timeChangeTimer);
|
||||
logDebug('Stopped watching for time change.');
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
Signals.addSignalMethods(TimerSchedule.prototype);
|
||||
|
||||
Reference in New Issue
Block a user