Skip to content

Commit

Permalink
Core: make Gtk app uniqueness optional
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
webwarrior-ws authored and knocte committed May 22, 2024
1 parent d92687b commit 6b67685
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Core/src/Platform/Gtk/MauiGtkApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ namespace Microsoft.Maui
{
public abstract class MauiGtkApplication : IPlatformApplication
{
/// <param name="enforceUniqueness">If true, only one instance of application can run at any moment.</param>
public MauiGtkApplication(bool enforceUniqueness = false)
{
EnforceUniqueness = enforceUniqueness;
}

protected abstract MauiApp CreateMauiApp();

static readonly Regex InvalidGtkApplicationIdElementCharRegex = new Regex("[^A-Za-z0-9_\\-]");
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 6b67685

Please sign in to comment.