From 82cd21f4b2bc6b6fa97aa275e285ea30a3539f2c Mon Sep 17 00:00:00 2001 From: enne2 Date: Fri, 25 Sep 2026 16:22:59 +0200 Subject: [PATCH] Robustezza backend: source univoco per ogni comando (il motore executable non rieseguiva comandi ripetuti) e ritentativi limitati sulla scadenza del timer (niente stato bloccato) --- contents/ui/main.qml | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/contents/ui/main.qml b/contents/ui/main.qml index 55cd159..7643919 100644 --- a/contents/ui/main.qml +++ b/contents/ui/main.qml @@ -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 - deactivate(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