[Xfce4-commits] [xfce/thunar] 01/01: Prevent crash after updating thunar if old thunar deamon is still running
noreply at xfce.org
noreply at xfce.org
Sun Dec 10 21:56:44 CET 2017
This is an automated email from the git hooks/post-receive script.
a l e x p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository xfce/thunar.
commit ad8663a45b55797e3cd7e1b8ade1cef258c91d3c
Author: Alexander Schwinn <acs82 at gmx.de>
Date: Tue Nov 28 22:39:07 2017 +0100
Prevent crash after updating thunar if old thunar deamon is still running
---
thunar/main.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
diff --git a/thunar/main.c b/thunar/main.c
index 0e5ff2b..f541233 100644
--- a/thunar/main.c
+++ b/thunar/main.c
@@ -45,6 +45,73 @@
+static void
+thunar_terminate_running_thunar (void)
+{
+ GDBusConnection *connection;
+ GDBusProxy *proxy;
+ GError *error;
+
+ error = NULL;
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ g_assert_no_error (error);
+ proxy = g_dbus_proxy_new_sync (connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.xfce.Thunar", /* bus name */
+ "/org/xfce/FileManager", /* object path */
+ "org.xfce.Thunar", /* interface name */
+ NULL,
+ &error);
+ g_assert_no_error (error);
+ g_dbus_proxy_call_sync (proxy,
+ "Terminate", /* method name */
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ g_assert_no_error (error);
+ g_object_unref (proxy);
+ g_object_unref (connection);
+}
+
+
+
+static void
+thunar_dialog_ask_terminate_old_daemon_activate (GtkApplication* app, gpointer user_data)
+{
+ GtkWidget *window;
+ GtkWidget *dialog;
+ gint result;
+
+ window = gtk_application_window_new (app);
+ dialog = gtk_message_dialog_new (GTK_WINDOW (window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
+ _("Thunar cannot be launched because an older instance of thunar is still running.\n"
+ "Would you like to terminate the old thunar instance and start this instance?\n\n"
+ "Before accepting please make sure there are no pending operations (e.g. file copying) as terminating them may leave your files corrupted."));
+ result = gtk_dialog_run (GTK_DIALOG (dialog));
+ if (result == GTK_RESPONSE_YES)
+ thunar_terminate_running_thunar ();
+ gtk_widget_destroy (window);
+ g_application_quit (G_APPLICATION (app));
+}
+
+
+
+static void
+thunar_dialog_ask_terminate_old_daemon (void)
+{
+ GtkApplication *app;
+
+ app = gtk_application_new ("terminate.old.thunar.daemon", G_APPLICATION_FLAGS_NONE);
+ g_signal_connect (app, "activate", G_CALLBACK (thunar_dialog_ask_terminate_old_daemon_activate), NULL);
+ g_application_run (G_APPLICATION (app), 0, 0);
+ g_object_unref (app);
+}
+
+
+
int
main (int argc, char **argv)
{
@@ -93,6 +160,16 @@ main (int argc, char **argv)
/* use the Thunar icon as default for new windows */
gtk_window_set_default_icon_name ("Thunar");
+ /* Workaround to bypass "silent fail" if new thunar version is installed while an old version still runs as daemon */
+ /* FIXME: "g_application_register" and the following logic can be removed as soon as g_application/gdbus provides a way to prevent this error */
+ g_application_register (G_APPLICATION (application), NULL, &error);
+ if (error != NULL)
+ {
+ if (error->code == G_DBUS_ERROR_UNKNOWN_METHOD && strstr (error->message, "GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: Method \"DescribeAll\" with signature \"\" on interface \"org.gtk.Actions"))
+ thunar_dialog_ask_terminate_old_daemon ();
+ g_error_free (error);
+ }
+
/* do further processing inside gapplication */
g_application_run (G_APPLICATION (application), argc, argv);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list