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
+29 -11
View File
@@ -29,9 +29,14 @@ PlasmoidItem {
property string backend: "unknown" // systemd | unsupported | unknown
property int deadlineEpoch: 0
property int remainingSec: 0
property bool timerExpiring: false
property bool unitsReady: false
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)
property bool pending: false
property string pendingTarget: "" // stato atteso: on | off
@@ -121,15 +126,22 @@ PlasmoidItem {
if (deadlineEpoch > 0) {
const remaining = deadlineEpoch - Math.floor(Date.now() / 1000)
remainingSec = remaining > 0 ? remaining : 0
// il timer è scaduto: disattiva una sola volta (evita rientranze
// mentre lo stato del backend non è ancora aggiornato)
if (remaining <= 0 && !timerExpiring) {
timerExpiring = true
if (remaining <= 0) {
// timer scaduto: disattiva, con ritentativi limitati se il
// backend non conferma (il flag sul deadline evita rientranze)
if (expiryHandledEpoch !== deadlineEpoch) {
expiryHandledEpoch = deadlineEpoch
expiryAttempts = 1
deactivate(true)
} else if (expiryAttempts > 0 && expiryAttempts < 3) {
expiryAttempts += 1
deactivate(true)
}
}
} else {
remainingSec = 0
timerExpiring = false
expiryHandledEpoch = 0
expiryAttempts = 0
}
}
@@ -137,8 +149,15 @@ PlasmoidItem {
if (backend === "unsupported") {
return
}
const source = scriptPath + " " + command
actionSource.disconnectSource(source)
// ogni comando ha un source univoco (contatore): così il motore
// "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)
}
@@ -171,10 +190,10 @@ PlasmoidItem {
function activate() {
const minutes = plasmoid.configuration.autoOffMinutes
timerExpiring = false
backendState = "on"
backendMode = startMode
remainingSec = minutes > 0 ? minutes * 60 : 0
expiryAttempts = 0
beginPending("on")
run("on " + startMode + " " + minutes)
}
@@ -211,7 +230,6 @@ PlasmoidItem {
if (!active) {
return
}
timerExpiring = false
backendMode = keepScreen ? "screen" : "sleep"
beginPending("on")
run("switch " + (keepScreen ? "screen" : "sleep"))
@@ -221,7 +239,7 @@ PlasmoidItem {
if (!active) {
return
}
timerExpiring = false
expiryAttempts = 0
beginPending("on")
if (minutes > 0) {
remainingSec = minutes * 60