Better sleep state handling for Linux

This commit is contained in:
Deniz Şafak
2025-05-15 21:15:47 +03:00
parent b75277a3cb
commit e03336836b
2 changed files with 14 additions and 13 deletions
+4
View File
@@ -1,3 +1,7 @@
# v1.0.8 (pre-release)
- Improved input box background color handling, fixed display issues in Linux Wayland.
- Better sleep state handling for Linux.
# v1.0.7
- Improve chaptered audio generation by outputting directly as `m4b` instead of converting from `wav`.
- Ignore chapter markers and single newlines when calculating text length, improving the accuracy of the text length calculation.
+10 -13
View File
@@ -227,29 +227,26 @@ def prevent_sleep_start():
system = platform.system()
if system == "Windows":
import ctypes
ctypes.windll.kernel32.SetThreadExecutionState(
0x80000000 | 0x00000001 | 0x00000040
) # ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED
)
elif system == "Darwin":
_sleep_procs["Darwin"] = create_process("caffeinate")
_sleep_procs["Darwin"] = create_process(["caffeinate"])
elif system == "Linux":
try:
_sleep_procs["Linux"] = create_process(
"systemd-inhibit --what=sleep --why=TextToAudiobook conversion sleep 999999"
)
except Exception:
try:
create_process("xdg-screensaver reset")
except Exception:
pass
# use a sleep that never exits so inhibition stays active
_sleep_procs["Linux"] = create_process([
"systemd-inhibit",
"--what=handle-lid-switch:sleep",
"--mode=block",
"sleep",
"infinity",
])
def prevent_sleep_end():
system = platform.system()
if system == "Windows":
import ctypes
ctypes.windll.kernel32.SetThreadExecutionState(0x80000000) # ES_CONTINUOUS
elif system in ("Darwin", "Linux") and _sleep_procs[system]:
try: