1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-05 21:15:38 -05:00

cups: only subscribe to cups, if widget is present

This commit is contained in:
bbedward
2025-11-05 18:10:54 -05:00
parent 20d797320a
commit e883ebe307
2 changed files with 79 additions and 1 deletions

View File

@@ -41,6 +41,18 @@ QtObject {
onItemChanged: {
root.cupsBuiltinInstance = item
if (item && !DMSService.activeSubscriptions.includes("cups") && !DMSService.activeSubscriptions.includes("all")) {
DMSService.addSubscription("cups")
}
}
onActiveChanged: {
if (!active) {
if (DMSService.activeSubscriptions.includes("cups")) {
DMSService.removeSubscription("cups")
}
root.cupsBuiltinInstance = null
}
}
Connections {

View File

@@ -47,6 +47,8 @@ Singleton {
signal brightnessStateUpdate(var data)
signal brightnessDeviceUpdate(var device)
property var activeSubscriptions: ["network", "loginctl", "freedesktop", "gamma", "bluetooth", "dwl", "brightness"]
Component.onCompleted: {
if (socketPath && socketPath.length > 0) {
detectUpdateCommand()
@@ -220,10 +222,74 @@ Singleton {
"method": "subscribe"
}
if (activeSubscriptions.length > 0) {
request.params = {
"services": activeSubscriptions
}
console.log("DMSService: Subscribing to services:", JSON.stringify(activeSubscriptions))
} else {
console.log("DMSService: Subscribing to all services")
}
subscribeSocket.send(request)
}
function subscribe(services) {
if (!Array.isArray(services)) {
services = [services]
}
activeSubscriptions = services
if (subscribeConnected) {
subscribeSocket.connected = false
Qt.callLater(() => {
subscribeSocket.connected = true
})
}
}
function addSubscription(service) {
if (activeSubscriptions.includes("all")) {
console.warn("DMSService: Cannot add specific subscription when subscribed to 'all'")
return
}
if (!activeSubscriptions.includes(service)) {
const newSubs = [...activeSubscriptions, service]
subscribe(newSubs)
}
}
function removeSubscription(service) {
if (activeSubscriptions.includes("all")) {
const allServices = ["network", "loginctl", "freedesktop", "gamma", "bluetooth", "dwl", "brightness"]
const filtered = allServices.filter(s => s !== service)
subscribe(filtered)
} else {
const filtered = activeSubscriptions.filter(s => s !== service)
if (filtered.length === 0) {
console.warn("DMSService: Cannot remove last subscription")
return
}
subscribe(filtered)
}
}
function subscribeAll() {
subscribe(["all"])
}
function subscribeAllExcept(excludeServices) {
if (!Array.isArray(excludeServices)) {
excludeServices = [excludeServices]
}
const allServices = ["network", "loginctl", "freedesktop", "gamma", "bluetooth", "cups", "dwl", "brightness"]
const filtered = allServices.filter(s => !excludeServices.includes(s))
subscribe(filtered)
}
function handleSubscriptionEvent(response) {
if (response.error) {
if (response.error.includes("unknown method") && response.error.includes("subscribe")) {