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:
@@ -41,6 +41,18 @@ QtObject {
|
|||||||
|
|
||||||
onItemChanged: {
|
onItemChanged: {
|
||||||
root.cupsBuiltinInstance = item
|
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 {
|
Connections {
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ Singleton {
|
|||||||
signal brightnessStateUpdate(var data)
|
signal brightnessStateUpdate(var data)
|
||||||
signal brightnessDeviceUpdate(var device)
|
signal brightnessDeviceUpdate(var device)
|
||||||
|
|
||||||
|
property var activeSubscriptions: ["network", "loginctl", "freedesktop", "gamma", "bluetooth", "dwl", "brightness"]
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (socketPath && socketPath.length > 0) {
|
if (socketPath && socketPath.length > 0) {
|
||||||
detectUpdateCommand()
|
detectUpdateCommand()
|
||||||
@@ -220,10 +222,74 @@ Singleton {
|
|||||||
"method": "subscribe"
|
"method": "subscribe"
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("DMSService: Subscribing to all services")
|
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)
|
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) {
|
function handleSubscriptionEvent(response) {
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
if (response.error.includes("unknown method") && response.error.includes("subscribe")) {
|
if (response.error.includes("unknown method") && response.error.includes("subscribe")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user