-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
48 lines (42 loc) · 1.39 KB
/
Copy pathProgram.cs
File metadata and controls
48 lines (42 loc) · 1.39 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
using System;
using System.IO;
using System.IO.Pipes;
using System.Threading;
using Avalonia;
using Avalonia.WebView.Desktop;
namespace SimpleMarkdownViewer;
class Program
{
private const string MutexName = "SimpleMarkdownViewer_SingleInstance";
private const string PipeName = "SimpleMarkdownViewer_Pipe";
[STAThread]
public static void Main(string[] args)
{
using var mutex = new Mutex(true, MutexName, out bool createdNew);
if (!createdNew)
{
// Another instance is already running - send file path via named pipe
if (args.Length > 0 && File.Exists(args[0]))
{
try
{
using var client = new NamedPipeClientStream(".", PipeName, PipeDirection.Out);
client.Connect(3000);
using var writer = new StreamWriter(client);
writer.WriteLine(args[0]);
writer.Flush();
}
catch { /* If pipe fails, just exit */ }
}
return;
}
// First instance - start the app
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace()
.UseDesktopWebView();
}