From c2e2004cfd0d7f931f6572960a3e5d024962b5d3 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 24 Nov 2024 13:11:38 +0000 Subject: [PATCH] Use spawn_async --- src/Widgets/TerminalWidget.vala | 53 +++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/src/Widgets/TerminalWidget.vala b/src/Widgets/TerminalWidget.vala index ef819fed46..d4584a0ca5 100644 --- a/src/Widgets/TerminalWidget.vala +++ b/src/Widgets/TerminalWidget.vala @@ -716,29 +716,58 @@ namespace Terminal { /* We need opening uri to be available asap when constructing window with working directory * so remove idle loop, which appears not to be necessary any longer */ - try { - this.spawn_sync (Vte.PtyFlags.DEFAULT, dir, { shell }, - envv, SpawnFlags.SEARCH_PATH, null, out this.child_pid, null); - } catch (Error e) { - warning (e.message); - } + this.spawn_async ( + Vte.PtyFlags.DEFAULT, + dir, + { shell }, + envv, + SpawnFlags.SEARCH_PATH, + null, + -1, + null, + (terminal, pid, error) => { + if (error == null) { + this.child_pid = pid; + } else { + warning (error.message); + } - check_cwd_changed (); + check_cwd_changed (); + } + ); } public void run_program (string _program_string, string? working_directory) { + string[]? program_with_args = null; + this.program_string = _program_string; try { - string[]? program_with_args = null; - this.program_string = _program_string; Shell.parse_argv (program_string, out program_with_args); - - this.spawn_sync (Vte.PtyFlags.DEFAULT, working_directory, program_with_args, - null, SpawnFlags.SEARCH_PATH, null, out this.child_pid, null); } catch (Error e) { warning (e.message); feed ((e.message + "\r\n\r\n").data); active_shell (working_directory); + return; } + + this.spawn_async ( + Vte.PtyFlags.DEFAULT, + working_directory, + program_with_args, + null, + SpawnFlags.SEARCH_PATH, + null, + -1, + null, + (terminal, pid, error) => { + if (error == null) { + this.child_pid = pid; + } else { + warning (error.message); + feed ((error.message + "\r\n\r\n").data); + active_shell (working_directory); + } + } + ); } public bool try_get_foreground_pid (out int pid) {