-
Notifications
You must be signed in to change notification settings - Fork 336
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
base: master
Are you sure you want to change the base?
feat: Add single-instance mode to prevent multiple instances #1949
Conversation
| var app = Adw.Application.New (PintaCore.ApplicationId, Gio.ApplicationFlags.NonUnique); | ||
|
|
||
| // Check if single-instance mode is enabled | ||
| var settings = new SettingsManager (); |
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.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
|
|
||
| // Check if single-instance mode is enabled | ||
| var settings = new SettingsManager (); | ||
| bool singleInstance = settings.GetSetting (SettingNames.SINGLE_INSTANCE_MODE, false); |
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 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 :)
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.
that's right
| }; | ||
|
|
||
| // Handle file opening in existing instance when single-instance mode is enabled | ||
| if (singleInstance) { |
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.
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?
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 tried it on linux system. I will check it again if I made any mistake.
Solves #1906
Changes
Added Settings Constant (SettingNames.cs)
internal const string SINGLE_INSTANCE_MODE = "single-instance-mode";Conditional Application Flags (Main.cs)
`// Check if single-instance mode is enabled
var settings = new SettingsManager ();
bool singleInstance = settings.GetSetting (SettingNames.SINGLE_INSTANCE_MODE, false);
// Use appropriate flags based on preference
var flags = singleInstance ? Gio.ApplicationFlags.HandlesOpen
: Gio.ApplicationFlags.NonUnique;
var app = Adw.Application.New (PintaCore.ApplicationId, flags);`
// Handle file opening in existing instance if (singleInstance) { app.OnOpen += (_, args) => { main_window.Activate (); foreach (var file in args.Files) PintaCore.Workspace.OpenFile (file); }; }Behaviour
<setting name="single-instance-mode" type="System.Boolean">True</setting>