-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.axaml.cs
48 lines (42 loc) · 1.39 KB
/
App.axaml.cs
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.Diagnostics;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using urlhandler.Helpers;
using urlhandler.Views;
using urlhandler.ViewModels;
namespace urlhandler;
public class App : Application {
public override void Initialize() {
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted() {
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
var mw = new MainWindow();
WindowHelper.MainWindowViewModel = new MainWindowViewModel(mw, desktop.Args ?? []);
mw.DataContext = WindowHelper.MainWindowViewModel;
desktop.Startup += DesktopOnStartup;
desktop.MainWindow = mw;
desktop.MainWindow.DataContext = mw.DataContext;
WindowHelper.MainWindow = mw;
}
base.OnFrameworkInitializationCompleted();
}
private void DesktopOnStartup(object? sender, ControlledApplicationLifetimeStartupEventArgs e) {
var currentProcess = Process.GetCurrentProcess();
if (Process.GetProcessesByName("ChemLocalLink").Length > 0) {
var processes = Process.GetProcessesByName("ChemLocalLink");
foreach (Process process in processes) {
if (process.Id != currentProcess.Id) {
try {
process.Kill();
}
catch (Exception) {
// ignored
}
}
}
}
}
}