1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-08 06:25:37 -05:00

feat: Plugin System (#276)

* feat: Plugin System

* fix: merge conflicts
This commit is contained in:
Bruno Cesar Rocha
2025-10-01 16:28:10 +01:00
committed by GitHub
parent ab0759f441
commit 53983933dc
13 changed files with 1662 additions and 49 deletions

View File

@@ -266,7 +266,8 @@ Item {
}
function getWidgetComponent(widgetId) {
const componentMap = {
// Build dynamic component map including plugins
let baseMap = {
"launcherButton": "launcherButtonComponent",
"workspaceSwitcher": "workspaceSwitcherComponent",
"focusedWindow": "focusedWindowComponent",
@@ -296,8 +297,15 @@ Item {
"systemUpdate": "systemUpdateComponent"
}
const componentKey = componentMap[widgetId]
return componentKey ? root.components[componentKey] : null
// For built-in components, get from components property
const componentKey = baseMap[widgetId]
if (componentKey && root.components[componentKey]) {
return root.components[componentKey]
}
// For plugin components, get from PluginService
let pluginMap = PluginService.getWidgetComponents()
return pluginMap[widgetId] || null
}
height: parent.height
@@ -337,6 +345,7 @@ Item {
id: centerRepeater
model: root.widgetsModel
Loader {
property string widgetId: model.widgetId
property var widgetData: model
@@ -364,6 +373,17 @@ Item {
if (root.axis && "isVertical" in item) {
item.isVertical = root.axis.isVertical
}
// Inject PluginService for plugin widgets
if (item.pluginService !== undefined) {
console.log("CenterSection: Injecting PluginService into plugin widget:", model.widgetId)
item.pluginService = PluginService
if (item.loadTimezones) {
console.log("CenterSection: Calling loadTimezones for widget:", model.widgetId)
item.loadTimezones()
}
}
layoutTimer.restart()
}
@@ -379,4 +399,27 @@ Item {
layoutTimer.restart()
}
}
// Listen for plugin changes and refresh components
Connections {
target: PluginService
function onPluginLoaded(pluginId) {
// Force refresh of component lookups
for (var i = 0; i < centerRepeater.count; i++) {
var item = centerRepeater.itemAt(i)
if (item && item.widgetId === pluginId) {
item.sourceComponent = root.getWidgetComponent(pluginId)
}
}
}
function onPluginUnloaded(pluginId) {
// Force refresh of component lookups
for (var i = 0; i < centerRepeater.count; i++) {
var item = centerRepeater.itemAt(i)
if (item && item.widgetId === pluginId) {
item.sourceComponent = root.getWidgetComponent(pluginId)
}
}
}
}
}

View File

@@ -95,6 +95,24 @@ Item {
Qt.callLater(() => Qt.callLater(forceWidgetRefresh))
}
Connections {
target: PluginService
function onPluginLoaded(pluginId) {
console.log("DankBar: Plugin loaded:", pluginId)
// Force componentMap to update by triggering property change
if (topBarContent) {
topBarContent.updateComponentMap()
}
}
function onPluginUnloaded(pluginId) {
console.log("DankBar: Plugin unloaded:", pluginId)
// Force componentMap to update by triggering property change
if (topBarContent) {
topBarContent.updateComponentMap()
}
}
}
function forceWidgetRefresh() {
}
@@ -366,7 +384,13 @@ Item {
anchors.bottomMargin: !barWindow.isVertical ? SettingsData.dankBarInnerPadding / 2 : Math.max(Theme.spacingXS, SettingsData.dankBarInnerPadding * 0.8)
clip: true
readonly property int availableWidth: width
property int componentMapRevision: 0
function updateComponentMap() {
componentMapRevision++
}
readonly property int availableWidth: width
readonly property int launcherButtonWidth: 40
readonly property int workspaceSwitcherWidth: 120
readonly property int focusedAppMaxWidth: 456
@@ -421,35 +445,44 @@ Item {
return widgetVisibility[widgetId] ?? true
}
readonly property var componentMap: ({
"launcherButton": launcherButtonComponent,
"workspaceSwitcher": workspaceSwitcherComponent,
"focusedWindow": focusedWindowComponent,
"runningApps": runningAppsComponent,
"clock": clockComponent,
"music": mediaComponent,
"weather": weatherComponent,
"systemTray": systemTrayComponent,
"privacyIndicator": privacyIndicatorComponent,
"clipboard": clipboardComponent,
"cpuUsage": cpuUsageComponent,
"memUsage": memUsageComponent,
"diskUsage": diskUsageComponent,
"cpuTemp": cpuTempComponent,
"gpuTemp": gpuTempComponent,
"notificationButton": notificationButtonComponent,
"battery": batteryComponent,
"controlCenterButton": controlCenterButtonComponent,
"idleInhibitor": idleInhibitorComponent,
"spacer": spacerComponent,
"separator": separatorComponent,
"network_speed_monitor": networkComponent,
"keyboard_layout_name": keyboardLayoutNameComponent,
"vpn": vpnComponent,
"notepadButton": notepadButtonComponent,
"colorPicker": colorPickerComponent,
"systemUpdate": systemUpdateComponent
})
readonly property var componentMap: {
// This property depends on componentMapRevision to ensure it updates when plugins change
componentMapRevision;
let baseMap = {
"launcherButton": launcherButtonComponent,
"workspaceSwitcher": workspaceSwitcherComponent,
"focusedWindow": focusedWindowComponent,
"runningApps": runningAppsComponent,
"clock": clockComponent,
"music": mediaComponent,
"weather": weatherComponent,
"systemTray": systemTrayComponent,
"privacyIndicator": privacyIndicatorComponent,
"clipboard": clipboardComponent,
"cpuUsage": cpuUsageComponent,
"memUsage": memUsageComponent,
"diskUsage": diskUsageComponent,
"cpuTemp": cpuTempComponent,
"gpuTemp": gpuTempComponent,
"notificationButton": notificationButtonComponent,
"battery": batteryComponent,
"controlCenterButton": controlCenterButtonComponent,
"idleInhibitor": idleInhibitorComponent,
"spacer": spacerComponent,
"separator": separatorComponent,
"network_speed_monitor": networkComponent,
"keyboard_layout_name": keyboardLayoutNameComponent,
"vpn": vpnComponent,
"notepadButton": notepadButtonComponent,
"colorPicker": colorPickerComponent,
"systemUpdate": systemUpdateComponent
}
// Merge with plugin widgets
let pluginMap = PluginService.getWidgetComponents()
return Object.assign(baseMap, pluginMap)
}
function getWidgetComponent(widgetId) {
return componentMap[widgetId] || null
@@ -1016,6 +1049,7 @@ Item {
}
}
}
}
}
}

View File

@@ -33,10 +33,21 @@ Loader {
if (axis && "isVertical" in item) {
item.isVertical = axis.isVertical
}
// Inject PluginService for plugin widgets
if (item.pluginService !== undefined) {
console.log("WidgetHost: Injecting PluginService into plugin widget:", widgetId)
item.pluginService = PluginService
if (item.loadTimezones) {
console.log("WidgetHost: Calling loadTimezones for widget:", widgetId)
item.loadTimezones()
}
}
}
}
function getWidgetComponent(widgetId, components) {
// Build component map for built-in widgets
const componentMap = {
"launcherButton": components.launcherButtonComponent,
"workspaceSwitcher": components.workspaceSwitcherComponent,
@@ -67,7 +78,14 @@ Loader {
"systemUpdate": components.systemUpdateComponent
}
return componentMap[widgetId] || null
// Check for built-in component first
if (componentMap[widgetId]) {
return componentMap[widgetId]
}
// Check for plugin component
let pluginMap = PluginService.getWidgetComponents()
return pluginMap[widgetId] || null
}
function getWidgetVisible(widgetId, dgopAvailable) {