Skip to content

Commit a62c469

Browse files
* check whether pywayland can be imported or not * disable smartpause plugin if it says NameError: name 'ExtIdleNotifierV1' is not defined * Update safeeyes/plugins/smartpause/ext_idle_notify.py Co-authored-by: Copilot <[email protected]> * Update safeeyes/plugins/smartpause/ext_idle_notify.py Co-authored-by: Copilot <[email protected]> * Fix Ruff warnings * work on mypy * trying to fix mypy warning * Try fixing mypy error * fix typo * This should satisfy both ruff and mypy * reinstate the comments * Update ext_idle_notify.py * respect github warning, ignore local warning slgobinath#784 (comment) 😕 * remove unnecessary comment and remove # noqa : F401 * add comments about variable's values * More transparent code for exception handling --------- Co-authored-by: Copilot <[email protected]>
1 parent 450d970 commit a62c469

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

safeeyes/plugins/smartpause/ext_idle_notify.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,25 @@
2727

2828
from pywayland.client import Display
2929
from pywayland.protocol.wayland.wl_seat import WlSeat
30-
from pywayland.protocol.ext_idle_notify_v1 import (
31-
ExtIdleNotifierV1,
32-
ExtIdleNotificationV1,
33-
)
30+
31+
32+
if typing.TYPE_CHECKING:
33+
from pywayland.protocol.ext_idle_notify_v1 import (
34+
ExtIdleNotifierV1,
35+
ExtIdleNotificationV1,
36+
)
37+
38+
try:
39+
from pywayland.protocol.ext_idle_notify_v1 import (
40+
ExtIdleNotifierV1,
41+
ExtIdleNotificationV1,
42+
)
43+
except Exception as e:
44+
logging.warning("The ext_idle_notify_v1 feature is not available. Exception: %s", e)
45+
logging.warning("This is likely due to an older version of Wayland.")
46+
EXT_IDLE_NOTIFY_IMPORT_ERROR = True
47+
else:
48+
EXT_IDLE_NOTIFY_IMPORT_ERROR = False
3449

3550
from .interface import IdleMonitorInterface
3651
from safeeyes import utility

safeeyes/plugins/smartpause/plugin.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,18 @@ def on_start() -> None:
159159
elif use_swayidle:
160160
idle_monitor = IdleMonitorSwayidle()
161161
elif use_ext_idle_notify:
162-
from .ext_idle_notify import IdleMonitorExtIdleNotify
162+
from .ext_idle_notify import (
163+
IdleMonitorExtIdleNotify,
164+
EXT_IDLE_NOTIFY_IMPORT_ERROR,
165+
)
163166

167+
if EXT_IDLE_NOTIFY_IMPORT_ERROR:
168+
logging.warning(
169+
"SmartPause plugin disabled:"
170+
" ext_idle_notify_v1 not available on this system."
171+
)
172+
idle_monitor_unsupported = True
173+
return
164174
idle_monitor = IdleMonitorExtIdleNotify()
165175
else:
166176
idle_monitor = IdleMonitorX11()

0 commit comments

Comments
 (0)