From 2ab4d001d696a4e7176b05e606280ac54f7ff3f6 Mon Sep 17 00:00:00 2001 From: webwarrior Date: Wed, 22 May 2024 14:58:44 +0200 Subject: [PATCH] Core: make Gtk app uniqueness optional Add optional parameter to MauiGtkApplication constructor that determines if application can have several instances running at the same time. Default is false (no uniqueness check), which requires no DBus connections, unlike previous default (uniqueness is enforced). --- src/Core/src/Platform/Gtk/MauiGtkApplication.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Core/src/Platform/Gtk/MauiGtkApplication.cs b/src/Core/src/Platform/Gtk/MauiGtkApplication.cs index 6f0d31600efc..65978186709c 100644 --- a/src/Core/src/Platform/Gtk/MauiGtkApplication.cs +++ b/src/Core/src/Platform/Gtk/MauiGtkApplication.cs @@ -10,6 +10,12 @@ namespace Microsoft.Maui { public abstract class MauiGtkApplication : IPlatformApplication { + /// If true, only one instance of application can run at any moment. + public MauiGtkApplication(bool enforceUniqueness = false) + { + EnforceUniqueness = enforceUniqueness; + } + protected abstract MauiApp CreateMauiApp(); static readonly Regex InvalidGtkApplicationIdElementCharRegex = new Regex("[^A-Za-z0-9_\\-]"); @@ -53,6 +59,7 @@ public string? Name public IServiceProvider Services { get; protected set; } = null!; public IApplication Application { get; protected set; } = null!; + public bool EnforceUniqueness { get; } public void Run(params string[] args) { @@ -135,7 +142,8 @@ protected void StartupLauch(object sender, EventArgs args) protected void Launch(EventArgs args) { Gtk.Application.Init(); - var app = new Gtk.Application(ApplicationId, GLib.ApplicationFlags.None); + var flags = EnforceUniqueness ? GLib.ApplicationFlags.None : GLib.ApplicationFlags.NonUnique; + var app = new Gtk.Application(ApplicationId, flags); RegisterLifecycleEvents(app);