Skip to content
Closed
Show file tree
Hide file tree
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
19 changes: 18 additions & 1 deletion Pinta/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@ private static void OpenMainWindow (int threads, IEnumerable<string> files, bool
Gsk.Module.Initialize ();
Pango.Module.Initialize ();
PangoCairo.Module.Initialize ();
var app = Adw.Application.New (PintaCore.ApplicationId, Gio.ApplicationFlags.NonUnique);

// Check if single-instance mode is enabled
var settings = new SettingsManager ();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this could use PintaCore.Settings instead to avoid creating another SettingsManager (and reloading the settings from disk again)

The line below uses PintaCore.ApplicationId so it should be safe to run the static constructors at this point

bool singleInstance = settings.GetSetting (SettingNames.SINGLE_INSTANCE_MODE, false);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'd need to find some way of configuring this setting in the GUI. If it requires editing the xml settings then it may as well not exist for the vast majority of users :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's right


// Use appropriate flags based on single-instance preference
var flags = singleInstance ? Gio.ApplicationFlags.HandlesOpen : Gio.ApplicationFlags.NonUnique;
var app = Adw.Application.New (PintaCore.ApplicationId, flags);

// For macOS, use bindtextdomain() to override the location for libadwaita's translations
// since the libraries are relocated into the .app package. This can be done for other libraries
Expand Down Expand Up @@ -129,6 +136,16 @@ private static void OpenMainWindow (int threads, IEnumerable<string> files, bool
}
};

// Handle file opening in existing instance when single-instance mode is enabled
if (singleInstance) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing on macOS the single-instance mode didn't seem to work, and multiple instances were launched. I'm not sure if this is a GTK limitation ..
Which platform(s) were you testing on?

Copy link
Copy Markdown
Author

@bv-saketha-rama bv-saketha-rama Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it on linux system. I will check it again if I made any mistake.

app.OnOpen += (_, args) => {
main_window.Activate ();
foreach (var file in args.Files) {
PintaCore.Workspace.OpenFile (file);
}
};
}

// Run with a SynchronizationContext to integrate async methods with GLib.MainLoop.
app.RunWithSynchronizationContext (null);
}
Expand Down
1 change: 1 addition & 0 deletions Pinta/SettingNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ internal static class SettingNames
internal const string TOOLBOX_SHOWN = "toolbox-shown";
internal const string LAST_DIALOG_DIRECTORY = "last-dialog-directory";
internal const string LAST_SELECTED_TOOL = "last-selected-tool";
internal const string SINGLE_INSTANCE_MODE = "single-instance-mode";
}
Loading