-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add screensaver support for Linux and refactor screensaver functions
- Added screensaver support for Linux, including X11 and Wayland - Moved screensaver functions to a dedicated screensaver.py file - Updated commands.py to use the new screensaver functions
- Loading branch information
Showing
3 changed files
with
56 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .command_handler import handle_command | ||
from .command_handler import handle_command | ||
from .screensaver import handle_command as screensaver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from app.utils.platform import is_windows, is_linux | ||
|
||
import os | ||
import subprocess | ||
import pyautogui | ||
from app.utils.kill_nircmd import kill_nircmd | ||
from app.utils.logger import log | ||
|
||
|
||
def handle_command(message): | ||
if message.endswith(("on", "/screensaver", "start")): | ||
screensaver() | ||
|
||
elif message.endswith(("hard", "full", "black")): | ||
screensaver(hard=True) | ||
|
||
elif message.endswith(("off", "false")): | ||
screensaver_off() | ||
|
||
else: | ||
return False | ||
return True | ||
|
||
|
||
def screensaver(hard=False): | ||
if is_windows: | ||
if hard: | ||
subprocess.Popen('"lib/nircmd.exe" monitor off', shell=True) | ||
kill_nircmd() | ||
else: | ||
subprocess.Popen("%windir%/system32/scrnsave.scr /s", shell=True) | ||
|
||
elif is_linux: | ||
# Try X11 (xset), then Wayland (gnome-screensaver) | ||
if subprocess.run("xset dpms force off", shell=True).returncode == 0: | ||
pass | ||
elif subprocess.run("gnome-screensaver-command -a", shell=True).returncode == 0: | ||
pass | ||
elif subprocess.run("swaymsg 'output * dpms off'", shell=True).returncode == 0: | ||
pass | ||
else: | ||
log.error("Unable to enable screensaver.") | ||
raise RuntimeError("Unable to enable screensaver.") | ||
|
||
else: | ||
raise NotImplementedError("Screensaver is not implemented for this platform.") | ||
|
||
|
||
def screensaver_off(): | ||
pyautogui.press("CTRL") | ||
if is_linux: | ||
os.system("gnome-screensaver-command -d") | ||
|