From 1e5c492bf55e091fee4c429a52bea7fd168e3aed Mon Sep 17 00:00:00 2001 From: Sandeep Bist Date: Wed, 28 Oct 2026 11:58:34 +0530 Subject: [PATCH] fix(launcher): detach application output from launcher replies --- scripts/launch-app.py | 9 ++++++--- tests/launcher.py | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/scripts/launch-app.py b/scripts/launch-app.py index 64f17c2..f5a36ae 100644 --- a/scripts/launch-app.py +++ b/scripts/launch-app.py @@ -7,7 +7,7 @@ def launch(identifier, terminal='foot'): import gi gi.require_version('Gio', '2.0') gi.require_version('GioUnix', '2.0') - from gi.repository import Gio, GioUnix + from gi.repository import Gio, GioUnix, GLib if os.environ.get('MODESTY_PREVIEW') == '1': raise ValueError('Launching is disabled in preview') env = clean_environment() os.environ.clear(); os.environ.update(env) @@ -19,7 +19,6 @@ def launch(identifier, terminal='foot'): # desktop entry with an explicit terminal prefix, preserving Exec syntax. if terminal not in ('foot', 'kitty', 'alacritty', 'wezterm'): raise ValueError('Unsupported terminal') if not shutil.which(terminal): raise ValueError(terminal+' is not installed. Choose another terminal in Settings.') - from gi.repository import GLib keyfile = GLib.KeyFile() keyfile.load_from_file(entry.get_filename(), GLib.KeyFileFlags.NONE) prefix = {'foot':'foot -e ', 'kitty':'kitty ', 'alacritty':'alacritty -e ', 'wezterm':'wezterm start -- '}[terminal] @@ -28,7 +27,11 @@ def launch(identifier, terminal='foot'): keyfile.set_boolean('Desktop Entry','DBusActivatable',False) entry = GioUnix.DesktopAppInfo.new_from_keyfile(keyfile) context = Gio.AppLaunchContext() - if not entry.launch([], context): raise RuntimeError('The application could not be started') + # App output must not retain or corrupt the launcher's JSON reply pipes. + with open(os.devnull, 'r+b', buffering=0) as streams: + if not entry.launch_uris_as_manager_with_fds([], context, GLib.SpawnFlags.SEARCH_PATH, + None, None, None, None, streams.fileno(), streams.fileno(), streams.fileno()): + raise RuntimeError('The application could not be started') return {'ok': True, 'id': identifier} def close_app(identifier): diff --git a/tests/launcher.py b/tests/launcher.py index 0d13ce8..159ab05 100644 --- a/tests/launcher.py +++ b/tests/launcher.py @@ -22,3 +22,30 @@ print('PASS desktop launch', 'terminal' if is_terminal else 'GUI', 'quoted args, field codes, working directory, clean environment') bad=subprocess.run(['python3','scripts/launch-app.py','modesty-definitely-missing'],capture_output=True,text=True);assert bad.returncode and not json.loads(bad.stdout)['ok'] print('PASS missing desktop entry reports error') + release=p/'release';result=p/'stdio.json' + noisy=p/'noisy app.py' + noisy.write_text('''import os,time,sys +from pathlib import Path +release=Path(os.environ['LAUNCH_RELEASE']) +deadline=time.monotonic()+10 +while not release.exists() and time.monotonic()