-
Notifications
You must be signed in to change notification settings - Fork 354
feat: Add single-instance mode to prevent multiple instances #1949
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 (); | ||
| bool singleInstance = settings.GetSetting (SettingNames.SINGLE_INSTANCE_MODE, false); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ..
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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.Settingsinstead to avoid creating anotherSettingsManager(and reloading the settings from disk again)The line below uses
PintaCore.ApplicationIdso it should be safe to run the static constructors at this point