mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-29 07:52:50 -05:00
portal: handle profile setting errors
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
pragma Singleton
|
pragma Singleton
|
||||||
|
|
||||||
pragma ComponentBehavior: Bound
|
pragma ComponentBehavior
|
||||||
|
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import Quickshell
|
import Quickshell
|
||||||
@@ -18,28 +18,33 @@ Singleton {
|
|||||||
|
|
||||||
property bool freedeskAvailable: false
|
property bool freedeskAvailable: false
|
||||||
property string colorSchemeCommand: ""
|
property string colorSchemeCommand: ""
|
||||||
|
property string pendingProfileImage: ""
|
||||||
|
|
||||||
readonly property string socketPath: Quickshell.env("DMS_SOCKET")
|
readonly property string socketPath: Quickshell.env("DMS_SOCKET")
|
||||||
|
|
||||||
function init() {}
|
function init() {}
|
||||||
|
|
||||||
function getSystemProfileImage() {
|
function getSystemProfileImage() {
|
||||||
if (!freedeskAvailable) return
|
if (!freedeskAvailable)
|
||||||
|
return
|
||||||
|
|
||||||
const username = Quickshell.env("USER")
|
const username = Quickshell.env("USER")
|
||||||
if (!username) return
|
if (!username)
|
||||||
|
return
|
||||||
|
|
||||||
DMSService.sendRequest("freedesktop.accounts.getUserIconFile", { username: username }, response => {
|
DMSService.sendRequest("freedesktop.accounts.getUserIconFile", {
|
||||||
if (response.result && response.result.success) {
|
"username": username
|
||||||
const iconFile = response.result.value || ""
|
}, response => {
|
||||||
if (iconFile && iconFile !== "" && iconFile !== "/var/lib/AccountsService/icons/") {
|
if (response.result && response.result.success) {
|
||||||
systemProfileImage = iconFile
|
const iconFile = response.result.value || ""
|
||||||
if (!profileImage || profileImage === "") {
|
if (iconFile && iconFile !== "" && iconFile !== "/var/lib/AccountsService/icons/") {
|
||||||
profileImage = iconFile
|
systemProfileImage = iconFile
|
||||||
}
|
if (!profileImage || profileImage === "") {
|
||||||
}
|
profileImage = iconFile
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUserProfileImage(username) {
|
function getUserProfileImage(username) {
|
||||||
@@ -57,28 +62,28 @@ Singleton {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
DMSService.sendRequest("freedesktop.accounts.getUserIconFile", { username: username }, response => {
|
DMSService.sendRequest("freedesktop.accounts.getUserIconFile", {
|
||||||
if (response.result && response.result.success) {
|
"username": username
|
||||||
const icon = response.result.value || ""
|
}, response => {
|
||||||
if (icon && icon !== "" && icon !== "/var/lib/AccountsService/icons/") {
|
if (response.result && response.result.success) {
|
||||||
profileImage = icon
|
const icon = response.result.value || ""
|
||||||
} else {
|
if (icon && icon !== "" && icon !== "/var/lib/AccountsService/icons/") {
|
||||||
profileImage = ""
|
profileImage = icon
|
||||||
}
|
} else {
|
||||||
} else {
|
profileImage = ""
|
||||||
profileImage = ""
|
}
|
||||||
}
|
} else {
|
||||||
})
|
profileImage = ""
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function setProfileImage(imagePath) {
|
function setProfileImage(imagePath) {
|
||||||
profileImage = imagePath
|
|
||||||
if (accountsServiceAvailable) {
|
if (accountsServiceAvailable) {
|
||||||
if (imagePath) {
|
pendingProfileImage = imagePath
|
||||||
setSystemProfileImage(imagePath)
|
setSystemProfileImage(imagePath || "")
|
||||||
} else {
|
} else {
|
||||||
setSystemProfileImage("")
|
profileImage = imagePath
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,13 +91,14 @@ Singleton {
|
|||||||
if (typeof SettingsData !== "undefined" && SettingsData.syncModeWithPortal === false) {
|
if (typeof SettingsData !== "undefined" && SettingsData.syncModeWithPortal === false) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!freedeskAvailable) return
|
if (!freedeskAvailable)
|
||||||
|
return
|
||||||
|
|
||||||
DMSService.sendRequest("freedesktop.settings.getColorScheme", null, response => {
|
DMSService.sendRequest("freedesktop.settings.getColorScheme", null, response => {
|
||||||
if (response.result) {
|
if (response.result) {
|
||||||
systemColorScheme = response.result.value || 0
|
systemColorScheme = response.result.value || 0
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLightMode(isLightMode) {
|
function setLightMode(isLightMode) {
|
||||||
@@ -107,7 +113,7 @@ Singleton {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetScheme = isLightMode ? "default": "prefer-dark"
|
const targetScheme = isLightMode ? "default" : "prefer-dark"
|
||||||
|
|
||||||
if (colorSchemeCommand === "gsettings") {
|
if (colorSchemeCommand === "gsettings") {
|
||||||
Quickshell.execDetached(["gsettings", "set", "org.gnome.desktop.interface", "color-scheme", targetScheme])
|
Quickshell.execDetached(["gsettings", "set", "org.gnome.desktop.interface", "color-scheme", targetScheme])
|
||||||
@@ -118,25 +124,50 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setSystemIconTheme(themeName) {
|
function setSystemIconTheme(themeName) {
|
||||||
if (!settingsPortalAvailable || !freedeskAvailable) return
|
if (!settingsPortalAvailable || !freedeskAvailable)
|
||||||
|
return
|
||||||
|
|
||||||
DMSService.sendRequest("freedesktop.settings.setIconTheme", { iconTheme: themeName }, response => {
|
DMSService.sendRequest("freedesktop.settings.setIconTheme", {
|
||||||
if (response.error) {
|
"iconTheme": themeName
|
||||||
console.warn("PortalService: Failed to set icon theme:", response.error)
|
}, response => {
|
||||||
}
|
if (response.error) {
|
||||||
})
|
console.warn("PortalService: Failed to set icon theme:", response.error)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function setSystemProfileImage(imagePath) {
|
function setSystemProfileImage(imagePath) {
|
||||||
if (!accountsServiceAvailable || !freedeskAvailable) return
|
if (!accountsServiceAvailable || !freedeskAvailable)
|
||||||
|
return
|
||||||
|
|
||||||
DMSService.sendRequest("freedesktop.accounts.setIconFile", { path: imagePath || "" }, response => {
|
DMSService.sendRequest("freedesktop.accounts.setIconFile", {
|
||||||
if (response.error) {
|
"path": imagePath || ""
|
||||||
console.warn("PortalService: Failed to set icon file:", response.error)
|
}, response => {
|
||||||
} else {
|
if (response.error) {
|
||||||
Qt.callLater(() => getSystemProfileImage())
|
console.warn("PortalService: Failed to set icon file:", response.error)
|
||||||
}
|
|
||||||
})
|
const errorMsg = response.error.toString()
|
||||||
|
let userMessage = I18n.tr("Failed to set profile image")
|
||||||
|
|
||||||
|
if (errorMsg.includes("too large")) {
|
||||||
|
userMessage = I18n.tr("Profile image is too large. Please use a smaller image.")
|
||||||
|
} else if (errorMsg.includes("permission")) {
|
||||||
|
userMessage = I18n.tr("Permission denied to set profile image.")
|
||||||
|
} else if (errorMsg.includes("not found") || errorMsg.includes("does not exist")) {
|
||||||
|
userMessage = I18n.tr("Selected image file not found.")
|
||||||
|
} else {
|
||||||
|
userMessage = I18n.tr("Failed to set profile image: ") + errorMsg.split(":").pop().trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
Quickshell.execDetached(["notify-send", "-u", "normal", "-a", "DMS", "-i", "error", I18n.tr("Profile Image Error"), userMessage])
|
||||||
|
|
||||||
|
pendingProfileImage = ""
|
||||||
|
} else {
|
||||||
|
profileImage = pendingProfileImage
|
||||||
|
pendingProfileImage = ""
|
||||||
|
Qt.callLater(() => getSystemProfileImage())
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
@@ -186,29 +217,31 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkAccountsService() {
|
function checkAccountsService() {
|
||||||
if (!freedeskAvailable) return
|
if (!freedeskAvailable)
|
||||||
|
return
|
||||||
|
|
||||||
DMSService.sendRequest("freedesktop.getState", null, response => {
|
DMSService.sendRequest("freedesktop.getState", null, response => {
|
||||||
if (response.result && response.result.accounts) {
|
if (response.result && response.result.accounts) {
|
||||||
accountsServiceAvailable = response.result.accounts.available || false
|
accountsServiceAvailable = response.result.accounts.available || false
|
||||||
if (accountsServiceAvailable) {
|
if (accountsServiceAvailable) {
|
||||||
getSystemProfileImage()
|
getSystemProfileImage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkSettingsPortal() {
|
function checkSettingsPortal() {
|
||||||
if (!freedeskAvailable) return
|
if (!freedeskAvailable)
|
||||||
|
return
|
||||||
|
|
||||||
DMSService.sendRequest("freedesktop.getState", null, response => {
|
DMSService.sendRequest("freedesktop.getState", null, response => {
|
||||||
if (response.result && response.result.settings) {
|
if (response.result && response.result.settings) {
|
||||||
settingsPortalAvailable = response.result.settings.available || false
|
settingsPortalAvailable = response.result.settings.available || false
|
||||||
if (settingsPortalAvailable && SettingsData.syncModeWithPortal) {
|
if (settingsPortalAvailable && SettingsData.syncModeWithPortal) {
|
||||||
getSystemColorScheme()
|
getSystemColorScheme()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGreeterUserProfileImage(username) {
|
function getGreeterUserProfileImage(username) {
|
||||||
@@ -216,10 +249,7 @@ Singleton {
|
|||||||
profileImage = ""
|
profileImage = ""
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userProfileCheckProcess.command = [
|
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 ""`]
|
||||||
"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
|
userProfileCheckProcess.running = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user