Skip to content

Commit 5bc3e16

Browse files
committed
screensaver: add tray action to lock screen now
1 parent e0d38fa commit 5bc3e16

File tree

2 files changed

+80
-8
lines changed

2 files changed

+80
-8
lines changed

safeeyes/plugins/screensaver/plugin.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
min_seconds = 0
3434
seconds_passed = 0
3535
tray_icon_path = None
36+
icon_lock_later_path = None
3637

3738

3839
def __lock_screen_command():
@@ -102,21 +103,29 @@ def __lock_screen_command():
102103
return None
103104

104105

105-
def __lock_screen():
106+
def __lock_screen_later():
106107
global user_locked_screen
107108
user_locked_screen = True
108109

109110

111+
def __lock_screen_now() -> None:
112+
utility.execute_command(lock_screen_command)
113+
114+
110115
def init(ctx, safeeyes_config, plugin_config):
111116
"""Initialize the screensaver plugin."""
112117
global context
113118
global lock_screen_command
114119
global min_seconds
115120
global tray_icon_path
121+
global icon_lock_later_path
116122
logging.debug("Initialize Screensaver plugin")
117123
context = ctx
118124
min_seconds = plugin_config["min_seconds"]
119125
tray_icon_path = os.path.join(plugin_config["path"], "resource/lock.png")
126+
icon_lock_later_path = os.path.join(
127+
plugin_config["path"], "resource/rotation-lock-symbolic.svg"
128+
)
120129
if plugin_config["command"]:
121130
lock_screen_command = plugin_config["command"].split()
122131
else:
@@ -147,10 +156,22 @@ def on_stop_break():
147156
min_seconds.
148157
"""
149158
if user_locked_screen or (lock_screen and seconds_passed >= min_seconds):
150-
utility.execute_command(lock_screen_command)
151-
152-
153-
def get_tray_action(break_obj):
154-
return TrayAction.build(
155-
"Lock screen", tray_icon_path, "dialog-password", __lock_screen
156-
)
159+
__lock_screen_now()
160+
161+
162+
def get_tray_action(break_obj) -> list[TrayAction]:
163+
return [
164+
TrayAction.build(
165+
"Lock screen now",
166+
tray_icon_path,
167+
"system-lock-screen",
168+
__lock_screen_now,
169+
single_use=False,
170+
),
171+
TrayAction.build(
172+
"Lock screen after break",
173+
icon_lock_later_path,
174+
"dialog-password",
175+
__lock_screen_later,
176+
),
177+
]
Lines changed: 51 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)