Merge branch 'refactor/ondemand-timer' into 'master'

Refactor On-demand Timer

See merge request rmnvgr/nightthemeswitcher-gnome-shell-extension!41
This commit is contained in:
Romain
2020-08-04 04:15:45 +00:00
2 changed files with 43 additions and 3 deletions
+14
View File
@@ -64,6 +64,7 @@ var SettingsManager = class {
this._cursorVariantOriginalChangedConnect = this._extensionsSettings.connect('changed::cursor-variant-original', this._onCursorVariantOriginalChanged.bind(this));
this._timeSourceChangedConnect = this._extensionsSettings.connect('changed::time-source', this._onTimeSourceChanged.bind(this));
this._manualTimeSourceChangedConnect = this._extensionsSettings.connect('changed::manual-time-source', this._onManualTimeSourceChanged.bind(this));
this._ondemandKeybindingChangedConnect = this._extensionsSettings.connect('changed::nightthemeswitcher-ondemand-keybinding', this._onOndemandKeybindingChanged.bind(this));
this._commandsStatusConnect = this._extensionsSettings.connect('changed::commands-enabled', this._onCommandsStatusChanged.bind(this));
this._backgroundsStatusConnect = this._extensionsSettings.connect('changed::backgrounds-enabled', this._onBackgroundsStatusChanged.bind(this));
this._backgroundDayChangedConnect = this._extensionsSettings.connect('changed::background-day', this._onBackgroundDayChanged.bind(this));
@@ -99,6 +100,7 @@ var SettingsManager = class {
this._extensionsSettings.disconnect(this._cursorVariantOriginalChangedConnect);
this._extensionsSettings.disconnect(this._timeSourceChangedConnect);
this._extensionsSettings.disconnect(this._manualTimeSourceChangedConnect);
this._extensionsSettings.disconnect(this._ondemandKeybindingChangedConnect);
this._extensionsSettings.disconnect(this._commandsStatusConnect);
this._extensionsSettings.disconnect(this._backgroundsStatusConnect);
this._extensionsSettings.disconnect(this._backgroundDayChangedConnect);
@@ -312,6 +314,10 @@ var SettingsManager = class {
}
}
get ondemandKeybinding() {
return this._extensionsSettings.get_strv('nightthemeswitcher-ondemand-keybinding')[0];
}
get scheduleSunrise() {
return this._extensionsSettings.get_double('schedule-sunrise');
}
@@ -554,6 +560,14 @@ var SettingsManager = class {
this.emit('manual-time-source-changed', this.manualTimeSource);
}
_onOndemandKeybindingChanged(_settings, _changedKey) {
if (this.ondemandKeybinding)
logDebug(`On-demand keybinding has changed to ${this.ondemandKeybinding}.`);
else
logDebug('On-demand keybinding has been cleared.');
this.emit('ondemand-keybinding-changed', this.ondemandKeybinding);
}
/* Commands */
+29 -3
View File
@@ -39,19 +39,23 @@ var TimerOndemand = class {
constructor() {
this._button = null;
this._icon = null;
this._ondemandKeybindingConnect = null;
}
enable() {
logDebug('Enabling On-demand Timer ...');
logDebug('Enabling On-demand Timer...');
this._connectSettings();
this._addKeybinding();
this._addButton();
this.emit('time-changed', this.time);
logDebug('On-demand Timer enabled.');
}
disable() {
logDebug('Disabling On-demand Timer ...');
logDebug('Disabling On-demand Timer...');
this._removeKeybinding();
this._removeButton();
this._disconnectSettings();
logDebug('On-demand Timer disabled.');
}
@@ -60,9 +64,31 @@ var TimerOndemand = class {
return e.settingsManager.ondemandTime;
}
_connectSettings() {
logDebug('Connecting On-demand Timer to settings...');
this._ondemandKeybindingConnect = e.settingsManager.connect('ondemand-keybinding-changed', this._onOndemandKeybindingChanged.bind(this));
}
_disconnectSettings() {
logDebug('Disconnecting On-demand Timer from settings...');
if (this._ondemandKeybindingConnect) {
e.settingsManager.disconnect(this._ondemandKeybindingConnect);
this._ondemandKeybindingConnect = null;
}
}
_onOndemandKeybindingChanged(_settings, _keybinding) {
this._removeKeybinding();
this._addKeybinding();
}
_addKeybinding() {
if (!e.settingsManager.ondemandKeybinding)
return;
logDebug('Adding On-demand Timer keybinding...');
// add our own keydinging handler
main.wm.addKeybinding(
'nightthemeswitcher-ondemand-keybinding',
e.settingsManager._extensionsSettings,