-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.xaml.cs
138 lines (134 loc) · 4.07 KB
/
App.xaml.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using LostArkMarketWatcherV2.modules;
using LostArkMarketWatcherV2.windows.login;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Threading;
using Application = System.Windows.Application;
namespace LostArkMarketWatcherV2
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class LamoWatcherApp : Application
{
private NotifyIcon? _notifyIcon;
private LogWindow? _logWindow;
private ConfigWindow? _configWindow;
private LoginWindow? _loginWindow;
public LamoLogger? logger;
public FileWatcher? fileWatcher;
protected override void OnStartup(StartupEventArgs e)
{
try
{
InitializeWindows();
InitializeSystemTrayIcon();
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
private void InitializeWindows()
{
_logWindow = new LogWindow();
logger = new LamoLogger(_logWindow);
_configWindow = new ConfigWindow();
_loginWindow = new LoginWindow();
if (LamoConfig.Instance.cookie == null)
{
_loginWindow.Show();
}
else
{
_ = CheckSession();
}
}
private void InitializeSystemTrayIcon()
{
this._notifyIcon = new System.Windows.Forms.NotifyIcon
{
Icon = new System.Drawing.Icon("Assets/Icons/favicon.ico"),
Visible = true,
ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip()
};
this._notifyIcon.ContextMenuStrip.Items.Add("Show Log", null, (sender, args) => ShowLog());
this._notifyIcon.ContextMenuStrip.Items.Add("Show Config", null, (sender, args) => ShowConfig());
this._notifyIcon.ContextMenuStrip.Items.Add("Exit", null, (sender, args) => CloseApp());
}
private void CloseApp()
{
_notifyIcon!.Visible = false;
Shutdown();
}
public void ShowLog()
{
if (_logWindow != null)
{
_logWindow.Show();
_logWindow.WindowState = WindowState.Normal;
}
}
private void ShowConfig()
{
if (_configWindow != null)
{
_configWindow.Show();
_configWindow.WindowState = WindowState.Normal;
}
}
public async Task CheckSession()
{
try
{
await LamoApi.session();
logger?.Debug("Logged in");
if (LamoConfig.Instance.open_log_on_start)
{
_logWindow!.Show();
}
if (LamoConfig.Instance.game_directory == null)
{
_configWindow!.Show();
}
else
{
fileWatcher = new FileWatcher();
}
}
catch (Exception ex)
{
logger?.Error(ex.Message.ToString());
_loginWindow!.Show();
}
}
}
public class LamoLogger(LogWindow logWindow)
{
private readonly LogWindow _logWindow = logWindow;
public void Debug(string text)
{
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
_logWindow?.debug(text);
}));
}
public void Info(string text)
{
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
_logWindow?.info(text);
}));
}
public void Error(string text)
{
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
_logWindow?.error(text);
}));
}
}
}