-
-
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 support for locking session on Linux and refactor functions
- Added support for locking session on Linux with various methods - Moved lock session function to a dedicated lock_session.py file - Updated commands.py to use the new lock_session function
- Loading branch information
Showing
3 changed files
with
32 additions
and
1 deletion.
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,2 +1,3 @@ | ||
from .command_handler import handle_command | ||
from .screensaver import handle_command as screensaver | ||
from .lock_session import lock_session |
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,30 @@ | ||
from app.utils.platform import is_windows, is_linux, is_mac | ||
|
||
import subprocess | ||
from app.utils.logger import log | ||
|
||
|
||
def lock_session(): | ||
"""Lock the user's session.""" | ||
if is_windows: | ||
# Lock workstation on Windows | ||
subprocess.Popen("Rundll32.exe user32.dll,LockWorkStation", shell=True) | ||
|
||
elif is_linux: | ||
# Try various Linux locking methods | ||
if subprocess.run("dm-tool lock", shell=True).returncode == 0: | ||
return | ||
elif subprocess.run("xdg-screensaver lock", shell=True).returncode == 0: | ||
return | ||
elif subprocess.run("gnome-screensaver-command -l", shell=True).returncode == 0: | ||
return | ||
elif subprocess.run("loginctl lock-session", shell=True).returncode == 0: | ||
return | ||
elif subprocess.run("swaylock", shell=True).returncode == 0: | ||
return | ||
else: | ||
log.error("Unable to lock the session.") | ||
raise RuntimeError("Unable to lock the session.") | ||
|
||
else: | ||
raise NotImplementedError("Screensaver is not implemented for this platform.") |