Extension: Migrate location settings
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import Gio from "gi://Gio";
|
||||
import GLib from "gi://GLib";
|
||||
|
||||
/**
|
||||
* Migrate the extension from a previous version.
|
||||
@@ -10,6 +11,7 @@ import Gio from "gi://Gio";
|
||||
export function migrate(extension) {
|
||||
initializeAccentColorSettings(extension);
|
||||
migrateCommandsSettings(extension);
|
||||
migrateLocationSettings(extension);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,3 +49,28 @@ function migrateCommandsSettings(extension) {
|
||||
commandsSettings.set_string("sunset", "");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the location from the time settings to its own settings.
|
||||
* @param {ExtensionBase} extension The extension base class.
|
||||
*/
|
||||
function migrateLocationSettings(extension) {
|
||||
const timeSettings = extension.getSettings(`${extension.metadata["settings-schema"]}.time`);
|
||||
const locationSettings = extension.getSettings(`${extension.metadata["settings-schema"]}.location`);
|
||||
|
||||
const [oldLatitude, oldLongitude] = timeSettings.get_value("location").deepUnpack();
|
||||
|
||||
let reset = false;
|
||||
|
||||
if (oldLatitude !== 91) {
|
||||
locationSettings.set_double("latitude", oldLatitude);
|
||||
reset = true;
|
||||
}
|
||||
|
||||
if (oldLongitude !== 181) {
|
||||
locationSettings.set_double("longitude", oldLongitude);
|
||||
reset = true;
|
||||
}
|
||||
|
||||
if (reset) timeSettings.set_value("location", new GLib.Variant("(dd)", [91, 181]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user