diff --git a/src/data/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml b/src/data/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml index 76070f7..e0414a6 100644 --- a/src/data/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml +++ b/src/data/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml @@ -16,11 +16,6 @@ SPDX-License-Identifier: GPL-3.0-or-later - - - - - 0 @@ -76,14 +71,6 @@ SPDX-License-Identifier: GPL-3.0-or-later 0 - - - "default" - - - "prefer-dark" - - "unset" diff --git a/src/data/ui/AppearanceChooser.ui b/src/data/ui/AppearanceChooser.ui index e481811..b18b1f9 100644 --- a/src/data/ui/AppearanceChooser.ui +++ b/src/data/ui/AppearanceChooser.ui @@ -26,39 +26,6 @@ SPDX-License-Identifier: GPL-3.0-or-later - - - Style - - - - center - - - - prefer-light - Light - - - - - default - Default - - - - - prefer-dark - Dark - - - - - - Accent color diff --git a/src/data/ui/AppearancePage.ui b/src/data/ui/AppearancePage.ui index ac5156f..070df0f 100644 --- a/src/data/ui/AppearancePage.ui +++ b/src/data/ui/AppearancePage.ui @@ -27,7 +27,9 @@ SPDX-License-Identifier: GPL-3.0-or-later day Day - + + default + @@ -36,7 +38,9 @@ SPDX-License-Identifier: GPL-3.0-or-later night Night - + + prefer-dark + diff --git a/src/modules/ColorSchemeSwitcher.js b/src/modules/ColorSchemeSwitcher.js index 014fb1d..0695dd9 100644 --- a/src/modules/ColorSchemeSwitcher.js +++ b/src/modules/ColorSchemeSwitcher.js @@ -14,7 +14,6 @@ import { Switcher } from "./Switcher.js"; * The Color Scheme Switcher changes the system color scheme according to the time. */ export class ColorSchemeSwitcher extends Switcher { - #settings; #interfaceSettings; #timer; @@ -25,15 +24,12 @@ export class ColorSchemeSwitcher extends Switcher { * @param {import("./Timer.js").Timer} params.timer Timer to listen to. */ constructor({ timer }) { - const settings = NTS.getSettings(`${NTS.metadata["settings-schema"]}.color-scheme`); super({ name: "Color Scheme", timer, - settings, callback: (time) => this.#onTimeChanged(time), }); this.#timer = timer; - this.#settings = settings; this.#interfaceSettings = new Gio.Settings({ schema: "org.gnome.desktop.interface" }); } @@ -49,14 +45,6 @@ export class ColorSchemeSwitcher extends Switcher { #connectSettings() { debug.message("Connecting Color Scheme Switcher to settings..."); - this.#settingsConnections.push({ - settings: this.#settings, - id: this.#settings.connect("changed::day", this.#onColorSchemeChanged.bind(this)), - }); - this.#settingsConnections.push({ - settings: this.#settings, - id: this.#settings.connect("changed::night", this.#onColorSchemeChanged.bind(this)), - }); this.#settingsConnections.push({ settings: this.#interfaceSettings, id: this.#interfaceSettings.connect("changed::color-scheme", this.#onSystemColorSchemeChanged.bind(this)), @@ -70,16 +58,10 @@ export class ColorSchemeSwitcher extends Switcher { } #onTimeChanged(time) { - const colorScheme = time === Time.NIGHT ? this.#settings.get_string("night") : this.#settings.get_string("day"); + const colorScheme = time === Time.NIGHT ? ColorScheme.PREFER_DARK : ColorScheme.DEFAULT; this.#interfaceSettings.set_string("color-scheme", colorScheme); } - #onColorSchemeChanged(_settings, time) { - const colorScheme = this.#settings.get_string(time); - debug.message(`${time} color scheme changed to ${colorScheme}.`); - if (time === this.#timer.time) this.#interfaceSettings.set_string("color-scheme", colorScheme); - } - #onSystemColorSchemeChanged() { const systemColorScheme = this.#interfaceSettings.get_string("color-scheme"); const time = systemColorScheme === ColorScheme.PREFER_DARK ? Time.NIGHT : Time.DAY; diff --git a/src/modules/Switcher.js b/src/modules/Switcher.js index 97f6ba0..b9c9bee 100644 --- a/src/modules/Switcher.js +++ b/src/modules/Switcher.js @@ -27,11 +27,11 @@ export class Switcher { * @param {object} params Params object. * @param {string} params.name Name of the switcher. * @param {import("./Timer.js").Timer} params.timer Timer to listen to. - * @param {import("gi://Gio").default.Settings} params.settings Settings. + * @param {?import("gi://Gio").default.Settings} params.settings Settings. * @param {TimeChangedCallback} params.callback Callback function. * @param {boolean} params.disableable If the switcher can be disabled using an `enabled` key in the settings. */ - constructor({ name, timer, settings, callback, disableable = false }) { + constructor({ name, timer, settings = null, callback, disableable = false }) { this.#name = name; this.#timer = timer; this.#settings = settings; @@ -41,6 +41,8 @@ export class Switcher { enable() { debug.message(`Enabling ${this.#name} switcher...`); + if (this.#disableable && !this.#settings) + throw new Error(`${this.#name} Switcher can't be disabled without settings.`); if (this.#disableable) this.#watchStatus(); if (!this.#disableable || this.#settings.get_boolean("enabled")) { this.#connectTimer(); diff --git a/src/preferences/AppearancePage.js b/src/preferences/AppearancePage.js index f682fb9..3ef3cd5 100644 --- a/src/preferences/AppearancePage.js +++ b/src/preferences/AppearancePage.js @@ -17,7 +17,7 @@ export class AppearancePage extends Adw.PreferencesPage { ); } - constructor({ accentColorSettings, colorSchemeSettings, ...params } = {}) { + constructor({ accentColorSettings, ...params } = {}) { super(params); const backgroundSettings = new Gio.Settings({ schema: "org.gnome.desktop.background" }); const interfaceSettings = new Gio.Settings({ schema: "org.gnome.desktop.interface" }); @@ -30,9 +30,6 @@ export class AppearancePage extends Adw.PreferencesPage { accentColorSettings.bind("day", this._day_appearance_chooser, "accent-color", Gio.SettingsBindFlags.DEFAULT); accentColorSettings.bind("night", this._night_appearance_chooser, "accent-color", Gio.SettingsBindFlags.DEFAULT); - colorSchemeSettings.bind("day", this._day_appearance_chooser, "color-scheme", Gio.SettingsBindFlags.DEFAULT); - colorSchemeSettings.bind("night", this._night_appearance_chooser, "color-scheme", Gio.SettingsBindFlags.DEFAULT); - backgroundSettings.bind( "picture-uri", this._day_appearance_chooser, diff --git a/src/prefs.js b/src/prefs.js index 4406bff..f359aa6 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -67,7 +67,6 @@ export default class NightThemeSwitcherPreferences extends ExtensionPreferences [ new AppearancePage({ accentColorSettings: this.getSettings(`${this.metadata["settings-schema"]}.accent-color`), - colorSchemeSettings: this.getSettings(`${this.metadata["settings-schema"]}.color-scheme`), }), new CommandsPage({ settings: this.getSettings(`${this.metadata["settings-schema"]}.commands`) }), new TweaksPage({