-
-
Notifications
You must be signed in to change notification settings - Fork 631
Expand file tree
/
Copy pathProgram.cs
More file actions
66 lines (57 loc) · 1.72 KB
/
Program.cs
File metadata and controls
66 lines (57 loc) · 1.72 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
//
// Copyright Fela Ameghino 2015-2023
//
// Distributed under the GNU General Public License v3.0. (See accompanying
// file LICENSE or copy at https://www.gnu.org/licenses/gpl-3.0.txt)
//
using System.Diagnostics;
using Windows.ApplicationModel;
namespace Telegram.Stub
{
static class Program
{
#if DEBUG
const string MUTEX_NAME = "TelegramBridgeMutexV2";
#else
const string MUTEX_NAME = "UnigramBridgeMutexV2";
#endif
private static readonly Mutex _mutex = new Mutex(true, MUTEX_NAME);
private static NotifyIcon? _context;
[STAThread]
public static void Main(string[] args)
{
AddLoopbackExemption();
if (args.Contains("/LoopbackExempt"))
{
return;
}
if (_mutex.WaitOne(0, true))
{
_context = new NotifyIcon();
_mutex.ReleaseMutex();
}
}
private static void AddLoopbackExemption()
{
var familyName = Package.Current.Id.FamilyName;
var info = new ProcessStartInfo
{
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
CreateNoWindow = true,
UseShellExecute = false,
FileName = "CheckNetIsolation.exe",
WindowStyle = ProcessWindowStyle.Hidden,
Arguments = "LoopbackExempt -a -n=" + familyName
};
try
{
Process? process = Process.Start(info);
process?.WaitForExit();
process?.Dispose();
}
catch { }
}
}
}