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 # v1.0.7
- Improve chaptered audio generation by outputting directly as `m4b` instead of converting from `wav`. - 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. - 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() system = platform.system()
if system == "Windows": if system == "Windows":
import ctypes import ctypes
ctypes.windll.kernel32.SetThreadExecutionState( ctypes.windll.kernel32.SetThreadExecutionState(
0x80000000 | 0x00000001 | 0x00000040 0x80000000 | 0x00000001 | 0x00000040
) # ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED )
elif system == "Darwin": elif system == "Darwin":
_sleep_procs["Darwin"] = create_process("caffeinate") _sleep_procs["Darwin"] = create_process(["caffeinate"])
elif system == "Linux": elif system == "Linux":
try: # use a sleep that never exits so inhibition stays active
_sleep_procs["Linux"] = create_process( _sleep_procs["Linux"] = create_process([
"systemd-inhibit --what=sleep --why=TextToAudiobook conversion sleep 999999" "systemd-inhibit",
) "--what=handle-lid-switch:sleep",
except Exception: "--mode=block",
try: "sleep",
create_process("xdg-screensaver reset") "infinity",
except Exception: ])
pass
def prevent_sleep_end(): def prevent_sleep_end():
system = platform.system() system = platform.system()
if system == "Windows": if system == "Windows":
import ctypes import ctypes
ctypes.windll.kernel32.SetThreadExecutionState(0x80000000) # ES_CONTINUOUS ctypes.windll.kernel32.SetThreadExecutionState(0x80000000) # ES_CONTINUOUS
elif system in ("Darwin", "Linux") and _sleep_procs[system]: elif system in ("Darwin", "Linux") and _sleep_procs[system]:
try: try: