-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
71 lines (63 loc) · 2.1 KB
/
Program.cs
File metadata and controls
71 lines (63 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Net;
using System.Net.Sockets;
using Avalonia;
namespace LoupixDeck;
sealed class Program
{
#if !WINDOWS
private const string SocketPath = "/tmp/loupixdeck_app.sock";
private static Socket _listenerSocket;
#else
private const string MutexName = "LoupixDeck_Mutex";
private static bool _mutexOwned;
private static Mutex _instanceMutex;
#endif
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args)
{
#if !WINDOWS
{
if (File.Exists(SocketPath))
{
try
{
using var client = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
client.Connect(new UnixDomainSocketEndPoint(SocketPath));
Console.WriteLine("Already running.");
return;
}
catch (SocketException)
{
File.Delete(SocketPath);
}
}
_listenerSocket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
_listenerSocket.Bind(new UnixDomainSocketEndPoint(SocketPath));
_listenerSocket.Listen(1);
AppDomain.CurrentDomain.ProcessExit += (_, _) =>
{
_listenerSocket.Close();
File.Delete(SocketPath);
};
}
#else
_instanceMutex = new Mutex(true, MutexName, out _mutexOwned);
if (!_mutexOwned)
{
Console.WriteLine("Already running.");
return;
}
#endif
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
}