Skip to content

Commit a07df22

Browse files
committed
Use glib's native asyncio integration when available
Glib >= 3.50 has native asyncio integration. When available, use it instead of gbulb. This requires few minor changes: - asyncio.run() doesn't work there (asyncio.set_event_loop() cannot be called on the main thread with glib...) - there is no gbulb.wait_signal() anymore - implement it manually Based on #191 by @CertainLach QubesOS/qubes-issues#9809
1 parent fc01331 commit a07df22

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

archlinux/PKGBUILD.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ depends=(
1111
bash
1212
glibc
1313
python
14+
python-gobject
1415
python-setuptools
1516
pam
1617
qubes-libvchan

debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Build-Depends:
1010
dh-python,
1111
lsb-release,
1212
python3-setuptools,
13-
python3-gbulb,
13+
python3-gi (>= 3.50.0) | python3-gbulb,
1414
pandoc,
1515
Standards-Version: 4.4.0.1
1616
Homepage: https://www.qubes-os.org

qrexec/tools/qrexec_policy_agent.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,20 @@
3131
import importlib.resources
3232

3333
# pylint: disable=import-error,wrong-import-position
34+
# pylint: disable=wrong-import-order
3435
import gi
3536

3637
gi.require_version("Gtk", "3.0")
3738
from gi.repository import Gtk, Gdk, GdkPixbuf, GLib, Gio
39+
try:
40+
from gi.events import GLibEventLoopPolicy
41+
has_gbulb = False
42+
except ImportError:
43+
import gbulb
44+
has_gbulb = True
3845

3946
# pylint: enable=import-error
4047

41-
# pylint: disable=wrong-import-order
42-
import gbulb
43-
4448
from .. import POLICY_AGENT_SOCKET_PATH
4549
from ..utils import sanitize_domain_name, sanitize_service_name
4650
from ..server import SocketService
@@ -508,7 +512,19 @@ def _close(self):
508512
self._rpc_window.close()
509513

510514
async def _wait_for_close(self):
511-
await gbulb.wait_signal(self._rpc_window, "delete-event")
515+
if has_gbulb:
516+
await gbulb.wait_signal(self._rpc_window, "delete-event")
517+
else:
518+
future = asyncio.Future()
519+
hnd = None
520+
def _delete_callback(*k):
521+
self._rpc_window.disconnect(hnd)
522+
future.set_result(k)
523+
hnd = self._rpc_window.connect(
524+
"delete-event",
525+
_delete_callback,
526+
)
527+
await future
512528

513529
def _show(self):
514530
self._rpc_window.set_keep_above(True)
@@ -668,10 +684,14 @@ def notify(self, resolution, service, argument, source, target):
668684
def main():
669685
args = parser.parse_args()
670686

671-
gbulb.install()
687+
if has_gbulb:
688+
gbulb.install()
689+
else:
690+
asyncio.set_event_loop_policy(GLibEventLoopPolicy())
691+
loop = asyncio.get_event_loop()
672692
agent = PolicyAgent(args.socket_path)
673693

674-
asyncio.run(agent.run())
694+
loop.run_until_complete(agent.run())
675695

676696

677697
if __name__ == "__main__":

rpm_spec/qubes-qrexec.spec.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ BuildRequires: python%{python3_pkgversion}-rpm-macros
4747
BuildRequires: systemd-rpm-macros
4848

4949
Requires: python%{python3_pkgversion}
50+
%if 0%{?fedora} < 42
5051
Requires: python%{python3_pkgversion}-gbulb
52+
%else
53+
Requires: python%{python3_pkgversion}-gobject >= 3.50.0
54+
%endif
5155
%if 0%{?is_opensuse}
5256
Requires: python%{python3_pkgversion}-pyinotify
5357
%else

0 commit comments

Comments
 (0)