Skip to content

Commit

Permalink
Merge pull request #91 from drittich/prevent-multiple-app-instances
Browse files Browse the repository at this point in the history
Prevent multiple tray app instances from running
  • Loading branch information
anthonylavado committed Sep 24, 2023
2 parents dee4b67 + d2aebb5 commit 2b0e1d8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Jellyfin.Windows.Tray/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using System.Windows.Forms;

namespace Jellyfin.Windows.Tray
Expand All @@ -8,9 +9,17 @@ namespace Jellyfin.Windows.Tray
/// </summary>
public static class Program
{
private static Mutex _mutex;

[STAThread]
private static void Main()
{
if (IsAlreadyRunning())
{
MessageBox.Show("The Jellyfin tray application is already running.", "Info", new MessageBoxButtons { }, MessageBoxIcon.Information);
Environment.Exit(1);
}

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

Expand All @@ -20,5 +29,12 @@ private static void Main()
Application.Run(trayApplicationContext);
}
}

private static bool IsAlreadyRunning()
{
_mutex = new Mutex(true, "Jellyfin.Windows.Tray", out bool createdNew);

return !createdNew;
}
}
}

0 comments on commit 2b0e1d8

Please sign in to comment.