-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
198 lines (168 loc) · 5.94 KB
/
MainWindow.xaml.cs
File metadata and controls
198 lines (168 loc) · 5.94 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using EdGo.EdgoClient;
namespace EdGo
{
/// <summary>
/// Логика взаимодействия для MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private Client client = Client.instance;
private bool started = false;
public System.Windows.Forms.NotifyIcon trayIcon; //Icon for system tray.
public MainWindow()
{
InitializeComponent();
//Create tray icon and setup initial settings for it
trayIcon = new System.Windows.Forms.NotifyIcon();
trayIcon.Icon = Properties.Resources.stoped;
trayIcon.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info; //Shows tip on systim tray icon with caugtion about continuing working.
trayIcon.BalloonTipText = "ED-GO Client still work in tray and continue tracking your flight journal!";
trayIcon.BalloonTipTitle = "I am track your logs!";
trayIcon.DoubleClick += ToggleMinimizeState; //Handle double click at tray icon
trayIcon.Visible = false;
trayIcon.ContextMenu = new System.Windows.Forms.ContextMenu();
trayIcon.ContextMenu.MenuItems.Add("Open screenshots folder", OpenScreenshotFolder);
trayIcon.ContextMenu.MenuItems.Add("Open journals folder", OpenJournalsFolder);
trayIcon.ContextMenu.MenuItems.Add("-");
trayIcon.ContextMenu.MenuItems.Add("Exit", Window_Closed);
if (Properties.Settings.Default.StartMinimized)
{
WindowState = WindowState.Minimized;
trayIcon.Visible = true;
this.Visibility = Visibility.Hidden;
}
TextLogger.instance.output = textOut;
AppDispatcher.instance.mWin = this;
AppDispatcher.instance.process();
if (Properties.Settings.Default.AutoStartProc) AppDispatcher.instance.pressStart();
}
private void OpenScreenshotFolder(object sender, EventArgs e)
{
String ScreenshotPath = Properties.Settings.Default.ScreenshotPath;
if (ScreenshotPath.Equals("Default") || ScreenshotPath.Length == 0)
ScreenshotPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures) + "\\Frontier Developments\\Elite Dangerous\\";
Process.Start(@ScreenshotPath);
}
private void OpenJournalsFolder(object sender, EventArgs e)
{
string homeDir = Environment.ExpandEnvironmentVariables("%USERPROFILE%") + "\\Saved Games\\Frontier Developments\\Elite Dangerous\\";
Process.Start(@homeDir);
}
// Toggle state between Normal and Minimized when double click at trayIcon.
private void ToggleMinimizeState(object sender, EventArgs e)
{
bool isMinimized = this.WindowState == WindowState.Minimized;
if (isMinimized)
{
Show();
WindowState = WindowState.Normal;
trayIcon.Visible = false;
}
}
//Event for window state chenged, it added in MainWindow.xaml
private void Window_StateChanged(object sender, EventArgs e)
{
if (this.WindowState == WindowState.Minimized)
{
trayIcon.Visible = true;
trayIcon.ShowBalloonTip(3000);
this.Hide();
}
else
{
Show();
WindowState = WindowState.Normal;
trayIcon.Visible = false;
}
}
private void edgoSettings_Click(object sender, RoutedEventArgs e)
{
AppDispatcher.instance.showClientSettings();
}
private void start()
{
IDictionary<string, string> startInfo = client.getLastInfo();
if (startInfo != null) {
foreach (string key in startInfo.Keys)
{
Console.WriteLine(key + "=>" + startInfo[key]);
}
}
}
private void startStop(bool state)
{
started = state;
if (started)
{
buttonProcess.Content = "Stop";
//start();
}
else
{
buttonProcess.Content = "Start";
}
}
private void buttonProcess_Click(object sender, RoutedEventArgs e)
{
//startStop(!started);
AppDispatcher.instance.pressStart();
}
public void showStopButton()
{
buttonProcess.Content = "Stop";
}
public void showStartButton()
{
buttonProcess.Content = "Start";
}
public void setStartStopState(bool state = true)
{
buttonProcess.IsEnabled = state;
buttonCompanion.IsEnabled = state;
}
private void textOut_TextChanged(object sender, TextChangedEventArgs e)
{
textOut.ScrollToEnd();
}
public bool showNewPilotDialog(String name)
{
bool result = true;
string message = "New pilot name \"" + name + "\"\nIs new E:D account?";
string caption = "Found unused pilot name!!!";
MessageBoxButton buttons = MessageBoxButton.YesNo;
MessageBoxImage icon = MessageBoxImage.Question;
MessageBoxResult defaultResult = MessageBoxResult.Yes;
result = MessageBox.Show(message, caption, buttons, icon, defaultResult).Equals(defaultResult);
return result;
}
private void Window_Closed(object sender, EventArgs e)
{
//System.Windows.Application.Current.Exit();
System.Environment.Exit(1);
}
private void buttonCompanion_Click(object sender, RoutedEventArgs e)
{
AppDispatcher.instance.showCompanionWindow();
}
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}
}
}