Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TerminalWidget: Use the non-deprecated spawn API #809

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 41 additions & 12 deletions src/Widgets/TerminalWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Terminal {
private bool init_complete;
public bool resized {get; set;}

GLib.Pid child_pid;
GLib.Pid child_pid = -1;

public unowned MainWindow main_window { get; construct set; }

Expand Down Expand Up @@ -665,29 +665,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 (pid != -1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to check error == null since the else clause dereferences error?

this.child_pid = pid;
} else {
warning (error.message);
}
}
);

check_cwd_changed ();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be inside the callback?

}

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 (pid != -1) {
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) {
Expand Down
Loading