mirror of
https://github.com/Stone-Red-Code/ClipCMD.git
synced 2026-09-04 00:46:10 +02:00
Use guid instead of app name to create the mutex
This commit is contained in:
+16
-7
@@ -1,4 +1,5 @@
|
|||||||
using System.Threading;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
||||||
namespace ClipCMD;
|
namespace ClipCMD;
|
||||||
@@ -8,20 +9,28 @@ namespace ClipCMD;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class App : Application
|
public partial class App : Application
|
||||||
{
|
{
|
||||||
Mutex mutex;
|
public const string AppName = "ClipCMD";
|
||||||
|
|
||||||
|
public const string AppGuid = "68d780d4-b946-4154-8815-e4632e5ec5d8";
|
||||||
|
|
||||||
|
private Mutex? mutex;
|
||||||
|
|
||||||
protected override void OnStartup(StartupEventArgs e)
|
protected override void OnStartup(StartupEventArgs e)
|
||||||
{
|
{
|
||||||
const string appName = "ClipCMD";
|
mutex = new Mutex(true, AppGuid, out bool createdNew);
|
||||||
|
|
||||||
mutex = new Mutex(true, appName, out bool createdNew);
|
|
||||||
|
|
||||||
if (!createdNew)
|
if (!createdNew)
|
||||||
{
|
{
|
||||||
//App is already running! Exiting the application
|
//App is already running! Exiting the application
|
||||||
_ = MessageBox.Show($"Another instance of {appName} already running!", $"{appName} is already running!", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
_ = MessageBox.Show($"Another instance of {AppName} already running!", $"{AppName} is already running!", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
||||||
Current.Shutdown();
|
Current.Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
base.OnStartup(e);
|
Exit += CloseHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void CloseHandler(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
mutex?.ReleaseMutex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Management.Automation;
|
using System.Management.Automation;
|
||||||
using System.Management.Automation.Language;
|
using System.Management.Automation.Language;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -45,7 +46,7 @@ public partial class MainWindow : Window
|
|||||||
|
|
||||||
notifyIcon.Click += NotifyIcon_Click;
|
notifyIcon.Click += NotifyIcon_Click;
|
||||||
|
|
||||||
string applicationDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
string applicationDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "StoneRed");
|
||||||
string folderPath = Path.Combine(applicationDataPath, "ClipCMD");
|
string folderPath = Path.Combine(applicationDataPath, "ClipCMD");
|
||||||
|
|
||||||
if (!Directory.Exists(folderPath))
|
if (!Directory.Exists(folderPath))
|
||||||
@@ -69,6 +70,12 @@ public partial class MainWindow : Window
|
|||||||
DataContext = this;
|
DataContext = this;
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
Title = $"{App.AppName} - Dev {Assembly.GetExecutingAssembly().GetName().Version}";
|
||||||
|
#else
|
||||||
|
Title = $"{App.AppName} - {Assembly.GetExecutingAssembly().GetName().Version}";
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnSourceInitialized(EventArgs e)
|
protected override void OnSourceInitialized(EventArgs e)
|
||||||
|
|||||||
Reference in New Issue
Block a user