-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMainWindow.xaml.cs
165 lines (142 loc) · 5.84 KB
/
MainWindow.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
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
using Microsoft.UI.Composition.SystemBackdrops;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using WinDurango.UI.Dialogs;
using WinDurango.UI.Pages;
using WinDurango.UI.Settings;
using WinDurango.UI.Utils;
namespace WinDurango.UI
{
public sealed partial class MainWindow : Window
{
public readonly string AppName = "WinDurango";
public static readonly UiConfig Settings = App.Settings;
public AppsListPage AppsListPage;
public SettingsPage SettingsPage;
public AboutPage AboutPage;
public AppMode currentMode;
public enum AppMode
{
DESKTOP,
CONTROLLER
}
private void NavigationInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
{
if (args.IsSettingsInvoked)
{
if (contentFrame.Content?.GetType() != typeof(SettingsPage))
{
_ = contentFrame.Navigate(typeof(SettingsPage));
}
}
else if (args.InvokedItemContainer is NavigationViewItem item)
{
string tag = item.Tag.ToString();
Type pageType = tag switch
{
"AppsListPage" => typeof(AppsListPage),
"AboutPage" => typeof(AboutPage),
"NotImplementedPage" => typeof(NotImplementedPage),
_ => typeof(NotImplementedPage)
};
if (contentFrame.Content?.GetType() != pageType && contentFrame.Navigate(pageType) && contentFrame.Content is AppsListPage appsList)
AppsListPage = appsList;
}
}
public void ReloadAppList()
{
_ = AppsListPage?.InitAppListAsync();
}
public void LoadSettings()
{
ExtendsContentIntoTitleBar = Settings.Settings.Theme != UiConfigData.ThemeSetting.System;
switch (Settings.Settings.Theme)
{
case UiConfigData.ThemeSetting.Mica:
this.SystemBackdrop = new MicaBackdrop() { Kind = MicaKind.Base };
break;
case UiConfigData.ThemeSetting.MicaAlt:
this.SystemBackdrop = new MicaBackdrop() { Kind = MicaKind.BaseAlt };
break;
case UiConfigData.ThemeSetting.Fluent:
this.SystemBackdrop = new DesktopAcrylicBackdrop();
break;
case UiConfigData.ThemeSetting.FluentThin:
this.SystemBackdrop = new DesktopAcrylicBackdrop();
break;
case UiConfigData.ThemeSetting.System:
this.SystemBackdrop = null;
break;
}
}
private void OnNavigate(object sender, NavigatingCancelEventArgs e)
{
Logger.WriteDebug($"Switching to page {e.SourcePageType.Name}");
}
public MainWindow()
{
Closed += App.OnClosed;
Title = AppName;
AppWindow.SetIcon("ms-appx:///Assets/icon.ico");
this.Activate();
LoadSettings();
this.InitializeComponent();
contentFrame.Navigating += OnNavigate;
contentFrame.Navigate(typeof(AppsListPage));
AppsListPage = (AppsListPage)contentFrame.Content;
}
private async void appTitleBar_Loaded(object sender, RoutedEventArgs e)
{
Dictionary<string, string> missing = [];
if (String.IsNullOrEmpty(FSHelper.FindFileOnPath("vcruntime140d.dll")))
missing.Add("Microsoft Visual C++ Redistributable", null);
if (App.Settings.Settings.ShowDevNotice)
{
var devNotice = new NoticeDialog("This UI is very early in development, and mainly developed by a C# learner... There WILL be bugs, and some things will NOT work...\n\nDevelopers, check Readme.md in the repo for the todolist.", "Important");
await devNotice.ShowAsync();
// We only show this notification once from now on
Settings.Set("ShowDevNotice", false);
Settings.Save();
}
if (missing.Count != 0)
{
// todo: properly provide download link
string notice = $"You are missing the following dependencies, which may be required to run some packages.\n";
foreach (KeyValuePair<string, string> ms in missing)
{
notice += $"\n - {ms.Key}";
}
var missingNotice = new NoticeDialog(notice, "Missing dependencies");
await missingNotice.ShowAsync();
}
if (ExtendsContentIntoTitleBar)
{
SetupTitleBar();
}
}
private void appTitleBar_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (ExtendsContentIntoTitleBar)
{
SetupTitleBar();
}
}
public void SwitchMode(AppMode mode)
{
currentMode = mode;
navView.PaneDisplayMode = currentMode == AppMode.CONTROLLER ? NavigationViewPaneDisplayMode.Top : NavigationViewPaneDisplayMode.LeftCompact;
}
private void SetupTitleBar()
{
AppWindowTitleBar titleBar = AppWindow.TitleBar;
double scaleAdjustment = appTitleBar.XamlRoot.RasterizationScale;
rightPaddingColumn.Width = new GridLength(titleBar.RightInset / scaleAdjustment);
leftPaddingColumn.Width = new GridLength(titleBar.LeftInset / scaleAdjustment);
}
}
}