From e7555c326fd86017d60052a74e4ab55d695959dd Mon Sep 17 00:00:00 2001 From: Romain Vigier Date: Tue, 16 Aug 2022 03:46:18 +0200 Subject: [PATCH] Timer: Remove night light timer --- ....extensions.nightthemeswitcher.gschema.xml | 10 +- src/data/ui/SchedulePage.ui | 58 ++++----- src/meson.build | 1 - src/modules/Timer.js | 57 ++------- src/modules/TimerNightlight.js | 113 ------------------ src/po/POTFILES | 1 - src/po/nightthemeswitcher@romainvigier.fr.pot | 49 ++------ src/preferences/SchedulePage.js | 42 +------ 8 files changed, 44 insertions(+), 287 deletions(-) delete mode 100644 src/modules/TimerNightlight.js diff --git a/src/data/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml b/src/data/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml index 798d0fc..ae050b3 100644 --- a/src/data/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml +++ b/src/data/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml @@ -65,18 +65,10 @@ SPDX-License-Identifier: GPL-3.0-or-later - - - - - - - "schedule" - t']]]> - + false diff --git a/src/data/ui/SchedulePage.ui b/src/data/ui/SchedulePage.ui index f981ec2..c8cf450 100644 --- a/src/data/ui/SchedulePage.ui +++ b/src/data/ui/SchedulePage.ui @@ -10,29 +10,41 @@ SPDX-License-Identifier: GPL-3.0-or-later nightthemeswitcher-schedule-symbolic + Manual schedule + 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. + + + start + + - Manual time source - 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. - manual_time_source_switch + Sunrise - + + 12 + 12 center - - Time source - + + Sunset + + + 12 + 12 + center + + - Advanced Keyboard shortcut @@ -44,36 +56,6 @@ SPDX-License-Identifier: GPL-3.0-or-later - - - Manual schedule - These settings only apply when using the manual schedule as the time source. - - - Sunrise - - - 12 - 12 - center - - - - - - - Sunset - - - 12 - 12 - center - - - - - - diff --git a/src/meson.build b/src/meson.build index 2f18f98..3382c2a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -35,7 +35,6 @@ modules = [ 'modules/SwitcherTheme.js', 'modules/Timer.js', 'modules/TimerLocation.js', - 'modules/TimerNightlight.js', 'modules/TimerSchedule.js', ] preferences = [ diff --git a/src/modules/Timer.js b/src/modules/Timer.js index b5fc059..01ca6cf 100644 --- a/src/modules/Timer.js +++ b/src/modules/Timer.js @@ -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; } diff --git a/src/modules/TimerNightlight.js b/src/modules/TimerNightlight.js deleted file mode 100644 index 5a2b9b1..0000000 --- a/src/modules/TimerNightlight.js +++ /dev/null @@ -1,113 +0,0 @@ -// SPDX-FileCopyrightText: 2020-2022 Romain Vigier -// 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 = ` - - - - - -`; - - -/** - * 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); diff --git a/src/po/POTFILES b/src/po/POTFILES index bc0cbd2..19d321e 100644 --- a/src/po/POTFILES +++ b/src/po/POTFILES @@ -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 diff --git a/src/po/nightthemeswitcher@romainvigier.fr.pot b/src/po/nightthemeswitcher@romainvigier.fr.pot index d7ec2f6..2873d44 100644 --- a/src/po/nightthemeswitcher@romainvigier.fr.pot +++ b/src/po/nightthemeswitcher@romainvigier.fr.pot @@ -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 \n" "Language-Team: LANGUAGE \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 "" diff --git a/src/preferences/SchedulePage.js b/src/preferences/SchedulePage.js index 4471dff..80551cb 100644 --- a/src/preferences/SchedulePage.js +++ b/src/preferences/SchedulePage.js @@ -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);