-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
335 lines (288 loc) · 11.8 KB
/
MainWindow.xaml.cs
File metadata and controls
335 lines (288 loc) · 11.8 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
using System;
using System.Linq;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using System.Diagnostics;
using WinUI_V3.Pages;
using System.Threading.Tasks;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace WinUI_V3
{
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
Title = "Proxxi";
ExtendsContentIntoTitleBar = true;
SetTitleBar(TitleBarArea);
// Set up the window with fixed size
var windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(this);
var windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle);
var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
// Get the display size
var displayArea = Microsoft.UI.Windowing.DisplayArea.GetFromWindowId(windowId, Microsoft.UI.Windowing.DisplayAreaFallback.Primary);
var workAreaSize = displayArea.WorkArea;
// Calculate appropriate window size
// Default size for standard display
int defaultWidth = 1020;
int defaultHeight = 1000;
// Calculate appropriate size based on screen resolution
// For smaller displays, scale down but keep a minimum size
int minWidth = 720;
int minHeight = 700;
// If screen is smaller than 1280x720, scale down proportionally
double widthScale = Math.Min(1.0, (double)workAreaSize.Width / 1280);
double heightScale = Math.Min(1.0, (double)workAreaSize.Height / 800);
double scale = Math.Min(widthScale, heightScale);
// Calculate adjusted size (with minimum constraints)
int adjustedWidth = Math.Max(minWidth, (int)(defaultWidth * scale));
int adjustedHeight = Math.Max(minHeight, (int)(defaultHeight * scale));
// Resize window to appropriate size
appWindow.Resize(new Windows.Graphics.SizeInt32 { Width = adjustedWidth, Height = adjustedHeight });
// Allow user to resize the window
var presenter = appWindow.Presenter as Microsoft.UI.Windowing.OverlappedPresenter;
if (presenter != null)
{
presenter.IsResizable = true;
presenter.IsMaximizable = true;
}
// Set up navigation
NavView.SelectionChanged += NavView_SelectionChanged;
// Navigate to the first page and select the first item
ContentFrame.Navigate(typeof(TargetsPage));
NavView.SelectedItem = NavView.MenuItems[0]; // Select the first item by default
// Handle coffee button image loading errors
var coffeeButtonContent = CoffeeButton.Content as Grid;
var image = coffeeButtonContent?.Children.OfType<Image>().FirstOrDefault();
image?.RegisterPropertyChangedCallback(
Image.SourceProperty, (s, e) =>
{
try
{
var img = s as Image;
if (img != null && img.Source == null)
{
// Image failed to load, show fallback icon
if (FallbackIcon != null)
FallbackIcon.Visibility = Visibility.Visible;
}
}
catch (Exception ex)
{
Debug.WriteLine($"Error handling coffee icon: {ex.Message}");
// Ensure fallback icon is visible
if (FallbackIcon != null)
FallbackIcon.Visibility = Visibility.Visible;
}
});
}
private void NavView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
if (args.IsSettingsSelected)
return;
var selectedItem = args.SelectedItem as NavigationViewItem;
if (selectedItem != null)
{
var tag = selectedItem.Tag?.ToString();
switch (tag)
{
case "targets":
ContentFrame.Navigate(typeof(TargetsPage));
break;
case "settings":
ContentFrame.Navigate(typeof(SettingsPage));
break;
case "info":
ContentFrame.Navigate(typeof(InfoPage));
break;
}
}
}
private void NavView_PaneClosing(NavigationView sender, NavigationViewPaneClosingEventArgs args)
{
// Update layout for closed pane - content now takes full width
UpdateContentMargins();
}
private void NavView_PaneOpening(NavigationView sender, object args)
{
// Update layout for open pane
UpdateContentMargins();
}
private void UpdateContentMargins()
{
// WinUI's NavigationView handles margins automatically
}
private async void CoffeeButton_Click(object sender, RoutedEventArgs e)
{
try
{
await ShowCoffeeDialog();
}
catch (Exception ex)
{
Debug.WriteLine($"Error showing coffee dialog: {ex.Message}");
}
}
private async Task ShowCoffeeDialog()
{
var coffeeDialog = new ContentDialog
{
Title = "Support me",
XamlRoot = this.Content.XamlRoot,
PrimaryButtonText = "Donate",
SecondaryButtonText = "Activate License Key",
CloseButtonText = "Cancel",
DefaultButton = ContentDialogButton.Primary
};
var content = new StackPanel
{
Spacing = 16,
Margin = new Thickness(0, 12, 0, 0)
};
content.Children.Add(new TextBlock
{
Text = "Thank you for considering a donation! Your support helps maintain and improve Proxxi.",
TextWrapping = TextWrapping.Wrap
});
var perksPanel = new StackPanel
{
Spacing = 8,
Margin = new Thickness(0, 8, 0, 12)
};
perksPanel.Children.Add(new TextBlock
{
Text = "Supporters receive:",
FontWeight = Microsoft.UI.Text.FontWeights.SemiBold
});
var perksList = new StackPanel { Spacing = 4 };
var perks = new string[]
{
"Nothing"
};
foreach (var perk in perks)
{
var perkItem = new StackPanel
{
Orientation = Orientation.Horizontal,
Spacing = 8
};
perkItem.Children.Add(new SymbolIcon
{
Symbol = Symbol.Accept,
Foreground = new SolidColorBrush(Microsoft.UI.Colors.Green)
});
perkItem.Children.Add(new TextBlock
{
Text = perk,
TextWrapping = TextWrapping.Wrap
});
perksList.Children.Add(perkItem);
}
perksPanel.Children.Add(perksList);
content.Children.Add(perksPanel);
coffeeDialog.Content = content;
var result = await coffeeDialog.ShowAsync();
if (result == ContentDialogResult.Primary)
{
LaunchDonationPage();
}
else if (result == ContentDialogResult.Secondary)
{
await ShowLicenseKeyDialog();
}
}
private void LaunchDonationPage()
{
try
{
var startInfo = new ProcessStartInfo
{
FileName = "https://buymeacoffee.com/SalamiSimon",
UseShellExecute = true
};
Process.Start(startInfo);
}
catch (Exception ex)
{
Debug.WriteLine($"Error launching donation page: {ex.Message}");
}
}
private async Task ShowLicenseKeyDialog()
{
try
{
// Create the license key input dialog
var licenseDialog = new ContentDialog
{
Title = "Enter License Key",
XamlRoot = this.Content.XamlRoot,
PrimaryButtonText = "Activate",
CloseButtonText = "Cancel"
};
// Create content for the dialog
var content = new StackPanel
{
Spacing = 16,
Margin = new Thickness(0, 12, 0, 0)
};
// Add explanation
content.Children.Add(new TextBlock
{
Text = "Enter your license key received after donation:",
TextWrapping = TextWrapping.Wrap
});
// Add license key input box
var licenseKeyBox = new TextBox
{
PlaceholderText = "XXXX-XXXX-XXXX-XXXX",
HorizontalAlignment = HorizontalAlignment.Stretch,
Margin = new Thickness(0, 8, 0, 0)
};
content.Children.Add(licenseKeyBox);
// Set the content
licenseDialog.Content = content;
// Show the dialog and get result
var result = await licenseDialog.ShowAsync();
// Handle the result
if (result == ContentDialogResult.Primary)
{
string licenseKey = licenseKeyBox.Text?.Trim() ?? "";
if (!string.IsNullOrEmpty(licenseKey))
{
// In a real app, you would validate the license key here
// For now, just pretend it worked
await ShowThankYouMessage();
}
}
}
catch (Exception ex)
{
Debug.WriteLine($"Error showing license key dialog: {ex.Message}");
}
}
private async Task ShowThankYouMessage()
{
try
{
var thankYouDialog = new ContentDialog
{
Title = "Thank You!",
Content = "Your license has been activated. Thank you for supporting Proxxi!",
CloseButtonText = "OK",
XamlRoot = this.Content.XamlRoot
};
await thankYouDialog.ShowAsync();
}
catch (Exception ex)
{
Debug.WriteLine($"Error showing thank you dialog: {ex.Message}");
}
}
}
}