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)
|
const deviceIndex = devices.findIndex(d => d.id === device.id)
|
||||||
if (deviceIndex !== -1) {
|
if (deviceIndex !== -1) {
|
||||||
const newDevices = [...devices]
|
const newDevices = [...devices]
|
||||||
let displayMax = device.class === "ddc" ? device.max : 100
|
const existingDevice = devices[deviceIndex]
|
||||||
if (displayMax <= 0 && deviceMaxCache[device.id]) {
|
const cachedMax = deviceMaxCache[device.id]
|
||||||
displayMax = deviceMaxCache[device.id]
|
|
||||||
} else if (displayMax > 0) {
|
let displayMax = cachedMax || (device.class === "ddc" ? device.max : 100)
|
||||||
|
if (displayMax > 0 && !cachedMax) {
|
||||||
const newCache = Object.assign({}, deviceMaxCache)
|
const newCache = Object.assign({}, deviceMaxCache)
|
||||||
newCache[device.id] = displayMax
|
newCache[device.id] = displayMax
|
||||||
deviceMaxCache = newCache
|
deviceMaxCache = newCache
|
||||||
}
|
}
|
||||||
|
|
||||||
newDevices[deviceIndex] = {
|
newDevices[deviceIndex] = {
|
||||||
"id": device.id,
|
"id": device.id,
|
||||||
"name": device.id,
|
"name": device.id,
|
||||||
@@ -87,14 +89,12 @@ Singleton {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const newMaxCache = Object.assign({}, deviceMaxCache)
|
||||||
devices = state.devices.map(d => {
|
devices = state.devices.map(d => {
|
||||||
let displayMax = d.class === "ddc" ? d.max : 100
|
const cachedMax = deviceMaxCache[d.id]
|
||||||
if (displayMax <= 0 && deviceMaxCache[d.id]) {
|
let displayMax = cachedMax || (d.class === "ddc" ? d.max : 100)
|
||||||
displayMax = deviceMaxCache[d.id]
|
if (displayMax > 0 && !cachedMax) {
|
||||||
} else if (displayMax > 0) {
|
newMaxCache[d.id] = displayMax
|
||||||
const newCache = Object.assign({}, deviceMaxCache)
|
|
||||||
newCache[d.id] = displayMax
|
|
||||||
deviceMaxCache = newCache
|
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
"id": d.id,
|
"id": d.id,
|
||||||
@@ -107,6 +107,7 @@ Singleton {
|
|||||||
"displayMax": displayMax
|
"displayMax": displayMax
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
deviceMaxCache = newMaxCache
|
||||||
|
|
||||||
const newBrightness = {}
|
const newBrightness = {}
|
||||||
for (const device of state.devices) {
|
for (const device of state.devices) {
|
||||||
@@ -207,7 +208,9 @@ Singleton {
|
|||||||
DMSService.sendRequest("brightness.setBrightness", params, response => {
|
DMSService.sendRequest("brightness.setBrightness", params, response => {
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("DisplayService: Failed to set brightness:", 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 => {
|
}, response => {
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("DisplayService: Failed to enable gamma control:", 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
|
nightModeEnabled = false
|
||||||
SessionData.setNightModeEnabled(false)
|
SessionData.setNightModeEnabled(false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
ToastService.dismissCategory("night-mode")
|
||||||
|
|
||||||
if (SessionData.nightModeAutoEnabled) {
|
if (SessionData.nightModeAutoEnabled) {
|
||||||
startAutomation()
|
startAutomation()
|
||||||
@@ -336,7 +340,9 @@ Singleton {
|
|||||||
}, response => {
|
}, response => {
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("DisplayService: Failed to disable gamma control:", 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", {
|
DMSService.sendRequest("wayland.gamma.setTemperature", {
|
||||||
"temp": temperature
|
"low": temperature,
|
||||||
|
"high": 6500
|
||||||
}, response => {
|
}, response => {
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("DisplayService: Failed to set temperature:", 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 => {
|
}, response => {
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("DisplayService: Failed to set temperature:", 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,7 +442,9 @@ Singleton {
|
|||||||
}, response => {
|
}, response => {
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("DisplayService: Failed to set manual times:", 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 => {
|
}, response => {
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("DisplayService: Failed to set temperature:", 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -469,7 +480,9 @@ Singleton {
|
|||||||
}, response => {
|
}, response => {
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("DisplayService: Failed to enable IP location:", 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) {
|
} else if (SessionData.latitude !== 0.0 && SessionData.longitude !== 0.0) {
|
||||||
@@ -487,7 +500,9 @@ Singleton {
|
|||||||
}, response => {
|
}, response => {
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("DisplayService: Failed to set location:", 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)
|
const trimmedLines = lines.map(line => line.replace(/\s+$/, '')).filter(line => line.length > 0)
|
||||||
configValidationOutput = trimmedLines.join('\n').trim()
|
configValidationOutput = trimmedLines.join('\n').trim()
|
||||||
if (hasInitialConnection) {
|
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
|
validateProcess.running = true
|
||||||
} else {
|
} else {
|
||||||
configValidationOutput = ""
|
configValidationOutput = ""
|
||||||
if (ToastService.toastVisible && ToastService.currentLevel === ToastService.levelError && ToastService.currentMessage.startsWith("niri:")) {
|
ToastService.dismissCategory("niri-config")
|
||||||
ToastService.hideToast()
|
|
||||||
}
|
|
||||||
fetchOutputs()
|
fetchOutputs()
|
||||||
if (hasInitialConnection && !suppressConfigToast && !suppressNextConfigToast && !matugenSuppression) {
|
if (hasInitialConnection && !suppressConfigToast && !suppressNextConfigToast && !matugenSuppression) {
|
||||||
ToastService.showInfo("niri: config reloaded")
|
ToastService.showInfo("niri: config reloaded", "", "", "niri-config")
|
||||||
} else if (suppressNextConfigToast) {
|
} else if (suppressNextConfigToast) {
|
||||||
suppressNextConfigToast = false
|
suppressNextConfigToast = false
|
||||||
suppressResetTimer.stop()
|
suppressResetTimer.stop()
|
||||||
|
|||||||
@@ -19,29 +19,92 @@ Singleton {
|
|||||||
property string currentCommand: ""
|
property string currentCommand: ""
|
||||||
property bool hasDetails: false
|
property bool hasDetails: false
|
||||||
property string wallpaperErrorStatus: ""
|
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({
|
toastQueue.push({
|
||||||
"message": message,
|
"message": message,
|
||||||
"level": level,
|
"level": level,
|
||||||
"details": details,
|
"details": details,
|
||||||
"command": command
|
"command": command,
|
||||||
|
"category": category
|
||||||
})
|
})
|
||||||
if (!toastVisible) {
|
if (!toastVisible) {
|
||||||
processQueue()
|
processQueue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showInfo(message, details = "", command = "") {
|
function showInfo(message, details = "", command = "", category = "") {
|
||||||
showToast(message, levelInfo, details, command)
|
showToast(message, levelInfo, details, command, category)
|
||||||
}
|
}
|
||||||
|
|
||||||
function showWarning(message, details = "", command = "") {
|
function showWarning(message, details = "", command = "", category = "") {
|
||||||
showToast(message, levelWarn, details, command)
|
showToast(message, levelWarn, details, command, category)
|
||||||
}
|
}
|
||||||
|
|
||||||
function showError(message, details = "", command = "") {
|
function showError(message, details = "", command = "", category = "") {
|
||||||
showToast(message, levelError, details, command)
|
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() {
|
function hideToast() {
|
||||||
@@ -49,6 +112,7 @@ Singleton {
|
|||||||
currentMessage = ""
|
currentMessage = ""
|
||||||
currentDetails = ""
|
currentDetails = ""
|
||||||
currentCommand = ""
|
currentCommand = ""
|
||||||
|
currentCategory = ""
|
||||||
hasDetails = false
|
hasDetails = false
|
||||||
currentLevel = levelInfo
|
currentLevel = levelInfo
|
||||||
toastTimer.stop()
|
toastTimer.stop()
|
||||||
@@ -68,6 +132,7 @@ Singleton {
|
|||||||
currentLevel = toast.level
|
currentLevel = toast.level
|
||||||
currentDetails = toast.details || ""
|
currentDetails = toast.details || ""
|
||||||
currentCommand = toast.command || ""
|
currentCommand = toast.command || ""
|
||||||
|
currentCategory = toast.category || ""
|
||||||
hasDetails = currentDetails.length > 0 || currentCommand.length > 0
|
hasDetails = currentDetails.length > 0 || currentCommand.length > 0
|
||||||
toastVisible = true
|
toastVisible = true
|
||||||
resetToastState()
|
resetToastState()
|
||||||
|
|||||||
Reference in New Issue
Block a user