1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-27 15:02:50 -05:00

desktop widgets: centralize config in desktop widgets tab, variants

always available
This commit is contained in:
bbedward
2025-12-22 10:39:19 -05:00
parent c548255bfc
commit a7494971fd
21 changed files with 2151 additions and 854 deletions

View File

@@ -9,110 +9,101 @@ Variants {
id: root
model: Quickshell.screens
Component.onCompleted: Qt.callLater(autoEnablePluginsForInstances)
function autoEnablePluginsForInstances() {
const instances = SettingsData.desktopWidgetInstances || [];
const pluginTypes = new Set();
for (const inst of instances) {
if (!inst.enabled)
continue;
if (inst.widgetType === "desktopClock" || inst.widgetType === "systemMonitor")
continue;
pluginTypes.add(inst.widgetType);
}
for (const pluginId of pluginTypes) {
if (PluginService.isPluginLoaded(pluginId))
continue;
if (!PluginService.availablePlugins[pluginId])
continue;
PluginService.enablePlugin(pluginId);
}
}
Connections {
target: PluginService
function onPluginListUpdated() {
Qt.callLater(root.autoEnablePluginsForInstances);
}
}
QtObject {
id: screenDelegate
required property var modelData
readonly property var screen: modelData
readonly property string screenKey: SettingsData.getScreenDisplayName(screen)
function shouldShowOnScreen(prefs) {
if (!Array.isArray(prefs) || prefs.length === 0 || prefs.includes("all"))
return true;
return prefs.some(p => p.name === modelData.name);
}
readonly property bool showBuiltinClock: SettingsData.desktopClockEnabled && shouldShowOnScreen(SettingsData.desktopClockDisplayPreferences)
readonly property bool showSystemMonitor: SettingsData.systemMonitorEnabled && shouldShowOnScreen(SettingsData.systemMonitorDisplayPreferences)
readonly property var visibleSystemMonitorVariants: {
if (!SettingsData.systemMonitorEnabled)
return [];
const variants = SettingsData.systemMonitorVariants || [];
return variants.filter(v => shouldShowOnScreen(v.config?.displayPreferences));
}
property var _pluginComponents: PluginService.pluginDesktopComponents
property var _pluginTrigger: 0
readonly property var visiblePlugins: {
void _pluginTrigger;
return Object.keys(_pluginComponents).filter(id => {
const prefs = PluginService.loadPluginData(id, "displayPreferences", ["all"]);
return shouldShowOnScreen(prefs);
return prefs.some(p => {
if (typeof p === "string")
return p === screenKey || p === modelData.name;
return p?.name === modelData.name || p === screenKey;
});
}
property var pluginServiceConnections: Connections {
target: PluginService
function onPluginDataChanged(pluginId) {
screenDelegate._pluginTrigger++;
}
function onPluginLoaded(pluginId) {
const plugin = PluginService.availablePlugins[pluginId];
if (plugin?.type === "desktop")
screenDelegate._pluginTrigger++;
}
function onPluginUnloaded(pluginId) {
screenDelegate._pluginTrigger++;
}
}
property Loader clockLoader: Loader {
active: screenDelegate.showBuiltinClock
sourceComponent: Component {
DesktopPluginWrapper {
pluginId: "desktopClock"
pluginComponent: clockComponent
screen: screenDelegate.screen
}
}
}
property Component clockComponent: Component {
DesktopClockWidget {}
}
property Loader systemMonitorLoader: Loader {
active: screenDelegate.showSystemMonitor
sourceComponent: Component {
DesktopPluginWrapper {
pluginId: "systemMonitor"
pluginComponent: systemMonitorComponent
screen: screenDelegate.screen
}
}
}
property Component systemMonitorComponent: Component {
SystemMonitorWidget {}
}
property Instantiator sysMonVariantInstantiator: Instantiator {
model: screenDelegate.visibleSystemMonitorVariants
property Instantiator widgetInstantiator: Instantiator {
model: ScriptModel {
objectProp: "id"
values: SettingsData.desktopWidgetInstances
}
DesktopPluginWrapper {
required property var modelData
required property int index
pluginId: "systemMonitor"
variantId: modelData.id
variantData: modelData
pluginComponent: screenDelegate.systemMonitorComponent
screen: screenDelegate.screen
}
}
property Instantiator pluginInstantiator: Instantiator {
model: screenDelegate.visiblePlugins
DesktopPluginWrapper {
required property string modelData
pluginId: modelData
pluginComponent: PluginService.pluginDesktopComponents[modelData]
pluginService: PluginService
readonly property string instanceIdRef: modelData.id
readonly property var liveInstanceData: {
const instances = SettingsData.desktopWidgetInstances || [];
return instances.find(inst => inst.id === instanceIdRef) ?? modelData;
}
readonly property bool shouldBeVisible: {
if (!liveInstanceData.enabled)
return false;
const prefs = liveInstanceData.config?.displayPreferences ?? ["all"];
return screenDelegate.shouldShowOnScreen(prefs);
}
pluginId: liveInstanceData.widgetType
instanceId: instanceIdRef
instanceData: liveInstanceData
builtinComponent: {
switch (liveInstanceData.widgetType) {
case "desktopClock":
return screenDelegate.clockComponent;
case "systemMonitor":
return screenDelegate.systemMonitorComponent;
default:
return null;
}
}
pluginService: (liveInstanceData.widgetType !== "desktopClock" && liveInstanceData.widgetType !== "systemMonitor") ? PluginService : null
screen: screenDelegate.screen
visible: shouldBeVisible
}
}
}