Extension: Group migrations in a single file
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
import { Extension } from "resource:///org/gnome/shell/extensions/extension.js";
|
||||
|
||||
import { migrate } from "./migrations.js";
|
||||
import * as debug from "./debug.js";
|
||||
|
||||
import { AccentColorSwitcher } from "./modules/AccentColorSwitcher.js";
|
||||
@@ -18,6 +19,8 @@ export default class NightThemeSwitcher extends Extension {
|
||||
enable() {
|
||||
globalThis.NTS = this;
|
||||
|
||||
migrate(this);
|
||||
|
||||
debug.message("Enabling extension...");
|
||||
|
||||
const timer = new Timer();
|
||||
|
||||
@@ -16,6 +16,7 @@ configure_file(
|
||||
main = [
|
||||
'debug.js',
|
||||
'extension.js',
|
||||
'migrations.js',
|
||||
'prefs.js',
|
||||
]
|
||||
enums = [
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// SPDX-FileCopyrightText: Night Theme Switcher Contributors
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import Gio from "gi://Gio";
|
||||
|
||||
/**
|
||||
* Migrate the extension from a previous version.
|
||||
* @param {ExtensionBase} extension The extension base class.
|
||||
*/
|
||||
export function migrate(extension) {
|
||||
initializeAccentColorSettings(extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the accent color settings to the current system accent color.
|
||||
* @param {ExtensionBase} extension The extension base class.
|
||||
*/
|
||||
function initializeAccentColorSettings(extension) {
|
||||
const accentColorSettings = extension.getSettings(`${extension.metadata["settings-schema"]}.accent-color`);
|
||||
const interfaceSettings = new Gio.Settings({ schema: "org.gnome.desktop.interface" });
|
||||
|
||||
if (accentColorSettings.get_string("day") === "unset")
|
||||
accentColorSettings.set_string("day", interfaceSettings.get_string("accent-color"));
|
||||
|
||||
if (accentColorSettings.get_string("night") === "unset")
|
||||
accentColorSettings.set_string("night", interfaceSettings.get_string("accent-color"));
|
||||
}
|
||||
@@ -34,7 +34,6 @@ export class AccentColorSwitcher extends Switcher {
|
||||
this.#timer = timer;
|
||||
this.#settings = settings;
|
||||
this.#interfaceSettings = new Gio.Settings({ schema: "org.gnome.desktop.interface" });
|
||||
this.#initSettings();
|
||||
}
|
||||
|
||||
enable() {
|
||||
@@ -47,13 +46,6 @@ export class AccentColorSwitcher extends Switcher {
|
||||
this.#disconnectSettings();
|
||||
}
|
||||
|
||||
#initSettings() {
|
||||
if (this.#settings.get_string(Time.DAY) === "unset")
|
||||
this.#settings.set_string(Time.DAY, this.#interfaceSettings.get_string("accent-color"));
|
||||
if (this.#settings.get_string(Time.NIGHT) === "unset")
|
||||
this.#settings.set_string(Time.NIGHT, this.#interfaceSettings.get_string("accent-color"));
|
||||
}
|
||||
|
||||
#connectSettings() {
|
||||
debug.message("Connecting Accent Color Switcher to settings...");
|
||||
this.#settingsConnections.push({
|
||||
|
||||
@@ -20,12 +20,6 @@ export class AppearancePage extends Adw.PreferencesPage {
|
||||
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" });
|
||||
|
||||
if (accentColorSettings.get_string("day") === "unset")
|
||||
accentColorSettings.set_string("day", interfaceSettings.get_string("accent-color"));
|
||||
if (accentColorSettings.get_string("night") === "unset")
|
||||
accentColorSettings.set_string("night", interfaceSettings.get_string("accent-color"));
|
||||
|
||||
accentColorSettings.bind("day", this._day_appearance_chooser, "accent-color", Gio.SettingsBindFlags.DEFAULT);
|
||||
accentColorSettings.bind("night", this._night_appearance_chooser, "accent-color", Gio.SettingsBindFlags.DEFAULT);
|
||||
|
||||
@@ -11,12 +11,17 @@ import Gtk from "gi://Gtk";
|
||||
|
||||
import { ExtensionPreferences } from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js";
|
||||
|
||||
import { migrate } from "./migrations.js";
|
||||
|
||||
export default class NightThemeSwitcherPreferences extends ExtensionPreferences {
|
||||
/**
|
||||
* Fill the PreferencesWindow.
|
||||
* @param {import("gi://Adw").default.PreferencesWindow} window The PreferencesWindow to fill.
|
||||
*/
|
||||
async fillPreferencesWindow(window) {
|
||||
// Migrate from a previous version
|
||||
migrate(this);
|
||||
|
||||
// Load resources
|
||||
const resource = Gio.Resource.load(GLib.build_filenamev([this.path, "resources", "preferences.gresource"]));
|
||||
Gio.resources_register(resource);
|
||||
|
||||
Reference in New Issue
Block a user