Timer: Remove night light timer
This commit is contained in:
@@ -65,18 +65,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
</key>
|
||||
</schema>
|
||||
<schema id="org.gnome.shell.extensions.nightthemeswitcher.time" path="/org/gnome/shell/extensions/nightthemeswitcher/time/">
|
||||
<key name="time-source" type="s">
|
||||
<choices>
|
||||
<choice value="nightlight"/>
|
||||
<choice value="location"/>
|
||||
<choice value="schedule"/>
|
||||
</choices>
|
||||
<default>"schedule"</default>
|
||||
</key>
|
||||
<key name="nightthemeswitcher-ondemand-keybinding" type="as">
|
||||
<default><![CDATA[['<Shift><Super>t']]]></default>
|
||||
</key>
|
||||
<key name="manual-time-source" type="b">
|
||||
<key name="manual-schedule" type="b">
|
||||
<default>false</default>
|
||||
</key>
|
||||
<key name="schedule-sunrise" type="d">
|
||||
|
||||
+20
-38
@@ -10,29 +10,41 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
<property name="icon-name">nightthemeswitcher-schedule-symbolic</property>
|
||||
<child>
|
||||
<object class="AdwPreferencesGroup">
|
||||
<property name="title" translatable="yes">Manual schedule</property>
|
||||
<property name="description" translatable="yes">Your location will be used to calculate the current sunrise and sunset times. If you prefer, you can set a manual schedule. It will also be used when your location is unavailable.</property>
|
||||
<child type="header-suffix">
|
||||
<object class="GtkSwitch" id="manual_schedule_switch">
|
||||
<property name="valign">start</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwActionRow">
|
||||
<property name="title" translatable="yes">Manual time source</property>
|
||||
<property name="subtitle" translatable="yes">The extension will try to use Night Light or Location Services to automatically set your current sunrise and sunset times if they are enabled. If you prefer, you can manually choose a time source.</property>
|
||||
<property name="activatable-widget">manual_time_source_switch</property>
|
||||
<property name="title" translatable="yes">Sunrise</property>
|
||||
<child>
|
||||
<object class="GtkSwitch" id="manual_time_source_switch">
|
||||
<object class="TimeChooser" id="schedule_sunrise_time_chooser">
|
||||
<property name="margin-top">12</property>
|
||||
<property name="margin-bottom">12</property>
|
||||
<property name="valign">center</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwComboRow" id="time_source_combo_row">
|
||||
<property name="title" translatable="yes">Time source</property>
|
||||
<property name="sensitive" bind-source="manual_time_source_switch" bind-property="active" bind-flags="sync-create"/>
|
||||
<object class="AdwActionRow">
|
||||
<property name="title" translatable="yes">Sunset</property>
|
||||
<child>
|
||||
<object class="TimeChooser" id="schedule_sunset_time_chooser">
|
||||
<property name="margin-top">12</property>
|
||||
<property name="margin-bottom">12</property>
|
||||
<property name="valign">center</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwPreferencesGroup">
|
||||
<property name="title" translatable="yes">Advanced</property>
|
||||
<child>
|
||||
<object class="AdwActionRow">
|
||||
<property name="title" translatable="yes">Keyboard shortcut</property>
|
||||
@@ -44,36 +56,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwExpanderRow">
|
||||
<property name="title" translatable="yes">Manual schedule</property>
|
||||
<property name="subtitle" translatable="yes">These settings only apply when using the manual schedule as the time source.</property>
|
||||
<child>
|
||||
<object class="AdwActionRow">
|
||||
<property name="title" translatable="yes">Sunrise</property>
|
||||
<child>
|
||||
<object class="TimeChooser" id="schedule_sunrise_time_chooser">
|
||||
<property name="margin-top">12</property>
|
||||
<property name="margin-bottom">12</property>
|
||||
<property name="valign">center</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwActionRow">
|
||||
<property name="title" translatable="yes">Sunset</property>
|
||||
<child>
|
||||
<object class="TimeChooser" id="schedule_sunset_time_chooser">
|
||||
<property name="margin-top">12</property>
|
||||
<property name="margin-bottom">12</property>
|
||||
<property name="valign">center</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
|
||||
@@ -35,7 +35,6 @@ modules = [
|
||||
'modules/SwitcherTheme.js',
|
||||
'modules/Timer.js',
|
||||
'modules/TimerLocation.js',
|
||||
'modules/TimerNightlight.js',
|
||||
'modules/TimerSchedule.js',
|
||||
]
|
||||
preferences = [
|
||||
|
||||
+9
-48
@@ -12,7 +12,6 @@ const Me = extensionUtils.getCurrentExtension();
|
||||
const debug = Me.imports.debug;
|
||||
|
||||
const { Time } = Me.imports.enums.Time;
|
||||
const { TimerNightlight } = Me.imports.modules.TimerNightlight;
|
||||
const { TimerLocation } = Me.imports.modules.TimerLocation;
|
||||
const { TimerSchedule } = Me.imports.modules.TimerSchedule;
|
||||
|
||||
@@ -23,19 +22,13 @@ const { TimerSchedule } = Me.imports.modules.TimerSchedule;
|
||||
* They can connect to its 'time-changed' signal and ask its 'time' property
|
||||
* for the current time.
|
||||
*
|
||||
* It will try to use one of these three different time sources, in this order
|
||||
* of preference:
|
||||
* - 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.
|
||||
* It will try to use the current location as a time source but will fall back
|
||||
* to a manual schedule if the location services are disabled or if the user
|
||||
* forced the manual schedule in the preferences.
|
||||
*/
|
||||
var Timer = class {
|
||||
#settings;
|
||||
#interfaceSettings;
|
||||
#colorSettings;
|
||||
#locationSettings;
|
||||
#time;
|
||||
|
||||
@@ -47,7 +40,6 @@ var Timer = class {
|
||||
constructor() {
|
||||
this.#settings = extensionUtils.getSettings(`${Me.metadata['settings-schema']}.time`);
|
||||
this.#interfaceSettings = new Gio.Settings({ schema: 'org.gnome.desktop.interface' });
|
||||
this.#colorSettings = new Gio.Settings({ schema: 'org.gnome.settings-daemon.plugins.color' });
|
||||
this.#locationSettings = new Gio.Settings({ schema: 'org.gnome.system.location' });
|
||||
this.#time = this.#interfaceSettings.get_string('color-scheme') === 'prefer-dark' ? Time.NIGHT : Time.DAY;
|
||||
}
|
||||
@@ -65,7 +57,7 @@ var Timer = class {
|
||||
disable() {
|
||||
debug.message('Disabling Timer...');
|
||||
this.#removeKeybinding();
|
||||
this.#disconnectSources();
|
||||
this.#disconnectSource();
|
||||
this.#disableSource();
|
||||
this.#disconnectSettings();
|
||||
debug.message('Timer disabled.');
|
||||
@@ -89,17 +81,13 @@ var Timer = class {
|
||||
|
||||
#connectSettings() {
|
||||
debug.message('Connecting Timer to settings...');
|
||||
this.#settingsConnections.push({
|
||||
settings: this.#colorSettings,
|
||||
id: this.#colorSettings.connect('changed::night-light-enabled', this.#onSourceChanged.bind(this)),
|
||||
});
|
||||
this.#settingsConnections.push({
|
||||
settings: this.#locationSettings,
|
||||
id: this.#locationSettings.connect('changed::enabled', this.#onSourceChanged.bind(this)),
|
||||
});
|
||||
this.#settingsConnections.push({
|
||||
settings: this.#settings,
|
||||
id: this.#settings.connect('changed::time-source', this.#onTimeSourceChanged.bind(this)),
|
||||
id: this.#settings.connect('changed::manual-schedule', this.#onSourceChanged.bind(this)),
|
||||
});
|
||||
this.#settingsConnections.push({
|
||||
settings: this.#settings,
|
||||
@@ -120,9 +108,6 @@ var Timer = class {
|
||||
#createSource() {
|
||||
const source = this.#getSource();
|
||||
switch (source) {
|
||||
case 'nightlight':
|
||||
this.#source = new TimerNightlight();
|
||||
break;
|
||||
case 'location':
|
||||
this.#source = new TimerLocation();
|
||||
break;
|
||||
@@ -160,11 +145,6 @@ var Timer = class {
|
||||
this.enable();
|
||||
}
|
||||
|
||||
#onTimeSourceChanged() {
|
||||
if (this.#settings.get_boolean('manual-time-source'))
|
||||
this.#onSourceChanged();
|
||||
}
|
||||
|
||||
#onOndemandKeybindingChanged() {
|
||||
this.#removeKeybinding();
|
||||
this.#addKeybinding();
|
||||
@@ -181,29 +161,10 @@ var Timer = class {
|
||||
|
||||
#getSource() {
|
||||
debug.message('Getting time source...');
|
||||
|
||||
let source;
|
||||
if (this.#settings.get_boolean('manual-time-source')) {
|
||||
source = this.#settings.get_string('time-source');
|
||||
debug.message(`Time source is forced to ${source}.`);
|
||||
if (
|
||||
(source === 'nightlight' && !this.#colorSettings.get_boolean('night-light-enabled')) ||
|
||||
(source === 'location' && !this.#locationSettings.get_boolean('enabled'))
|
||||
) {
|
||||
debug.message(`Unable to choose ${source} time source, falling back to manual schedule.`);
|
||||
source = 'schedule';
|
||||
this.#settings.set_string('time-source', source);
|
||||
}
|
||||
} else {
|
||||
if (this.#colorSettings.get_boolean('night-light-enabled'))
|
||||
source = 'nightlight';
|
||||
else if (this.#locationSettings.get_boolean('enabled'))
|
||||
source = 'location';
|
||||
else
|
||||
source = 'schedule';
|
||||
debug.message(`Time source is ${source}.`);
|
||||
this.#settings.set_string('time-source', source);
|
||||
}
|
||||
let source = 'schedule';
|
||||
if (this.#locationSettings.get_boolean('enabled') && !this.#settings.get_boolean('manual-schedule'))
|
||||
source = 'location';
|
||||
debug.message(`Time source is ${source}.`);
|
||||
return source;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2020-2022 Romain Vigier <contact AT romainvigier.fr>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
const { Gio } = imports.gi;
|
||||
const { extensionUtils } = imports.misc;
|
||||
const Signals = imports.signals;
|
||||
|
||||
const Me = extensionUtils.getCurrentExtension();
|
||||
|
||||
const debug = Me.imports.debug;
|
||||
|
||||
const { Time } = Me.imports.enums.Time;
|
||||
|
||||
|
||||
const COLOR_INTERFACE = `
|
||||
<node>
|
||||
<interface name="org.gnome.SettingsDaemon.Color">
|
||||
<property name="DisabledUntilTomorrow" type="b" access="readwrite"/>
|
||||
<property name="NightLightActive" type="b" access="read"/>
|
||||
</interface>
|
||||
</node>`;
|
||||
|
||||
|
||||
/**
|
||||
* The Night Light Timer uses Night Light as a time source.
|
||||
*
|
||||
* It connects to the Color SettingsDaemon DBus proxy to listen to the
|
||||
* 'NightLightActive' property and will signal any change.
|
||||
*/
|
||||
var TimerNightlight = class {
|
||||
#cancellable = null;
|
||||
#colorDbusProxy = null;
|
||||
#nightlightStateConnection = null;
|
||||
#previousNightlightState = null;
|
||||
|
||||
async enable() {
|
||||
debug.message('Enabling Night Light Timer...');
|
||||
this.#cancellable = new Gio.Cancellable();
|
||||
this.#colorDbusProxy = await this.#createColorDbusProxy();
|
||||
this.#listenToNightlightState();
|
||||
this.emit('time-changed', this.time);
|
||||
debug.message('Night Light Timer enabled.');
|
||||
}
|
||||
|
||||
disable() {
|
||||
debug.message('Disabling Night Light Timer...');
|
||||
this.#stopListeningToNightlightState();
|
||||
this.#colorDbusProxy = null;
|
||||
this.#cancellable.cancel();
|
||||
this.#cancellable = null;
|
||||
debug.message('Night Light Timer disabled.');
|
||||
}
|
||||
|
||||
|
||||
get time() {
|
||||
return this.#isNightlightActive() ? Time.NIGHT : Time.DAY;
|
||||
}
|
||||
|
||||
|
||||
#createColorDbusProxy() {
|
||||
debug.message('Creating the Color DBus proxy...');
|
||||
const ColorProxy = Gio.DBusProxy.makeProxyWrapper(COLOR_INTERFACE);
|
||||
return new Promise((resolve, reject) => {
|
||||
ColorProxy(
|
||||
Gio.DBus.session,
|
||||
'org.gnome.SettingsDaemon.Color',
|
||||
'/org/gnome/SettingsDaemon/Color',
|
||||
(proxy, error) => {
|
||||
if (error === null) {
|
||||
debug.message('Created the Color DBus proxy.');
|
||||
resolve(proxy);
|
||||
} else {
|
||||
reject(error);
|
||||
}
|
||||
},
|
||||
this.#cancellable,
|
||||
Gio.DBusProxyFlags.NONE
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#listenToNightlightState() {
|
||||
debug.message('Listening to Night Light state...');
|
||||
this.#nightlightStateConnection = this.#colorDbusProxy.connect(
|
||||
'g-properties-changed',
|
||||
this.#onNightlightStateChanged.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
#stopListeningToNightlightState() {
|
||||
if (this.#colorDbusProxy && this.#nightlightStateConnection) {
|
||||
this.#colorDbusProxy.disconnect(this.#nightlightStateConnection);
|
||||
this.#nightlightStateConnection = null;
|
||||
}
|
||||
debug.message('Stopped listening to Night Light state.');
|
||||
}
|
||||
|
||||
|
||||
#onNightlightStateChanged(_sender, _dbusProperties) {
|
||||
const newState = this.#isNightlightActive();
|
||||
if (newState !== this.#previousNightlightState) {
|
||||
debug.message(`Night Light has become ${newState ? '' : 'in'}active.`);
|
||||
this.#previousNightlightState = newState;
|
||||
this.emit('time-changed', newState ? Time.NIGHT : Time.DAY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#isNightlightActive() {
|
||||
return this.#colorDbusProxy.NightLightActive;
|
||||
}
|
||||
};
|
||||
Signals.addSignalMethods(TimerNightlight.prototype);
|
||||
@@ -24,7 +24,6 @@ src/modules/SwitcherCommands.js
|
||||
src/modules/SwitcherTheme.js
|
||||
src/modules/Timer.js
|
||||
src/modules/TimerLocation.js
|
||||
src/modules/TimerNightlight.js
|
||||
src/modules/TimerSchedule.js
|
||||
|
||||
src/preferences/BackgroundButton.js
|
||||
|
||||
@@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: nightthemeswitcher@romainvigier.fr\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2022-08-16 02:19+0200\n"
|
||||
"POT-Creation-Date: 2022-08-16 03:46+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@@ -50,7 +50,7 @@ msgstr ""
|
||||
msgid "Run commands"
|
||||
msgstr ""
|
||||
|
||||
#: src/data/ui/CommandsPage.ui:21 src/data/ui/SchedulePage.ui:53
|
||||
#: src/data/ui/CommandsPage.ui:21 src/data/ui/SchedulePage.ui:22
|
||||
msgid "Sunrise"
|
||||
msgstr ""
|
||||
|
||||
@@ -59,7 +59,7 @@ msgstr ""
|
||||
msgid "notify-send \"Hello sunshine!\""
|
||||
msgstr ""
|
||||
|
||||
#: src/data/ui/CommandsPage.ui:35 src/data/ui/SchedulePage.ui:65
|
||||
#: src/data/ui/CommandsPage.ui:35 src/data/ui/SchedulePage.ui:34
|
||||
msgid "Sunset"
|
||||
msgstr ""
|
||||
|
||||
@@ -88,36 +88,19 @@ msgstr ""
|
||||
msgid "Schedule"
|
||||
msgstr ""
|
||||
|
||||
#: src/data/ui/SchedulePage.ui:15
|
||||
msgid "Manual time source"
|
||||
msgstr ""
|
||||
|
||||
#: src/data/ui/SchedulePage.ui:16
|
||||
msgid ""
|
||||
"The extension will try to use Night Light or Location Services to "
|
||||
"automatically set your current sunrise and sunset times if they are enabled. "
|
||||
"If you prefer, you can manually choose a time source."
|
||||
msgstr ""
|
||||
|
||||
#: src/data/ui/SchedulePage.ui:27
|
||||
msgid "Time source"
|
||||
msgstr ""
|
||||
|
||||
#: src/data/ui/SchedulePage.ui:35
|
||||
msgid "Advanced"
|
||||
msgstr ""
|
||||
|
||||
#: src/data/ui/SchedulePage.ui:38
|
||||
msgid "Keyboard shortcut"
|
||||
msgstr ""
|
||||
|
||||
#: src/data/ui/SchedulePage.ui:49 src/preferences/SchedulePage.js:48
|
||||
#: src/data/ui/SchedulePage.ui:13
|
||||
msgid "Manual schedule"
|
||||
msgstr ""
|
||||
|
||||
#: src/data/ui/SchedulePage.ui:50
|
||||
#: src/data/ui/SchedulePage.ui:14
|
||||
msgid ""
|
||||
"These settings only apply when using the manual schedule as the time source."
|
||||
"Your location will be used to calculate the current sunrise and sunset "
|
||||
"times. If you prefer, you can set a manual schedule. It will also be used "
|
||||
"when your location is unavailable."
|
||||
msgstr ""
|
||||
|
||||
#: src/data/ui/SchedulePage.ui:50
|
||||
msgid "Keyboard shortcut"
|
||||
msgstr ""
|
||||
|
||||
#: src/data/ui/ShortcutButton.ui:15
|
||||
@@ -188,14 +171,6 @@ msgstr ""
|
||||
msgid "Version %d"
|
||||
msgstr ""
|
||||
|
||||
#: src/preferences/SchedulePage.js:36
|
||||
msgid "Night Light"
|
||||
msgstr ""
|
||||
|
||||
#: src/preferences/SchedulePage.js:40
|
||||
msgid "Location Services"
|
||||
msgstr ""
|
||||
|
||||
#: src/preferences/ThemesPage.js:50
|
||||
msgid "Default"
|
||||
msgstr ""
|
||||
|
||||
@@ -5,20 +5,14 @@ const { Adw, Gio, GLib, GObject, Gtk } = imports.gi;
|
||||
const { extensionUtils } = imports.misc;
|
||||
|
||||
const Me = extensionUtils.getCurrentExtension();
|
||||
const _ = extensionUtils.gettext;
|
||||
|
||||
const utils = Me.imports.utils;
|
||||
|
||||
const { DropDownChoice } = Me.imports.preferences.DropDownChoice;
|
||||
|
||||
|
||||
var SchedulePage = GObject.registerClass({
|
||||
GTypeName: 'SchedulePage',
|
||||
Template: 'resource:///org/gnome/shell/extensions/nightthemeswitcher/preferences/ui/SchedulePage.ui',
|
||||
InternalChildren: [
|
||||
'manual_schedule_switch',
|
||||
'keyboard_shortcut_button',
|
||||
'manual_time_source_switch',
|
||||
'time_source_combo_row',
|
||||
'schedule_sunrise_time_chooser',
|
||||
'schedule_sunset_time_chooser',
|
||||
],
|
||||
@@ -26,40 +20,8 @@ var SchedulePage = GObject.registerClass({
|
||||
constructor(props = {}) {
|
||||
super(props);
|
||||
const settings = extensionUtils.getSettings(`${Me.metadata['settings-schema']}.time`);
|
||||
const colorSettings = new Gio.Settings({ schema: 'org.gnome.settings-daemon.plugins.color' });
|
||||
const locationSettings = new Gio.Settings({ schema: 'org.gnome.system.location' });
|
||||
|
||||
settings.bind('manual-time-source', this._manual_time_source_switch, 'active', Gio.SettingsBindFlags.DEFAULT);
|
||||
|
||||
const choiceFilter = new Gtk.BoolFilter({ expression: Gtk.PropertyExpression.new(DropDownChoice, null, 'enabled') });
|
||||
|
||||
const nightlightChoice = new DropDownChoice({ id: 'nightlight', title: _('Night Light') });
|
||||
nightlightChoice.connect('notify::enabled', () => choiceFilter.changed(Gtk.FilterChange.DIFFERENT));
|
||||
colorSettings.bind('night-light-enabled', nightlightChoice, 'enabled', Gio.SettingsBindFlags.GET);
|
||||
|
||||
const locationChoice = new DropDownChoice({ id: 'location', title: _('Location Services') });
|
||||
locationChoice.connect('notify::enabled', () => choiceFilter.changed(Gtk.FilterChange.DIFFERENT));
|
||||
locationSettings.bind('enabled', locationChoice, 'enabled', Gio.SettingsBindFlags.GET);
|
||||
|
||||
const timeSources = Gio.ListStore.new(DropDownChoice);
|
||||
timeSources.splice(0, 0, [
|
||||
nightlightChoice,
|
||||
locationChoice,
|
||||
new DropDownChoice({ id: 'schedule', title: _('Manual schedule') }),
|
||||
]);
|
||||
|
||||
this._time_source_combo_row.model = new Gtk.FilterListModel({
|
||||
model: timeSources,
|
||||
filter: choiceFilter,
|
||||
});
|
||||
this._time_source_combo_row.expression = Gtk.PropertyExpression.new(DropDownChoice, null, 'title');
|
||||
this._time_source_combo_row.connect('notify::selected-item', () => settings.set_string('time-source', this._time_source_combo_row.selected_item.id));
|
||||
const updateTimeSourceComboRowState = () => {
|
||||
this._time_source_combo_row.selected = utils.findItemPositionInModel(this._time_source_combo_row.model, item => item.id === settings.get_string('time-source'));
|
||||
this._time_source_combo_row.sensitive = settings.get_boolean('manual-time-source');
|
||||
};
|
||||
settings.connect('changed::time-source', () => updateTimeSourceComboRowState());
|
||||
updateTimeSourceComboRowState();
|
||||
settings.bind('manual-schedule', this._manual_schedule_switch, 'active', Gio.SettingsBindFlags.DEFAULT);
|
||||
|
||||
settings.bind('schedule-sunrise', this._schedule_sunrise_time_chooser, 'time', Gio.SettingsBindFlags.DEFAULT);
|
||||
settings.bind('schedule-sunset', this._schedule_sunset_time_chooser, 'time', Gio.SettingsBindFlags.DEFAULT);
|
||||
|
||||
Reference in New Issue
Block a user