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

Core: make Gtk app uniqueness optional #25

Merged
merged 1 commit into from
May 22, 2024
Merged
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
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
Loading