1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-30 08:22:51 -05:00

settings: refactor for read-only handling

- Remove default-* copying logic
- Allow in-memory changes of settings/session datas
- Convert SessionData to newer spec pattern
- Migrate weather coords to Session data
- Bricks home manager (temporarily)
This commit is contained in:
bbedward
2026-01-01 13:13:35 -05:00
parent 571a9dabcd
commit 957c89a85d
10 changed files with 431 additions and 203 deletions

View File

@@ -22,10 +22,6 @@ Singleton {
pluginSettingsCheckProcess.running = true;
}
function checkDefaultSettings() {
defaultSettingsCheckProcess.running = true;
}
property var qtToolsDetectionProcess: Process {
command: ["sh", "-c", "echo -n 'qt5ct:'; command -v qt5ct >/dev/null && echo 'true' || echo 'false'; echo -n 'qt6ct:'; command -v qt6ct >/dev/null && echo 'true' || echo 'false'; echo -n 'gtk:'; (command -v gsettings >/dev/null || command -v dconf >/dev/null) && echo 'true' || echo 'false'"]
running: false
@@ -51,25 +47,6 @@ Singleton {
}
}
property var defaultSettingsCheckProcess: Process {
command: ["sh", "-c", "CONFIG_DIR=\"" + (settingsRoot?._configDir || "") + "/DankMaterialShell\"; if [ -f \"$CONFIG_DIR/default-settings.json\" ] && [ ! -f \"$CONFIG_DIR/settings.json\" ]; then cp --no-preserve=mode \"$CONFIG_DIR/default-settings.json\" \"$CONFIG_DIR/settings.json\" && echo 'copied'; else echo 'not_found'; fi"]
running: false
onExited: function (exitCode) {
if (!settingsRoot)
return;
if (exitCode === 0) {
console.info("Copied default-settings.json to settings.json");
if (settingsRoot.settingsFile) {
settingsRoot.settingsFile.reload();
}
} else {
if (typeof ThemeApplier !== "undefined") {
ThemeApplier.applyStoredTheme(settingsRoot);
}
}
}
}
property var fprintdDetectionProcess: Process {
command: ["sh", "-c", "command -v fprintd-list >/dev/null 2>&1"]
running: false

View File

@@ -0,0 +1,63 @@
.pragma library
var SPEC = {
isLightMode: { def: false },
doNotDisturb: { def: false },
wallpaperPath: { def: "" },
perMonitorWallpaper: { def: false },
monitorWallpapers: { def: {} },
perModeWallpaper: { def: false },
wallpaperPathLight: { def: "" },
wallpaperPathDark: { def: "" },
monitorWallpapersLight: { def: {} },
monitorWallpapersDark: { def: {} },
wallpaperTransition: { def: "fade" },
includedTransitions: { def: ["fade", "wipe", "disc", "stripes", "iris bloom", "pixelate", "portal"] },
wallpaperCyclingEnabled: { def: false },
wallpaperCyclingMode: { def: "interval" },
wallpaperCyclingInterval: { def: 300 },
wallpaperCyclingTime: { def: "06:00" },
monitorCyclingSettings: { def: {} },
nightModeEnabled: { def: false },
nightModeTemperature: { def: 4500 },
nightModeHighTemperature: { def: 6500 },
nightModeAutoEnabled: { def: false },
nightModeAutoMode: { def: "time" },
nightModeStartHour: { def: 18 },
nightModeStartMinute: { def: 0 },
nightModeEndHour: { def: 6 },
nightModeEndMinute: { def: 0 },
latitude: { def: 0.0 },
longitude: { def: 0.0 },
nightModeUseIPLocation: { def: false },
nightModeLocationProvider: { def: "" },
weatherLocation: { def: "New York, NY" },
weatherCoordinates: { def: "40.7128,-74.0060" },
pinnedApps: { def: [] },
hiddenTrayIds: { def: [] },
recentColors: { def: [] },
showThirdPartyPlugins: { def: false },
launchPrefix: { def: "" },
lastBrightnessDevice: { def: "" },
brightnessExponentialDevices: { def: {} },
brightnessUserSetValues: { def: {} },
brightnessExponentValues: { def: {} },
selectedGpuIndex: { def: 0 },
nvidiaGpuTempEnabled: { def: false },
nonNvidiaGpuTempEnabled: { def: false },
enabledGpuPciIds: { def: [] },
wifiDeviceOverride: { def: "" },
weatherHourlyDetailed: { def: true }
};
function getValidKeys() {
return Object.keys(SPEC).concat(["configVersion"]);
}

View File

@@ -0,0 +1,92 @@
.pragma library
.import "./SessionSpec.js" as SpecModule
function parse(root, jsonObj) {
var SPEC = SpecModule.SPEC;
for (var k in SPEC) {
root[k] = SPEC[k].def;
}
if (!jsonObj) return;
for (var k in jsonObj) {
if (!SPEC[k]) continue;
var raw = jsonObj[k];
var spec = SPEC[k];
var coerce = spec.coerce;
root[k] = coerce ? (coerce(raw) !== undefined ? coerce(raw) : root[k]) : raw;
}
}
function toJson(root) {
var SPEC = SpecModule.SPEC;
var out = {};
for (var k in SPEC) {
if (SPEC[k].persist === false) continue;
out[k] = root[k];
}
out.configVersion = root.sessionConfigVersion;
return out;
}
function migrateToVersion(obj, targetVersion, settingsData) {
if (!obj) return null;
var session = JSON.parse(JSON.stringify(obj));
var currentVersion = session.configVersion || 0;
if (currentVersion >= targetVersion) {
return null;
}
if (currentVersion < 2) {
console.info("SessionData: Migrating session from version", currentVersion, "to version 2");
console.info("SessionData: Importing weather location and coordinates from settings");
if (settingsData && typeof settingsData !== "undefined") {
if (session.weatherLocation === undefined || session.weatherLocation === "New York, NY") {
var settingsWeatherLocation = settingsData._legacyWeatherLocation;
if (settingsWeatherLocation && settingsWeatherLocation !== "New York, NY") {
session.weatherLocation = settingsWeatherLocation;
console.info("SessionData: Migrated weatherLocation:", settingsWeatherLocation);
}
}
if (session.weatherCoordinates === undefined || session.weatherCoordinates === "40.7128,-74.0060") {
var settingsWeatherCoordinates = settingsData._legacyWeatherCoordinates;
if (settingsWeatherCoordinates && settingsWeatherCoordinates !== "40.7128,-74.0060") {
session.weatherCoordinates = settingsWeatherCoordinates;
console.info("SessionData: Migrated weatherCoordinates:", settingsWeatherCoordinates);
}
}
}
session.configVersion = 2;
}
return session;
}
function cleanup(fileText) {
var getValidKeys = SpecModule.getValidKeys;
if (!fileText || !fileText.trim()) return null;
try {
var session = JSON.parse(fileText);
var validKeys = getValidKeys();
var needsSave = false;
for (var key in session) {
if (validKeys.indexOf(key) < 0) {
delete session[key];
needsSave = true;
}
}
return needsSave ? JSON.stringify(session, null, 2) : null;
} catch (e) {
console.warn("SessionData: Failed to cleanup unused keys:", e.message);
return null;
}
}

View File

@@ -112,8 +112,6 @@ var SPEC = {
spotlightCloseNiriOverview: { def: true },
niriOverviewOverlayEnabled: { def: true },
weatherLocation: { def: "New York, NY" },
weatherCoordinates: { def: "40.7128,-74.0060" },
useAutoLocation: { def: false },
weatherEnabled: { def: true },

View File

@@ -214,6 +214,16 @@ function migrateToVersion(obj, targetVersion) {
settings.configVersion = 4;
}
if (currentVersion < 5) {
console.info("Migrating settings from version", currentVersion, "to version 5");
console.info("Moving sensitive data (weather location, coordinates) to session.json");
delete settings.weatherLocation;
delete settings.weatherCoordinates;
settings.configVersion = 5;
}
return settings;
}