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

Application: Properly Unexport the DBus Interface on Exit #709

Merged
merged 2 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
67 changes: 38 additions & 29 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class Terminal.Application : Gtk.Application {
public int minimum_height;

private string commandline = "\0"; // used to temporary hold the argument to --commandline=
private uint dbus_id = 0;

public static GLib.Settings saved_state;
public static GLib.Settings settings;
Expand Down Expand Up @@ -102,11 +103,38 @@ public class Terminal.Application : Gtk.Application {
return base.local_command_line (ref args, out exit_status);
}

protected override int handle_local_options (VariantDict options) {
unowned string working_directory;
unowned string[] args;

if (options.lookup ("working-directory", "^&ay", out working_directory)) {
if (working_directory != "\0") {
Environment.set_current_dir (working_directory); // will be sent via platform-data
}

options.remove ("working-directory");
}

if (options.lookup (OPTION_REMAINING, "^a&ay", out args)) {
if (commandline != "\0") {
commandline += " %s".printf (string.joinv (" ", args));
} else {
commandline = string.joinv (" ", args);
}
}

if (commandline != "\0") {
options.insert ("commandline", "^&ay", commandline.escape ());
}

return -1;
}

protected override bool dbus_register (DBusConnection connection, string object_path) throws Error {
base.dbus_register (connection, object_path);

var dbus = new DBus ();
connection.register_object (object_path, dbus);
dbus_id = connection.register_object (object_path, dbus);

dbus.finished_process.connect ((id, process, exit_status) => {
TerminalWidget terminal = null;
Expand Down Expand Up @@ -153,34 +181,7 @@ public class Terminal.Application : Gtk.Application {
return true;
}

public override int handle_local_options (VariantDict options) {
unowned string working_directory;
unowned string[] args;

if (options.lookup ("working-directory", "^&ay", out working_directory)) {
if (working_directory != "\0") {
Environment.set_current_dir (working_directory); // will be sent via platform-data
}

options.remove ("working-directory");
}

if (options.lookup (OPTION_REMAINING, "^a&ay", out args)) {
if (commandline != "\0") {
commandline += " %s".printf (string.joinv (" ", args));
} else {
commandline = string.joinv (" ", args);
}
}

if (commandline != "\0") {
options.insert ("commandline", "^&ay", commandline.escape ());
}

return -1;
}

public override int command_line (ApplicationCommandLine command_line) {
protected override int command_line (ApplicationCommandLine command_line) {
unowned var options = command_line.get_options_dict ();
var window = (MainWindow) active_window;
bool new_window;
Expand Down Expand Up @@ -217,6 +218,14 @@ public class Terminal.Application : Gtk.Application {
return 0;
}

protected override void dbus_unregister (DBusConnection connection, string path) {
if (dbus_id != 0) {
connection.unregister_object (dbus_id);
}

base.dbus_unregister (connection, path);
}

public void new_window () {
new MainWindow (this, active_window == null).present ();
}
Expand Down
8 changes: 6 additions & 2 deletions src/tests/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ namespace Terminal.Test.Application {
return 0;
});

application.run (args);
if (application.run (args) != 0) {
GLib.Test.fail ();
}
}

private void option (string options, string platform_data, CommandLineCallback callback) {
Expand All @@ -58,7 +60,9 @@ namespace Terminal.Test.Application {
return application.command_line (cmdline);
});

application.run (null);
if (application.run (null) != 0) {
GLib.Test.fail ();
}
}

public static int main (string[] args) {
Expand Down