Robustezza backend: source univoco per ogni comando (il motore executable non rieseguiva comandi ripetuti) e ritentativi limitati sulla scadenza del timer (niente stato bloccato)

This commit is contained in:
enne2
2026-09-25 16:22:59 +02:00
parent 93dc22b654
commit 82cd21f4b2
+30 -12
View File
@@ -29,9 +29,14 @@ PlasmoidItem {
property string backend: "unknown" // systemd | unsupported | unknown property string backend: "unknown" // systemd | unsupported | unknown
property int deadlineEpoch: 0 property int deadlineEpoch: 0
property int remainingSec: 0 property int remainingSec: 0
property bool timerExpiring: false
property bool unitsReady: false property bool unitsReady: false
property string lastError: "" property string lastError: ""
// scadenza del timer già gestita (evita rientranze sullo stesso deadline)
property int expiryHandledEpoch: 0
property int expiryAttempts: 0
// ultimo comando inviato al backend (per la pulizia del source)
property string lastActionSource: ""
property int actionCounter: 0
// operazione in corso verso il backend (feedback ottimistico) // operazione in corso verso il backend (feedback ottimistico)
property bool pending: false property bool pending: false
property string pendingTarget: "" // stato atteso: on | off property string pendingTarget: "" // stato atteso: on | off
@@ -121,15 +126,22 @@ PlasmoidItem {
if (deadlineEpoch > 0) { if (deadlineEpoch > 0) {
const remaining = deadlineEpoch - Math.floor(Date.now() / 1000) const remaining = deadlineEpoch - Math.floor(Date.now() / 1000)
remainingSec = remaining > 0 ? remaining : 0 remainingSec = remaining > 0 ? remaining : 0
// il timer è scaduto: disattiva una sola volta (evita rientranze if (remaining <= 0) {
// mentre lo stato del backend non è ancora aggiornato) // timer scaduto: disattiva, con ritentativi limitati se il
if (remaining <= 0 && !timerExpiring) { // backend non conferma (il flag sul deadline evita rientranze)
timerExpiring = true if (expiryHandledEpoch !== deadlineEpoch) {
deactivate(true) expiryHandledEpoch = deadlineEpoch
expiryAttempts = 1
deactivate(true)
} else if (expiryAttempts > 0 && expiryAttempts < 3) {
expiryAttempts += 1
deactivate(true)
}
} }
} else { } else {
remainingSec = 0 remainingSec = 0
timerExpiring = false expiryHandledEpoch = 0
expiryAttempts = 0
} }
} }
@@ -137,8 +149,15 @@ PlasmoidItem {
if (backend === "unsupported") { if (backend === "unsupported") {
return return
} }
const source = scriptPath + " " + command // ogni comando ha un source univoco (contatore): così il motore
actionSource.disconnectSource(source) // "executable" lo esegue sempre, anche se lo stesso comando era già
// stato eseguito prima.
if (lastActionSource !== "") {
actionSource.disconnectSource(lastActionSource)
}
actionCounter += 1
const source = scriptPath + " " + command + " " + actionCounter
lastActionSource = source
actionSource.connectSource(source) actionSource.connectSource(source)
} }
@@ -171,10 +190,10 @@ PlasmoidItem {
function activate() { function activate() {
const minutes = plasmoid.configuration.autoOffMinutes const minutes = plasmoid.configuration.autoOffMinutes
timerExpiring = false
backendState = "on" backendState = "on"
backendMode = startMode backendMode = startMode
remainingSec = minutes > 0 ? minutes * 60 : 0 remainingSec = minutes > 0 ? minutes * 60 : 0
expiryAttempts = 0
beginPending("on") beginPending("on")
run("on " + startMode + " " + minutes) run("on " + startMode + " " + minutes)
} }
@@ -211,7 +230,6 @@ PlasmoidItem {
if (!active) { if (!active) {
return return
} }
timerExpiring = false
backendMode = keepScreen ? "screen" : "sleep" backendMode = keepScreen ? "screen" : "sleep"
beginPending("on") beginPending("on")
run("switch " + (keepScreen ? "screen" : "sleep")) run("switch " + (keepScreen ? "screen" : "sleep"))
@@ -221,7 +239,7 @@ PlasmoidItem {
if (!active) { if (!active) {
return return
} }
timerExpiring = false expiryAttempts = 0
beginPending("on") beginPending("on")
if (minutes > 0) { if (minutes > 0) {
remainingSec = minutes * 60 remainingSec = minutes * 60