mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-06 05:25:41 -05:00
errors: generally, handle errors more gracefully with toasts
This commit is contained in:
@@ -43,14 +43,16 @@ Singleton {
|
||||
const deviceIndex = devices.findIndex(d => d.id === device.id)
|
||||
if (deviceIndex !== -1) {
|
||||
const newDevices = [...devices]
|
||||
let displayMax = device.class === "ddc" ? device.max : 100
|
||||
if (displayMax <= 0 && deviceMaxCache[device.id]) {
|
||||
displayMax = deviceMaxCache[device.id]
|
||||
} else if (displayMax > 0) {
|
||||
const existingDevice = devices[deviceIndex]
|
||||
const cachedMax = deviceMaxCache[device.id]
|
||||
|
||||
let displayMax = cachedMax || (device.class === "ddc" ? device.max : 100)
|
||||
if (displayMax > 0 && !cachedMax) {
|
||||
const newCache = Object.assign({}, deviceMaxCache)
|
||||
newCache[device.id] = displayMax
|
||||
deviceMaxCache = newCache
|
||||
}
|
||||
|
||||
newDevices[deviceIndex] = {
|
||||
"id": device.id,
|
||||
"name": device.id,
|
||||
@@ -87,14 +89,12 @@ Singleton {
|
||||
return
|
||||
}
|
||||
|
||||
const newMaxCache = Object.assign({}, deviceMaxCache)
|
||||
devices = state.devices.map(d => {
|
||||
let displayMax = d.class === "ddc" ? d.max : 100
|
||||
if (displayMax <= 0 && deviceMaxCache[d.id]) {
|
||||
displayMax = deviceMaxCache[d.id]
|
||||
} else if (displayMax > 0) {
|
||||
const newCache = Object.assign({}, deviceMaxCache)
|
||||
newCache[d.id] = displayMax
|
||||
deviceMaxCache = newCache
|
||||
const cachedMax = deviceMaxCache[d.id]
|
||||
let displayMax = cachedMax || (d.class === "ddc" ? d.max : 100)
|
||||
if (displayMax > 0 && !cachedMax) {
|
||||
newMaxCache[d.id] = displayMax
|
||||
}
|
||||
return {
|
||||
"id": d.id,
|
||||
@@ -107,6 +107,7 @@ Singleton {
|
||||
"displayMax": displayMax
|
||||
}
|
||||
})
|
||||
deviceMaxCache = newMaxCache
|
||||
|
||||
const newBrightness = {}
|
||||
for (const device of state.devices) {
|
||||
@@ -207,7 +208,9 @@ Singleton {
|
||||
DMSService.sendRequest("brightness.setBrightness", params, response => {
|
||||
if (response.error) {
|
||||
console.error("DisplayService: Failed to set brightness:", response.error)
|
||||
ToastService.showError("Failed to set brightness: " + response.error)
|
||||
ToastService.showError("Failed to set brightness: " + response.error, "", "", "brightness")
|
||||
} else {
|
||||
ToastService.dismissCategory("brightness")
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -309,11 +312,12 @@ Singleton {
|
||||
}, response => {
|
||||
if (response.error) {
|
||||
console.error("DisplayService: Failed to enable gamma control:", response.error)
|
||||
ToastService.showError("Failed to enable night mode: " + response.error)
|
||||
ToastService.showError("Failed to enable night mode: " + response.error, "", "", "night-mode")
|
||||
nightModeEnabled = false
|
||||
SessionData.setNightModeEnabled(false)
|
||||
return
|
||||
}
|
||||
ToastService.dismissCategory("night-mode")
|
||||
|
||||
if (SessionData.nightModeAutoEnabled) {
|
||||
startAutomation()
|
||||
@@ -336,7 +340,9 @@ Singleton {
|
||||
}, response => {
|
||||
if (response.error) {
|
||||
console.error("DisplayService: Failed to disable gamma control:", response.error)
|
||||
ToastService.showError("Failed to disable night mode: " + response.error)
|
||||
ToastService.showError("Failed to disable night mode: " + response.error, "", "", "night-mode")
|
||||
} else {
|
||||
ToastService.dismissCategory("night-mode")
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -370,11 +376,14 @@ Singleton {
|
||||
}
|
||||
|
||||
DMSService.sendRequest("wayland.gamma.setTemperature", {
|
||||
"temp": temperature
|
||||
"low": temperature,
|
||||
"high": 6500
|
||||
}, response => {
|
||||
if (response.error) {
|
||||
console.error("DisplayService: Failed to set temperature:", response.error)
|
||||
ToastService.showError("Failed to set night mode temperature: " + response.error)
|
||||
ToastService.showError("Failed to set night mode temperature: " + response.error, "", "", "night-mode")
|
||||
} else {
|
||||
ToastService.dismissCategory("night-mode")
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -423,7 +432,7 @@ Singleton {
|
||||
}, response => {
|
||||
if (response.error) {
|
||||
console.error("DisplayService: Failed to set temperature:", response.error)
|
||||
ToastService.showError("Failed to set night mode temperature: " + response.error)
|
||||
ToastService.showError("Failed to set night mode temperature: " + response.error, "", "", "night-mode")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -433,7 +442,9 @@ Singleton {
|
||||
}, response => {
|
||||
if (response.error) {
|
||||
console.error("DisplayService: Failed to set manual times:", response.error)
|
||||
ToastService.showError("Failed to set night mode schedule: " + response.error)
|
||||
ToastService.showError("Failed to set night mode schedule: " + response.error, "", "", "night-mode")
|
||||
} else {
|
||||
ToastService.dismissCategory("night-mode")
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -459,7 +470,7 @@ Singleton {
|
||||
}, response => {
|
||||
if (response.error) {
|
||||
console.error("DisplayService: Failed to set temperature:", response.error)
|
||||
ToastService.showError("Failed to set night mode temperature: " + response.error)
|
||||
ToastService.showError("Failed to set night mode temperature: " + response.error, "", "", "night-mode")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -469,7 +480,9 @@ Singleton {
|
||||
}, response => {
|
||||
if (response.error) {
|
||||
console.error("DisplayService: Failed to enable IP location:", response.error)
|
||||
ToastService.showError("Failed to enable IP location: " + response.error)
|
||||
ToastService.showError("Failed to enable IP location: " + response.error, "", "", "night-mode")
|
||||
} else {
|
||||
ToastService.dismissCategory("night-mode")
|
||||
}
|
||||
})
|
||||
} else if (SessionData.latitude !== 0.0 && SessionData.longitude !== 0.0) {
|
||||
@@ -487,7 +500,9 @@ Singleton {
|
||||
}, response => {
|
||||
if (response.error) {
|
||||
console.error("DisplayService: Failed to set location:", response.error)
|
||||
ToastService.showError("Failed to set night mode location: " + response.error)
|
||||
ToastService.showError("Failed to set night mode location: " + response.error, "", "", "night-mode")
|
||||
} else {
|
||||
ToastService.dismissCategory("night-mode")
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -78,7 +78,7 @@ Singleton {
|
||||
const trimmedLines = lines.map(line => line.replace(/\s+$/, '')).filter(line => line.length > 0)
|
||||
configValidationOutput = trimmedLines.join('\n').trim()
|
||||
if (hasInitialConnection) {
|
||||
ToastService.showError("niri: failed to load config", configValidationOutput)
|
||||
ToastService.showError("niri: failed to load config", configValidationOutput, "", "niri-config")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -498,12 +498,10 @@ Singleton {
|
||||
validateProcess.running = true
|
||||
} else {
|
||||
configValidationOutput = ""
|
||||
if (ToastService.toastVisible && ToastService.currentLevel === ToastService.levelError && ToastService.currentMessage.startsWith("niri:")) {
|
||||
ToastService.hideToast()
|
||||
}
|
||||
ToastService.dismissCategory("niri-config")
|
||||
fetchOutputs()
|
||||
if (hasInitialConnection && !suppressConfigToast && !suppressNextConfigToast && !matugenSuppression) {
|
||||
ToastService.showInfo("niri: config reloaded")
|
||||
ToastService.showInfo("niri: config reloaded", "", "", "niri-config")
|
||||
} else if (suppressNextConfigToast) {
|
||||
suppressNextConfigToast = false
|
||||
suppressResetTimer.stop()
|
||||
|
||||
@@ -19,29 +19,92 @@ Singleton {
|
||||
property string currentCommand: ""
|
||||
property bool hasDetails: false
|
||||
property string wallpaperErrorStatus: ""
|
||||
property int maxQueueSize: 3
|
||||
property var lastErrorTime: ({})
|
||||
property int errorThrottleMs: 1000
|
||||
property string currentCategory: ""
|
||||
|
||||
function showToast(message, level = levelInfo, details = "", command = "", category = "") {
|
||||
const now = Date.now()
|
||||
const messageKey = message + level
|
||||
|
||||
if (level === levelError) {
|
||||
const lastTime = lastErrorTime[messageKey] || 0
|
||||
if (now - lastTime < errorThrottleMs) {
|
||||
return
|
||||
}
|
||||
lastErrorTime[messageKey] = now
|
||||
}
|
||||
|
||||
if (category && level === levelError) {
|
||||
if (currentCategory === category && toastVisible && currentLevel === levelError) {
|
||||
currentMessage = message
|
||||
currentDetails = details || ""
|
||||
currentCommand = command || ""
|
||||
hasDetails = currentDetails.length > 0 || currentCommand.length > 0
|
||||
resetToastState()
|
||||
if (hasDetails) {
|
||||
toastTimer.interval = 8000
|
||||
} else {
|
||||
toastTimer.interval = 5000
|
||||
}
|
||||
toastTimer.restart()
|
||||
return
|
||||
}
|
||||
|
||||
toastQueue = toastQueue.filter(t => t.category !== category)
|
||||
}
|
||||
|
||||
const isDuplicate = toastQueue.some(toast =>
|
||||
toast.message === message && toast.level === level
|
||||
)
|
||||
if (isDuplicate) {
|
||||
return
|
||||
}
|
||||
|
||||
if (toastQueue.length >= maxQueueSize) {
|
||||
if (level === levelError) {
|
||||
toastQueue = toastQueue.filter(t => t.level !== levelError).slice(0, maxQueueSize - 1)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
function showToast(message, level = levelInfo, details = "", command = "") {
|
||||
toastQueue.push({
|
||||
"message": message,
|
||||
"level": level,
|
||||
"details": details,
|
||||
"command": command
|
||||
"command": command,
|
||||
"category": category
|
||||
})
|
||||
if (!toastVisible) {
|
||||
processQueue()
|
||||
}
|
||||
}
|
||||
|
||||
function showInfo(message, details = "", command = "") {
|
||||
showToast(message, levelInfo, details, command)
|
||||
function showInfo(message, details = "", command = "", category = "") {
|
||||
showToast(message, levelInfo, details, command, category)
|
||||
}
|
||||
|
||||
function showWarning(message, details = "", command = "") {
|
||||
showToast(message, levelWarn, details, command)
|
||||
function showWarning(message, details = "", command = "", category = "") {
|
||||
showToast(message, levelWarn, details, command, category)
|
||||
}
|
||||
|
||||
function showError(message, details = "", command = "") {
|
||||
showToast(message, levelError, details, command)
|
||||
function showError(message, details = "", command = "", category = "") {
|
||||
showToast(message, levelError, details, command, category)
|
||||
}
|
||||
|
||||
function dismissCategory(category) {
|
||||
if (!category) {
|
||||
return
|
||||
}
|
||||
|
||||
if (currentCategory === category && toastVisible) {
|
||||
hideToast()
|
||||
return
|
||||
}
|
||||
|
||||
toastQueue = toastQueue.filter(t => t.category !== category)
|
||||
}
|
||||
|
||||
function hideToast() {
|
||||
@@ -49,6 +112,7 @@ Singleton {
|
||||
currentMessage = ""
|
||||
currentDetails = ""
|
||||
currentCommand = ""
|
||||
currentCategory = ""
|
||||
hasDetails = false
|
||||
currentLevel = levelInfo
|
||||
toastTimer.stop()
|
||||
@@ -68,6 +132,7 @@ Singleton {
|
||||
currentLevel = toast.level
|
||||
currentDetails = toast.details || ""
|
||||
currentCommand = toast.command || ""
|
||||
currentCategory = toast.category || ""
|
||||
hasDetails = currentDetails.length > 0 || currentCommand.length > 0
|
||||
toastVisible = true
|
||||
resetToastState()
|
||||
|
||||
Reference in New Issue
Block a user