Skip to content

Commit d545223

Browse files
committed
typing: add Context to smartpause plugin
1 parent b7adbf0 commit d545223

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

safeeyes/plugins/smartpause/plugin.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import typing
2222

2323
from safeeyes.model import State
24+
from safeeyes.context import Context
2425

2526
from .interface import IdleMonitorInterface
2627
from .gnome_dbus import IdleMonitorGnomeDBus
@@ -31,7 +32,7 @@
3132
Safe Eyes smart pause plugin
3233
"""
3334

34-
context = None
35+
context: Context
3536
idle_time: float = 0
3637
enable_safeeyes = None
3738
disable_safeeyes = None
@@ -60,7 +61,7 @@ def _on_idle() -> None:
6061
global smart_pause_activated
6162
global idle_start_time
6263

63-
if context["state"] == State.WAITING: # type: ignore[index]
64+
if context["state"] == State.WAITING:
6465
smart_pause_activated = True
6566
idle_start_time = datetime.datetime.now() - datetime.timedelta(
6667
seconds=idle_time
@@ -73,15 +74,12 @@ def _on_resumed() -> None:
7374
global smart_pause_activated
7475
global idle_start_time
7576

76-
if (
77-
context["state"] == State.RESTING # type: ignore[index]
78-
and idle_start_time is not None
79-
):
77+
if context["state"] == State.RESTING and idle_start_time is not None:
8078
logging.info("Resume Safe Eyes due to user activity")
8179
smart_pause_activated = False
8280
idle_period = datetime.datetime.now() - idle_start_time
8381
idle_seconds = idle_period.total_seconds()
84-
context["idle_period"] = idle_seconds # type: ignore[index]
82+
context["idle_period"] = idle_seconds
8583
if idle_seconds < short_break_interval:
8684
# Credit back the idle time
8785
if next_break_time is not None:
@@ -281,7 +279,7 @@ def disable() -> None:
281279
global idle_monitor
282280

283281
# Remove the idle_period
284-
context.pop("idle_period", None) # type: ignore[union-attr]
282+
context.pop("idle_period", None)
285283

286284
if idle_monitor is not None:
287285
idle_monitor.stop()

0 commit comments

Comments
 (0)