-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
67 lines (58 loc) · 1.69 KB
/
App.xaml.cs
File metadata and controls
67 lines (58 loc) · 1.69 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
using System.Drawing;
using WinForms = System.Windows.Forms;
using System.Windows;
using Application = System.Windows.Application;
using MessageBox = System.Windows.MessageBox;
namespace RedLight;
public partial class App : Application
{
private WinForms.NotifyIcon? _notifyIcon;
private MainWindow? _mainWindow;
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
ThemeManager.ApplySystemTheme();
try
{
NativeMethods.MagInitialize();
}
catch (Exception ex)
{
MessageBox.Show($"Failed to initialize Magnification API: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Shutdown();
return;
}
_mainWindow = new MainWindow();
_notifyIcon = new WinForms.NotifyIcon();
using var iconStream = typeof(App).Assembly
.GetManifestResourceStream("RedLightForWindows.icon.ico");
_notifyIcon.Icon = new Icon(iconStream!);
_notifyIcon.Text = "Red Light";
_notifyIcon.Visible = true;
_notifyIcon.MouseClick += (s, args) =>
{
if (_mainWindow!.IsVisible)
_mainWindow.HidePopup();
else
_mainWindow.ShowPopup();
};
}
protected override void OnExit(ExitEventArgs e)
{
if (_notifyIcon != null)
{
_notifyIcon.Dispose();
_notifyIcon = null;
}
try
{
NativeMethods.ResetColorEffect();
NativeMethods.MagUninitialize();
}
catch
{
// Suppress errors on exit
}
base.OnExit(e);
}
}