diff --git a/src/extension.js b/src/extension.js index d475dbd..b73c45f 100644 --- a/src/extension.js +++ b/src/extension.js @@ -1,20 +1,21 @@ -// SPDX-FileCopyrightText: 2020, 2021 Romain Vigier +// SPDX-FileCopyrightText: 2020-2022 Romain Vigier // SPDX-License-Identifier: GPL-3.0-or-later 'use strict'; -const { GLib } = imports.gi; +const { Gio, GLib } = imports.gi; const { extensionUtils } = imports.misc; const { extensionManager } = imports.ui.main; const Me = extensionUtils.getCurrentExtension(); +const utils = Me.imports.utils; + const { Timer } = Me.imports.modules.Timer; const { GtkThemer } = Me.imports.modules.GtkThemer; const { ShellThemer } = Me.imports.modules.ShellThemer; const { IconThemer } = Me.imports.modules.IconThemer; const { CursorThemer } = Me.imports.modules.CursorThemer; -const { Backgrounder } = Me.imports.modules.Backgrounder; const { Commander } = Me.imports.modules.Commander; @@ -24,7 +25,6 @@ var gtkThemer = null; var shellThemer = null; var iconThemer = null; var cursorThemer = null; -var backgrounder = null; var commander = null; @@ -34,6 +34,7 @@ var commander = null; function init() { console.debug('Initializing extension...'); extensionUtils.initTranslations(); + _migrateBackgroundSettings(); console.debug('Extension initialized.'); } @@ -55,7 +56,6 @@ function start() { shellThemer = new ShellThemer(); iconThemer = new IconThemer(); cursorThemer = new CursorThemer(); - backgrounder = new Backgrounder(); commander = new Commander(); timer.enable(); @@ -63,7 +63,6 @@ function start() { shellThemer.enable(); iconThemer.enable(); cursorThemer.enable(); - backgrounder.enable(); commander.enable(); enabled = true; @@ -81,7 +80,6 @@ function disable() { shellThemer.disable(); iconThemer.disable(); cursorThemer.disable(); - backgrounder.disable(); commander.disable(); timer.disable(); @@ -90,7 +88,6 @@ function disable() { shellThemer = null; iconThemer = null; cursorThemer = null; - backgrounder = null; commander = null; console.debug('Extension disabled.'); } @@ -110,3 +107,22 @@ function _waitForExtensionManager() { resolve(); }); } + +/** + * Migrate background settings from the extension to the system. + */ +function _migrateBackgroundSettings() { + const systemSettings = new Gio.Settings({ schema: 'org.gnome.desktop.background' }); + const extensionSettings = extensionUtils.getSettings(utils.getSettingsSchema('backgrounds')); + + if (extensionSettings.get_string('day')) { + systemSettings.set_string('picture-uri', extensionSettings.get_string('day')); + systemSettings.set_string('picture-uri-dark', extensionSettings.get_string('day')); + extensionSettings.set_string('day', ''); + } + + if (extensionSettings.get_string('night')) { + systemSettings.set_string('picture-uri-dark', extensionSettings.get_string('night')); + extensionSettings.set_string('night', ''); + } +} diff --git a/src/modules/Backgrounder.js b/src/modules/Backgrounder.js deleted file mode 100644 index 0b75703..0000000 --- a/src/modules/Backgrounder.js +++ /dev/null @@ -1,136 +0,0 @@ -// SPDX-FileCopyrightText: 2020, 2021 Romain Vigier -// SPDX-License-Identifier: GPL-3.0-or-later - -const { Gio } = imports.gi; -const { extensionUtils } = imports.misc; - -const Me = extensionUtils.getCurrentExtension(); - -const e = Me.imports.extension; -const utils = Me.imports.utils; - -const { Time } = Me.imports.enums.Time; - -/** - * The Backgrounder is responsible for changing the desktop background - * according to the time. - * - * When the user changes its desktop background (for example via the system - * settings), it will use it as the current time background. - */ -var Backgrounder = class { - constructor() { - this._backgroundsSettings = extensionUtils.getSettings(utils.getSettingsSchema('backgrounds')); - this._systemBackgroundSettings = new Gio.Settings({ schema: 'org.gnome.desktop.background' }); - this._settingsConnections = []; - this._statusConnection = null; - this._timerConnection = null; - } - - enable() { - console.debug('Enabling Backgrounder...'); - this._watchStatus(); - if (this._backgroundsSettings.get_boolean('enabled')) { - this._connectSettings(); - this._connectTimer(); - this._updateSystemBackground(e.timer.time); - } - console.debug('Backgrounder enabled.'); - } - - disable() { - console.debug('Disabling Backgrounder...'); - this._disconnectTimer(); - this._disconnectSettings(); - this._unwatchStatus(); - console.debug('Backgrounder disabled.'); - } - - - _watchStatus() { - console.debug('Watching backgrounds status...'); - this._statusConnection = this._backgroundsSettings.connect('changed::enabled', this._onStatusChanged.bind(this)); - } - - _unwatchStatus() { - if (this._statusConnection) { - this._backgroundsSettings.disconnect(this._statusConnection); - this._statusConnection = null; - } - console.debug('Stopped watching backgrounds status.'); - } - - _connectSettings() { - console.debug('Connecting Backgrounder to settings...'); - this._settingsConnections.push({ - settings: this._backgroundsSettings, - id: this._backgroundsSettings.connect('changed::day', this._onDayBackgroundChanged.bind(this)), - }); - this._settingsConnections.push({ - settings: this._backgroundsSettings, - id: this._backgroundsSettings.connect('changed::night', this._onNightBackgroundChanged.bind(this)), - }); - this._settingsConnections.push({ - settings: this._systemBackgroundSettings, - id: this._systemBackgroundSettings.connect('changed::picture-uri', this._onSystemBackgroundChanged.bind(this)), - }); - } - - _disconnectSettings() { - this._settingsConnections.forEach(connection => connection.settings.disconnect(connection.id)); - this._settingsConnections = []; - console.debug('Disconnected Backgrounder from settings.'); - } - - _connectTimer() { - console.debug('Connecting Backgrounder to Timer...'); - this._timerConnection = e.timer.connect('time-changed', this._onTimeChanged.bind(this)); - } - - _disconnectTimer() { - if (this._timerConnection) { - e.timer.disconnect(this._timerConnection); - this._timerConnection = null; - } - console.debug('Disconnected Backgrounder from Timer.'); - } - - - _onStatusChanged() { - console.debug(`Backgrounds switching has been ${this._backgroundsSettings.get_boolean('enabled') ? 'enabled' : 'disabled'}.`); - this.disable(); - this.enable(); - } - - _onDayBackgroundChanged() { - console.debug(`Day background changed to '${this._backgroundsSettings.get_string('day')}'.`); - this._updateSystemBackground(); - } - - _onNightBackgroundChanged() { - console.debug(`Night background changed to '${this._backgroundsSettings.get_string('night')}'.`); - this._updateSystemBackground(); - } - - _onSystemBackgroundChanged() { - console.debug(`System background changed to '${this._systemBackgroundSettings.get_string('picture-uri')}'.`); - this._updateCurrentBackground(); - } - - _onTimeChanged() { - this._updateSystemBackground(); - } - - - _updateCurrentBackground() { - if (e.timer.time === Time.UNKNOWN) - return; - this._backgroundsSettings.set_string(e.timer.time, this._systemBackgroundSettings.get_string('picture-uri')); - } - - _updateSystemBackground() { - if (e.timer.time === Time.UNKNOWN || !this._backgroundsSettings.get_string(e.timer.time)) - return; - this._systemBackgroundSettings.set_string('picture-uri', this._backgroundsSettings.get_string(e.timer.time)); - } -}; diff --git a/src/preferences/BackgroundsPreferences.js b/src/preferences/BackgroundsPreferences.js index 8f4a2e2..cb9a4e6 100644 --- a/src/preferences/BackgroundsPreferences.js +++ b/src/preferences/BackgroundsPreferences.js @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2021 Romain Vigier +// SPDX-FileCopyrightText: 2021, 2022 Romain Vigier // SPDX-License-Identifier: GPL-3.0-or-later const { Gio, GLib, GObject, Gtk } = imports.gi; @@ -6,14 +6,11 @@ const { extensionUtils } = imports.misc; const Me = extensionUtils.getCurrentExtension(); -const utils = Me.imports.utils; - var BackgroundsPreferences = GObject.registerClass({ GTypeName: 'BackgroundsPreferences', Template: `file://${GLib.build_filenamev([Me.path, 'preferences', 'ui', 'BackgroundsPreferences.ui'])}`, InternalChildren: [ - 'enabled_switch', 'day_button', 'night_button', ], @@ -29,24 +26,17 @@ var BackgroundsPreferences = GObject.registerClass({ }, class BackgroundsPreferences extends Gtk.Box { _init(props = {}) { super._init(props); - this.settings = extensionUtils.getSettings(utils.getSettingsSchema('backgrounds')); + this.settings = new Gio.Settings({ schema: 'org.gnome.desktop.background' }); this.settings.bind( - 'enabled', - this._enabled_switch, - 'active', - Gio.SettingsBindFlags.DEFAULT - ); - - this.settings.bind( - 'day', + 'picture-uri', this._day_button, 'path', Gio.SettingsBindFlags.DEFAULT ); this.settings.bind( - 'night', + 'picture-uri-dark', this._night_button, 'path', Gio.SettingsBindFlags.DEFAULT diff --git a/src/preferences/ui/BackgroundsPreferences.ui b/src/preferences/ui/BackgroundsPreferences.ui index 46559be..4cf0f3b 100644 --- a/src/preferences/ui/BackgroundsPreferences.ui +++ b/src/preferences/ui/BackgroundsPreferences.ui @@ -1,6 +1,6 @@ @@ -8,48 +8,31 @@ SPDX-License-Identifier: GPL-3.0-or-later vertical 8 - - horizontal - - - Switch backgrounds - center - True - 0 - - - - - - center - - + + Switch backgrounds + 0 + - - + + 36 - - 36 - - - Day background - - - - - - - - Night background - - - - - + + Day background + + + + + + + + Night background + + +