From 46b0ec6aa862d209fcfa0269be66b4b62ce1668c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Maillard?= <33429284+sebastien-maillard@users.noreply.github.com> Date: Mon, 2 Dec 2024 22:32:16 +0100 Subject: [PATCH] AutoStandby: schedule next standby on init (#12815) --- plugins/autostandby.koplugin/main.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugins/autostandby.koplugin/main.lua b/plugins/autostandby.koplugin/main.lua index cd3422db8..f12709670 100644 --- a/plugins/autostandby.koplugin/main.lua +++ b/plugins/autostandby.koplugin/main.lua @@ -42,10 +42,17 @@ function AutoStandby:init() UIManager.event_hook:registerWidget("InputEvent", self) self.ui.menu:registerToMainMenu(self) + + -- Schedule the next standby on plugin init, either: + -- 1. When KOReader starts -> to prevent the device from instantly going into standby + -- 2. During a transition -> since the standby scheduled following the input event leading to the transition has been unscheduled + -- to avoid going into standby during the transition, re-schedule the next standby + self:_scheduleNext(os.time(), self.settings.data) end function AutoStandby:onCloseWidget() logger.dbg("AutoStandby:onCloseWidget() instance=", tostring(self)) + -- Unschedule the next standby to avoid going into standby during a transition UIManager:unschedule(AutoStandby.allow) end @@ -79,6 +86,12 @@ function AutoStandby:onInputEvent() return end + self:_scheduleNext(t, config) +end + +-- Schedule the next standby for when it's actually due +function AutoStandby:_scheduleNext(t, config) + -- Nuke past timer as we'll reschedule the allow (or not) UIManager:unschedule(AutoStandby.allow)