diff --git a/Documentation/Settings.md b/Documentation/Settings.md index 4e22342..a3201f4 100644 --- a/Documentation/Settings.md +++ b/Documentation/Settings.md @@ -10,6 +10,7 @@ Back to [Home](https://github.com/dankrusi/WindowsVirtualDesktopHelper) |Config|Default|Description| | --- | --- | --- | +| debug.singleInstance | ``true`` | If true, the app will prevent multiple instances of the app from starting. Most users won't need to change this option. | | general.startupWithWindows | ``false`` | If true, the app will register itself with Windows to startup when Windows starts (via the registry). | | general.theme | ``"auto"`` | Can be either auto, dark or light. If set to auto, the theme is derived from the current windows theme (dark or light). | | theme.icons.disabledOpacity | ``"0.5"`` | Defines the opacity to use for icons which are disabled. | diff --git a/Source/App/Settings.cs b/Source/App/Settings.cs index 83dc61b..fffb024 100644 --- a/Source/App/Settings.cs +++ b/Source/App/Settings.cs @@ -24,10 +24,13 @@ class Settings { public static void LoadDefaults() { // Register any known default settings here + // Debug + RegisterDefault("debug.singleInstance", true, "true - only allow a single instance of the application to run (default); false - allow multiple instances (expect errors registering hotkeys)"); + // General RegisterDefault("general.startupWithWindows", false, "If true, the app will register itself with Windows to startup when Windows starts (via the registry)."); RegisterDefault("general.theme", "auto", "Can be either auto, dark or light. If set to auto, the theme is derived from the current windows theme (dark or light)."); - + // Theme RegisterDefault("theme.icons.disabledOpacity", 0.5, "Defines the opacity to use for icons which are disabled."); RegisterDefault("theme.icons.font", "Segoe UI", "Defines the font name to use for the icons (for regular numbers, characters)."); diff --git a/Source/Main.cs b/Source/Main.cs index 068c71c..575abe9 100644 --- a/Source/Main.cs +++ b/Source/Main.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using System.Windows.Forms; namespace WindowsVirtualDesktopHelper { @@ -14,10 +15,17 @@ public static void Main(string[] args) { // Load config Settings.LoadConfig(); // Start app - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - var app = new App(); - Application.Run(app.AppForm); + using (Mutex mutex = new Mutex(false, "Mutex/WindowsVirtualDesktopHelper")) { + if (Settings.GetBool("debug.singleInstance") && !mutex.WaitOne(0)) { + MessageBox.Show("WindowsVirtualDesktopHelper is already running.", "Error", MessageBoxButtons.OK); + return; + } + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + var app = new App(); + Application.Run(app.AppForm); + } } catch (Exception e) { // Global error handler Console.Error.WriteLine(e);