mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-29 07:52:50 -05:00
desktop widgets: centralize config in desktop widgets tab, variants
always available
This commit is contained in:
@@ -14,7 +14,7 @@ import "settings/SettingsStore.js" as Store
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
readonly property int settingsConfigVersion: 3
|
||||
readonly property int settingsConfigVersion: 4
|
||||
|
||||
readonly property bool isGreeterMode: Quickshell.env("DMS_RUN_GREETER") === "1" || Quickshell.env("DMS_RUN_GREETER") === "true"
|
||||
|
||||
@@ -450,6 +450,7 @@ Singleton {
|
||||
property var systemMonitorVariants: []
|
||||
property var desktopWidgetPositions: ({})
|
||||
property var desktopWidgetGridSettings: ({})
|
||||
property var desktopWidgetInstances: []
|
||||
|
||||
function getDesktopWidgetGridSetting(screenKey, property, defaultValue) {
|
||||
const val = desktopWidgetGridSettings?.[screenKey]?.[property];
|
||||
@@ -546,6 +547,73 @@ Singleton {
|
||||
};
|
||||
}
|
||||
|
||||
function createDesktopWidgetInstance(widgetType, name, config) {
|
||||
const id = "dw_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
||||
const instance = {
|
||||
id: id,
|
||||
widgetType: widgetType,
|
||||
name: name || widgetType,
|
||||
enabled: true,
|
||||
config: config || {},
|
||||
positions: {}
|
||||
};
|
||||
const instances = JSON.parse(JSON.stringify(desktopWidgetInstances || []));
|
||||
instances.push(instance);
|
||||
desktopWidgetInstances = instances;
|
||||
saveSettings();
|
||||
return instance;
|
||||
}
|
||||
|
||||
function updateDesktopWidgetInstance(instanceId, updates) {
|
||||
const instances = JSON.parse(JSON.stringify(desktopWidgetInstances || []));
|
||||
const idx = instances.findIndex(inst => inst.id === instanceId);
|
||||
if (idx === -1) return;
|
||||
Object.assign(instances[idx], updates);
|
||||
desktopWidgetInstances = instances;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function updateDesktopWidgetInstanceConfig(instanceId, configUpdates) {
|
||||
const instances = JSON.parse(JSON.stringify(desktopWidgetInstances || []));
|
||||
const idx = instances.findIndex(inst => inst.id === instanceId);
|
||||
if (idx === -1) return;
|
||||
instances[idx].config = Object.assign({}, instances[idx].config || {}, configUpdates);
|
||||
desktopWidgetInstances = instances;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function updateDesktopWidgetInstancePosition(instanceId, screenKey, positionUpdates) {
|
||||
const instances = JSON.parse(JSON.stringify(desktopWidgetInstances || []));
|
||||
const idx = instances.findIndex(inst => inst.id === instanceId);
|
||||
if (idx === -1) return;
|
||||
if (!instances[idx].positions) instances[idx].positions = {};
|
||||
instances[idx].positions[screenKey] = Object.assign(
|
||||
{},
|
||||
instances[idx].positions[screenKey] || {},
|
||||
positionUpdates
|
||||
);
|
||||
desktopWidgetInstances = instances;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function removeDesktopWidgetInstance(instanceId) {
|
||||
const instances = (desktopWidgetInstances || []).filter(inst => inst.id !== instanceId);
|
||||
desktopWidgetInstances = instances;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function getDesktopWidgetInstance(instanceId) {
|
||||
return (desktopWidgetInstances || []).find(inst => inst.id === instanceId) || null;
|
||||
}
|
||||
|
||||
function getDesktopWidgetInstancesOfType(widgetType) {
|
||||
return (desktopWidgetInstances || []).filter(inst => inst.widgetType === widgetType);
|
||||
}
|
||||
|
||||
function getEnabledDesktopWidgetInstances() {
|
||||
return (desktopWidgetInstances || []).filter(inst => inst.enabled);
|
||||
}
|
||||
|
||||
signal forceDankBarLayoutRefresh
|
||||
signal forceDockLayoutRefresh
|
||||
signal widgetDataChanged
|
||||
|
||||
@@ -337,6 +337,7 @@ var SPEC = {
|
||||
systemMonitorTopProcessCount: { def: 3 },
|
||||
systemMonitorTopProcessSortBy: { def: "cpu" },
|
||||
systemMonitorGraphInterval: { def: 60 },
|
||||
systemMonitorLayoutMode: { def: "auto" },
|
||||
systemMonitorX: { def: -1 },
|
||||
systemMonitorY: { def: -1 },
|
||||
systemMonitorWidth: { def: 320 },
|
||||
@@ -344,7 +345,9 @@ var SPEC = {
|
||||
systemMonitorDisplayPreferences: { def: ["all"] },
|
||||
systemMonitorVariants: { def: [] },
|
||||
desktopWidgetPositions: { def: {} },
|
||||
desktopWidgetGridSettings: { def: {} }
|
||||
desktopWidgetGridSettings: { def: {} },
|
||||
|
||||
desktopWidgetInstances: { def: [] }
|
||||
};
|
||||
|
||||
function getValidKeys() {
|
||||
|
||||
@@ -119,6 +119,101 @@ function migrateToVersion(obj, targetVersion) {
|
||||
settings.configVersion = 3;
|
||||
}
|
||||
|
||||
if (currentVersion < 4) {
|
||||
console.info("Migrating settings from version", currentVersion, "to version 4");
|
||||
console.info("Migrating desktop widgets to unified desktopWidgetInstances");
|
||||
|
||||
var instances = [];
|
||||
|
||||
if (settings.desktopClockEnabled) {
|
||||
var clockPositions = {};
|
||||
if (settings.desktopClockX !== undefined && settings.desktopClockX >= 0) {
|
||||
clockPositions["default"] = {
|
||||
x: settings.desktopClockX,
|
||||
y: settings.desktopClockY,
|
||||
width: settings.desktopClockWidth || 280,
|
||||
height: settings.desktopClockHeight || 180
|
||||
};
|
||||
}
|
||||
|
||||
instances.push({
|
||||
id: "dw_clock_primary",
|
||||
widgetType: "desktopClock",
|
||||
name: "Desktop Clock",
|
||||
enabled: true,
|
||||
config: {
|
||||
style: settings.desktopClockStyle || "analog",
|
||||
transparency: settings.desktopClockTransparency !== undefined ? settings.desktopClockTransparency : 0.8,
|
||||
colorMode: settings.desktopClockColorMode || "primary",
|
||||
customColor: settings.desktopClockCustomColor || "#ffffff",
|
||||
showDate: settings.desktopClockShowDate !== false,
|
||||
showAnalogNumbers: settings.desktopClockShowAnalogNumbers || false,
|
||||
showAnalogSeconds: settings.desktopClockShowAnalogSeconds !== false,
|
||||
displayPreferences: settings.desktopClockDisplayPreferences || ["all"]
|
||||
},
|
||||
positions: clockPositions
|
||||
});
|
||||
}
|
||||
|
||||
if (settings.systemMonitorEnabled) {
|
||||
var sysmonPositions = {};
|
||||
if (settings.systemMonitorX !== undefined && settings.systemMonitorX >= 0) {
|
||||
sysmonPositions["default"] = {
|
||||
x: settings.systemMonitorX,
|
||||
y: settings.systemMonitorY,
|
||||
width: settings.systemMonitorWidth || 320,
|
||||
height: settings.systemMonitorHeight || 480
|
||||
};
|
||||
}
|
||||
|
||||
instances.push({
|
||||
id: "dw_sysmon_primary",
|
||||
widgetType: "systemMonitor",
|
||||
name: "System Monitor",
|
||||
enabled: true,
|
||||
config: {
|
||||
showHeader: settings.systemMonitorShowHeader !== false,
|
||||
transparency: settings.systemMonitorTransparency !== undefined ? settings.systemMonitorTransparency : 0.8,
|
||||
colorMode: settings.systemMonitorColorMode || "primary",
|
||||
customColor: settings.systemMonitorCustomColor || "#ffffff",
|
||||
showCpu: settings.systemMonitorShowCpu !== false,
|
||||
showCpuGraph: settings.systemMonitorShowCpuGraph !== false,
|
||||
showCpuTemp: settings.systemMonitorShowCpuTemp !== false,
|
||||
showGpuTemp: settings.systemMonitorShowGpuTemp || false,
|
||||
gpuPciId: settings.systemMonitorGpuPciId || "",
|
||||
showMemory: settings.systemMonitorShowMemory !== false,
|
||||
showMemoryGraph: settings.systemMonitorShowMemoryGraph !== false,
|
||||
showNetwork: settings.systemMonitorShowNetwork !== false,
|
||||
showNetworkGraph: settings.systemMonitorShowNetworkGraph !== false,
|
||||
showDisk: settings.systemMonitorShowDisk !== false,
|
||||
showTopProcesses: settings.systemMonitorShowTopProcesses || false,
|
||||
topProcessCount: settings.systemMonitorTopProcessCount || 3,
|
||||
topProcessSortBy: settings.systemMonitorTopProcessSortBy || "cpu",
|
||||
layoutMode: settings.systemMonitorLayoutMode || "auto",
|
||||
graphInterval: settings.systemMonitorGraphInterval || 60,
|
||||
displayPreferences: settings.systemMonitorDisplayPreferences || ["all"]
|
||||
},
|
||||
positions: sysmonPositions
|
||||
});
|
||||
}
|
||||
|
||||
var variants = settings.systemMonitorVariants || [];
|
||||
for (var i = 0; i < variants.length; i++) {
|
||||
var v = variants[i];
|
||||
instances.push({
|
||||
id: v.id,
|
||||
widgetType: "systemMonitor",
|
||||
name: v.name || ("System Monitor " + (i + 2)),
|
||||
enabled: true,
|
||||
config: v.config || {},
|
||||
positions: v.positions || {}
|
||||
});
|
||||
}
|
||||
|
||||
settings.desktopWidgetInstances = instances;
|
||||
settings.configVersion = 4;
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user