-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
71 lines (66 loc) · 2.46 KB
/
App.xaml.cs
File metadata and controls
71 lines (66 loc) · 2.46 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 Microsoft.Toolkit.Uwp.Notifications;
using System;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using TMP.NET.Modules;
namespace TMP.NET
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
///
public static class Program
{
[STAThread]
public static void Main(string[] args)
{
var proc = Process.GetCurrentProcess();
var processName = proc.ProcessName.Replace(".vshost", "");
var runningProcess = Process.GetProcesses().FirstOrDefault(x =>
(x.ProcessName == processName || x.ProcessName == proc.ProcessName || x.ProcessName == proc.ProcessName + ".vshost") && x.Id != proc.Id);
if (runningProcess == null)
{
var app = new App();
app.InitializeComponent();
var window = new MainWindow();
MainWindow.HandleParameter(args);
app.Run(window);
return;
}
if (args.Length > 0)
UnsafeNative.SendMessage(runningProcess.MainWindowHandle, string.Join(" ", args));
}
}
public partial class App : Application
{
public App() : base()
{
this.Dispatcher.UnhandledException += OnDispatcherUnhandledException;
}
void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
TMP.NET.MainWindow.log.Fatal("PROGRAM CRASH", e.Exception);
MessageBox.Show("Unhandled exception occurred: \n" + e.Exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
protected override void OnStartup(StartupEventArgs e)
{
ToastNotificationManagerCompat.OnActivated += toastArgs =>
{
ToastArguments args = ToastArguments.Parse(toastArgs.Argument);
Application.Current.Dispatcher.Invoke(delegate
{
if (args.Contains("openss"))
{
Process.Start(args.Get("openss"));
}
else if (args.Contains("openweb"))
{
string repoUrl = "https://trackmyplaytime.netlify.app/";
Process.Start(new ProcessStartInfo { FileName = repoUrl, UseShellExecute = true });
}
});
};
}
}
}