Skip to content

Commit 2d85b6a

Browse files
Merge pull request slgobinath#808 from deltragon/smartpause-missing-import-error
smartpause: don't fail if types don't exist
2 parents 0572571 + 1e78e1c commit 2d85b6a

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

safeeyes/plugins/smartpause/ext_idle_notify.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,6 @@
3535
ExtIdleNotificationV1,
3636
)
3737

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
49-
5038
from .interface import IdleMonitorInterface
5139
from safeeyes import utility
5240

@@ -74,6 +62,16 @@ class IdleMonitorExtIdleNotify(IdleMonitorInterface):
7462
_idle_config: typing.Optional[IdleConfig] = None
7563

7664
def init(self) -> None:
65+
try:
66+
from pywayland.protocol.ext_idle_notify_v1 import (
67+
ExtIdleNotifierV1, # noqa: F401
68+
ExtIdleNotificationV1, # noqa: F401
69+
)
70+
except Exception as e:
71+
logging.warning("The ext_idle_notify_v1 feature is not available.")
72+
logging.warning("This is likely due to an older version of Wayland.")
73+
raise e
74+
7775
# we spawn one wayland client once
7876
# when the monitor is not running, it should be quite idle
7977
self._r_channel_started, self._w_channel_started = os.pipe()
@@ -197,8 +195,8 @@ class ExtIdleNotifyInternal:
197195
Split out into a separate object to simplify lifetime handling.
198196
"""
199197

200-
_idle_notifier: typing.Optional[ExtIdleNotifierV1] = None
201-
_notification: typing.Optional[ExtIdleNotificationV1] = None
198+
_idle_notifier: typing.Optional["ExtIdleNotifierV1"] = None
199+
_notification: typing.Optional["ExtIdleNotificationV1"] = None
202200
_display: Display
203201
_r_channel_stop: int
204202
_w_channel_started: int
@@ -323,6 +321,8 @@ def _listen(self):
323321
self._notification.dispatcher["resumed"] = self._idle_notifier_resume_handler
324322

325323
def _global_handler(self, reg, id_num, iface_name, version) -> None:
324+
from pywayland.protocol.ext_idle_notify_v1 import ExtIdleNotifierV1
325+
326326
if iface_name == "wl_seat":
327327
self._seat = reg.bind(id_num, WlSeat, version)
328328
if iface_name == "ext_idle_notifier_v1":

safeeyes/plugins/smartpause/plugin.py

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

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
174164
idle_monitor = IdleMonitorExtIdleNotify()
175165
else:
176166
idle_monitor = IdleMonitorX11()

0 commit comments

Comments
 (0)