1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-11 07:52:50 -05:00

api: unify dms API clients

- Single subscribe socket
- Single req/callback socket
- Remove PrepareForSleep handling
- Dependency on dms API version enforcement
- Remove gdbus from portal and session
This commit is contained in:
bbedward
2025-10-11 14:37:18 -04:00
parent 71543c35d6
commit 3a7777c643
8 changed files with 426 additions and 477 deletions

View File

@@ -22,24 +22,22 @@ Singleton {
function init() {}
function getSystemProfileImage() {
if (freedeskAvailable) {
const username = Quickshell.env("USER")
if (!username) return
if (!freedeskAvailable) return
DMSService.sendRequest("freedesktop.accounts.getUserIconFile", { username: username }, response => {
if (response.result && response.result.success) {
const iconFile = response.result.value || ""
if (iconFile && iconFile !== "" && iconFile !== "/var/lib/AccountsService/icons/") {
systemProfileImage = iconFile
if (!profileImage || profileImage === "") {
profileImage = iconFile
}
const username = Quickshell.env("USER")
if (!username) return
DMSService.sendRequest("freedesktop.accounts.getUserIconFile", { username: username }, response => {
if (response.result && response.result.success) {
const iconFile = response.result.value || ""
if (iconFile && iconFile !== "" && iconFile !== "/var/lib/AccountsService/icons/") {
systemProfileImage = iconFile
if (!profileImage || profileImage === "") {
profileImage = iconFile
}
}
})
} else {
systemProfileCheckProcess.running = true
}
}
})
}
function getUserProfileImage(username) {
@@ -52,26 +50,23 @@ Singleton {
return
}
if (freedeskAvailable) {
DMSService.sendRequest("freedesktop.accounts.getUserIconFile", { username: username }, response => {
if (response.result && response.result.success) {
const icon = response.result.value || ""
if (icon && icon !== "" && icon !== "/var/lib/AccountsService/icons/") {
profileImage = icon
} else {
profileImage = ""
}
if (!freedeskAvailable) {
profileImage = ""
return
}
DMSService.sendRequest("freedesktop.accounts.getUserIconFile", { username: username }, response => {
if (response.result && response.result.success) {
const icon = response.result.value || ""
if (icon && icon !== "" && icon !== "/var/lib/AccountsService/icons/") {
profileImage = icon
} else {
profileImage = ""
}
})
} else {
userProfileCheckProcess.command = [
"bash", "-c",
`uid=$(id -u ${username} 2>/dev/null) && [ -n "$uid" ] && dbus-send --system --print-reply --dest=org.freedesktop.Accounts /org/freedesktop/Accounts/User$uid org.freedesktop.DBus.Properties.Get string:org.freedesktop.Accounts.User string:IconFile 2>/dev/null | grep -oP 'string "\\K[^"]+' || echo ""`
]
userProfileCheckProcess.running = true
}
} else {
profileImage = ""
}
})
}
function setProfileImage(imagePath) {
@@ -86,25 +81,23 @@ Singleton {
}
function getSystemColorScheme() {
if (freedeskAvailable) {
DMSService.sendRequest("freedesktop.settings.getColorScheme", null, response => {
if (response.result) {
systemColorScheme = response.result.value || 0
if (!freedeskAvailable) return
if (typeof Theme !== "undefined") {
const shouldBeLightMode = (systemColorScheme === 2)
if (Theme.isLightMode !== shouldBeLightMode) {
Theme.isLightMode = shouldBeLightMode
if (typeof SessionData !== "undefined") {
SessionData.setLightMode(shouldBeLightMode)
}
DMSService.sendRequest("freedesktop.settings.getColorScheme", null, response => {
if (response.result) {
systemColorScheme = response.result.value || 0
if (typeof Theme !== "undefined") {
const shouldBeLightMode = (systemColorScheme === 2)
if (Theme.isLightMode !== shouldBeLightMode) {
Theme.isLightMode = shouldBeLightMode
if (typeof SessionData !== "undefined") {
SessionData.setLightMode(shouldBeLightMode)
}
}
}
})
} else {
systemColorSchemeCheckProcess.running = true
}
}
})
}
function setLightMode(isLightMode) {
@@ -114,49 +107,32 @@ Singleton {
}
function setSystemColorScheme(isLightMode) {
if (!settingsPortalAvailable) return
if (!settingsPortalAvailable || !freedeskAvailable) return
const colorScheme = isLightMode ? "default" : "prefer-dark"
colorSchemeSetProcess.command = ["gsettings", "set", "org.gnome.desktop.interface", "color-scheme", colorScheme]
colorSchemeSetProcess.running = true
}
Process {
id: colorSchemeSetProcess
running: false
onExited: exitCode => {
if (exitCode === 0) {
DMSService.sendRequest("freedesktop.settings.setColorScheme", { preferDark: !isLightMode }, response => {
if (!response.error) {
Qt.callLater(() => getSystemColorScheme())
}
}
})
}
function setSystemProfileImage(imagePath) {
if (!accountsServiceAvailable) return
if (!accountsServiceAvailable || !freedeskAvailable) return
if (freedeskAvailable) {
DMSService.sendRequest("freedesktop.accounts.setIconFile", { path: imagePath || "" }, response => {
if (response.error) {
console.warn("PortalService: Failed to set icon file:", response.error)
} else {
Qt.callLater(() => getSystemProfileImage())
}
})
} else {
const path = imagePath || ""
systemProfileSetProcess.command = ["bash", "-c", `dbus-send --system --print-reply --dest=org.freedesktop.Accounts /org/freedesktop/Accounts/User$(id -u) org.freedesktop.Accounts.User.SetIconFile string:'${path}'`]
systemProfileSetProcess.running = true
}
DMSService.sendRequest("freedesktop.accounts.setIconFile", { path: imagePath || "" }, response => {
if (response.error) {
console.warn("PortalService: Failed to set icon file:", response.error)
} else {
Qt.callLater(() => getSystemProfileImage())
}
})
}
Component.onCompleted: {
if (socketPath && socketPath.length > 0) {
checkDMSCapabilities()
} else {
console.log("PortalService: DMS_SOCKET not set, using fallback methods")
checkAccountsServiceFallback()
checkSettingsPortalFallback()
console.log("PortalService: DMS_SOCKET not set")
}
}
@@ -193,9 +169,7 @@ Singleton {
checkAccountsService()
checkSettingsPortal()
} else {
console.log("PortalService: freedesktop capability not available in DMS, using fallback methods")
checkAccountsServiceFallback()
checkSettingsPortalFallback()
console.log("PortalService: freedesktop capability not available in DMS")
}
}
@@ -225,14 +199,6 @@ Singleton {
})
}
function checkAccountsServiceFallback() {
accountsServiceCheckProcess.running = true
}
function checkSettingsPortalFallback() {
settingsPortalCheckProcess.running = true
}
function getGreeterUserProfileImage(username) {
if (!username) {
profileImage = ""
@@ -245,54 +211,6 @@ Singleton {
userProfileCheckProcess.running = true
}
Process {
id: accountsServiceCheckProcess
command: ["bash", "-c", "dbus-send --system --print-reply --dest=org.freedesktop.Accounts /org/freedesktop/Accounts org.freedesktop.Accounts.FindUserByName string:\"$USER\""]
running: false
onExited: exitCode => {
accountsServiceAvailable = (exitCode === 0)
if (accountsServiceAvailable) {
getSystemProfileImage()
}
}
}
Process {
id: systemProfileCheckProcess
command: ["bash", "-c", "dbus-send --system --print-reply --dest=org.freedesktop.Accounts /org/freedesktop/Accounts/User$(id -u) org.freedesktop.DBus.Properties.Get string:org.freedesktop.Accounts.User string:IconFile"]
running: false
stdout: StdioCollector {
onStreamFinished: {
const match = text.match(/string\s+"([^"]+)"/)
if (match && match[1] && match[1] !== "" && match[1] !== "/var/lib/AccountsService/icons/") {
systemProfileImage = match[1]
if (!profileImage || profileImage === "") {
profileImage = systemProfileImage
}
}
}
}
onExited: exitCode => {
if (exitCode !== 0) {
systemProfileImage = ""
}
}
}
Process {
id: systemProfileSetProcess
running: false
onExited: exitCode => {
if (exitCode === 0) {
getSystemProfileImage()
}
}
}
Process {
id: userProfileCheckProcess
command: []
@@ -316,50 +234,6 @@ Singleton {
}
}
Process {
id: settingsPortalCheckProcess
command: ["gdbus", "call", "--session", "--dest", "org.freedesktop.portal.Desktop", "--object-path", "/org/freedesktop/portal/desktop", "--method", "org.freedesktop.portal.Settings.ReadOne", "org.freedesktop.appearance", "color-scheme"]
running: false
onExited: exitCode => {
settingsPortalAvailable = (exitCode === 0)
if (settingsPortalAvailable) {
getSystemColorScheme()
}
}
}
Process {
id: systemColorSchemeCheckProcess
command: ["gdbus", "call", "--session", "--dest", "org.freedesktop.portal.Desktop", "--object-path", "/org/freedesktop/portal/desktop", "--method", "org.freedesktop.portal.Settings.ReadOne", "org.freedesktop.appearance", "color-scheme"]
running: false
stdout: StdioCollector {
onStreamFinished: {
const match = text.match(/uint32 (\d+)/)
if (match && match[1]) {
systemColorScheme = parseInt(match[1])
if (typeof Theme !== "undefined") {
const shouldBeLightMode = (systemColorScheme === 2)
if (Theme.isLightMode !== shouldBeLightMode) {
Theme.isLightMode = shouldBeLightMode
if (typeof SessionData !== "undefined") {
SessionData.setLightMode(shouldBeLightMode)
}
}
}
}
}
}
onExited: exitCode => {
if (exitCode !== 0) {
systemColorScheme = 0
}
}
}
IpcHandler {
target: "profile"