From eb0ee5f33aa1429ffdc49db7b930fb5e5b3d54e7 Mon Sep 17 00:00:00 2001 From: Jehan Date: Mon, 12 Jun 2023 00:58:09 +0200 Subject: [PATCH] Issue #9598: do not rely on GApplication uniqueness feature. When passing an application ID (which is necessary for application inhibition to work, i.e. logoff/reboot/shutdown inhibition), GApplication will try to ensure process uniqueness, which will trigger a new activation to an already running process. Since our current code assumes that the application can be activated a single time only, this was what was triggering a whole lot of errors (on the first running process) in #9598 because there was all the initialization code which ran again, whereas it was not supposed to. This doubly-running initialization code was also what completely messed up the session files, hence broke the GUI after a restart (#9599). Therefore passing G_APPLICATION_NON_UNIQUE advertizes we don't want GIO to handle process uniqueness for us. Note that this is actually a very interesting feature which we have had in GIMP codebase forever. It would be interesting to kill all our own uniqueness code in favor of GIO code (and let them handle/maintain passing command line arguments from one process to another, for all possible platforms). So I added a TODO for this (for now, we just ignore this feature as it doesn't work well with current codebase). --- app/gimpconsoleapp.c | 1 + app/gui/gimpapp.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/gimpconsoleapp.c b/app/gimpconsoleapp.c index db7f9b3f7a..309d7263c4 100644 --- a/app/gimpconsoleapp.c +++ b/app/gimpconsoleapp.c @@ -66,6 +66,7 @@ gimp_console_app_new (Gimp *gimp, app = g_object_new (GIMP_TYPE_CONSOLE_APP, "application-id", GIMP_APPLICATION_ID, + "flags", G_APPLICATION_DEFAULT_FLAGS | G_APPLICATION_NON_UNIQUE, "gimp", gimp, "filenames", filenames, "as-new", as_new, diff --git a/app/gui/gimpapp.c b/app/gui/gimpapp.c index da4b0cf9a8..f0c09e0aa7 100644 --- a/app/gui/gimpapp.c +++ b/app/gui/gimpapp.c @@ -131,6 +131,18 @@ gimp_app_new (Gimp *gimp, app = g_object_new (GIMP_TYPE_APP, "application-id", GIMP_APPLICATION_ID, + /* We have our own code to handle process uniqueness, so + * when we reached this code, we are already passed this + * (it means that either this is the first process, or we + * don't want uniqueness). See bugs #9598 and #9599 for + * what happens when we let GIO try to handle uniqueness. + * + * TODO: since GApplication has code to pass over files + * and command line arguments, we may eventually want to + * remove our own code for uniqueness and batch command + * inter-process communication. This should be tested. + */ + "flags", G_APPLICATION_DEFAULT_FLAGS | G_APPLICATION_NON_UNIQUE, "gimp", gimp, "filenames", filenames, "as-new", as_new,