Skip to content

Commit e151084

Browse files
authored
build release for Microsoft Hack2gether (#17)
* refactor * refactor * refactor * resharp * resharp. * refactor * gui * Add dummy MenuBar to FileManagerPage, WorkbenchPage. Minor tweaks. * Remove german strings temporarily * refactor * refactor * gui * enhance gui; add Graph adapters * connect to graph * connect to graph * connect to graph * gui * Add Microsoft365Page * Add Microsoft365Page * refactoring. gui. * refactor. code quality.
1 parent 3bd9f56 commit e151084

24 files changed

Lines changed: 672 additions & 303 deletions

src/electrifier/Activation/AppNotificationActivationHandler.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using electrifier.Contracts.Services;
2+
using electrifier.ViewModels;
23
using Microsoft.UI.Dispatching;
34
using Microsoft.UI.Xaml;
45
using Microsoft.Windows.AppLifecycle;
6+
using Microsoft.Windows.AppNotifications;
57

68
namespace electrifier.Activation;
79

@@ -25,18 +27,18 @@ protected async override Task HandleInternalAsync(LaunchActivatedEventArgs args)
2527
{
2628
// TODO: Handle notification activations.
2729

28-
//// // Access the AppNotificationActivatedEventArgs.
29-
//// var activatedEventArgs = (AppNotificationActivatedEventArgs)AppInstance.GetCurrent().GetActivatedEventArgs().Data;
30-
31-
//// // Navigate to a specific page based on the notification arguments.
32-
//// if (_notificationService.ParseArguments(activatedEventArgs.Argument)["action"] == "Settings")
33-
//// {
34-
//// // Queue navigation with low priority to allow the UI to initialize.
35-
//// App.MainWindow.DispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, () =>
36-
//// {
37-
//// _navigationService.NavigateTo(typeof(SettingsViewModel).FullName!);
38-
//// });
39-
//// }
30+
// Access the AppNotificationActivatedEventArgs.
31+
var activatedEventArgs = (AppNotificationActivatedEventArgs)AppInstance.GetCurrent().GetActivatedEventArgs().Data;
32+
33+
// Navigate to a specific page based on the notification arguments.
34+
if (_notificationService.ParseArguments(activatedEventArgs.Argument)["action"] == "Settings")
35+
{
36+
// Queue navigation with low priority to allow the UI to initialize.
37+
App.MainWindow.DispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, () =>
38+
{
39+
_navigationService.NavigateTo(typeof(SettingsViewModel).FullName!);
40+
});
41+
}
4042

4143
App.MainWindow.DispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, () =>
4244
{

src/electrifier/App.xaml.cs

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@
33
//#define DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
44

55

6-
using CommunityToolkit.WinUI;
76
using electrifier.Activation;
87
using electrifier.Contracts.Services;
98
using electrifier.Models.Configuration.Global;
10-
using electrifier.Models;
119
using electrifier.Services;
1210
using electrifier.ViewModels;
1311
using electrifier.Views;
14-
using Microsoft.AppCenter.Analytics;
15-
using Microsoft.AppCenter.Crashes;
16-
using Microsoft.AppCenter;
1712
using Microsoft.Extensions.DependencyInjection;
1813
using Microsoft.Extensions.Hosting;
1914
using Microsoft.UI.Xaml;
2015
using System.Diagnostics;
2116
using System.Text;
17+
using Microsoft.UI.Xaml.Controls;
18+
using WinRT;
2219

2320
namespace electrifier;
2421

@@ -63,8 +60,6 @@ public App()
6360
{
6461
InitializeComponent();
6562

66-
//UnhandledException += App_UnhandledException;
67-
6863
Host = Microsoft.Extensions.Hosting.Host.
6964
CreateDefaultBuilder().
7065
UseContentRoot(AppContext.BaseDirectory).
@@ -77,16 +72,15 @@ public App()
7772
services.AddTransient<IActivationHandler, AppNotificationActivationHandler>();
7873

7974
// Services
75+
services.AddSingleton<IActivationService, ActivationService>();
8076
services.AddSingleton<IAppNotificationService, AppNotificationService>();
8177
services.AddSingleton<ILocalSettingsService, LocalSettingsService>();
78+
services.AddSingleton<INavigationService, NavigationService>();
79+
services.AddSingleton<IPageService, PageService>();
8280
services.AddSingleton<IThemeSelectorService, ThemeSelectorService>();
8381
services.AddTransient<INavigationViewService, NavigationViewService>();
8482
services.AddTransient<IWebViewService, WebViewService>();
8583

86-
services.AddSingleton<IActivationService, ActivationService>();
87-
services.AddSingleton<INavigationService, NavigationService>();
88-
services.AddSingleton<IPageService, PageService>();
89-
9084
// Core Services
9185
services.AddSingleton<IFileService, FileService>();
9286

@@ -97,6 +91,8 @@ public App()
9791
services.AddTransient<DevicesViewModel>();
9892
services.AddTransient<FileManagerPage>();
9993
services.AddTransient<FileManagerViewModel>();
94+
services.AddTransient<Microsoft365Page>();
95+
services.AddTransient<Microsoft365ViewModel>();
10096
services.AddTransient<NetworkDevicesPage>();
10197
services.AddTransient<NetworkDevicesViewModel>();
10298
services.AddTransient<SettingsPage>();
@@ -119,7 +115,7 @@ public App()
119115
GetService<IAppNotificationService>()?
120116
.Initialize();
121117

122-
UnhandledException += App_UnhandledException;
118+
// UnhandledException += App_UnhandledException;
123119
}
124120

125121
//private void App_StartAppCenter()
@@ -128,11 +124,22 @@ public App()
128124
//}
129125

130126

131-
private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs args)
127+
// private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs args)
128+
// {
129+
// App_UnhandledException(sender, args, false);
130+
// }
131+
132+
protected async override void OnLaunched(LaunchActivatedEventArgs args)
132133
{
133-
App_UnhandledException(sender, args, false);
134+
base.OnLaunched(args);
135+
136+
//GetService<IAppNotificationService>()?
137+
// .Show(string.Format("AppNotificationSamplePayload".GetLocalized(), AppContext.BaseDirectory));
138+
139+
await GetService<IActivationService>()?.ActivateAsync(args);
134140
}
135141

142+
136143
/// <summary>
137144
/// Log and handle exceptions as appropriate.
138145
///
@@ -154,43 +161,41 @@ private void App_UnhandledException(
154161
Microsoft.UI.Xaml.UnhandledExceptionEventArgs args,
155162
bool itIsComplicated)
156163
{
164+
// TODO: Try to make an backup of current configuration and mark as "dirty".
165+
// TODO: Log and handle exceptions as appropriate.
166+
157167
try
158168
{
159169
StringBuilder sb = new();
170+
sb.Append($"{nameof(App_UnhandledException)}:");
171+
sb.Append($"Sender: {sender.As<string>()}");
172+
sb.Append($"args: {args.As<string>()}");
160173

161-
sb.AppendJoin("\n", "Exception happened!", "line 1", "line 2");
162-
163-
// TODO: Try to make an backup of current configuration and mark as "dirty".
164-
// TODO: Log and handle exceptions as appropriate.
165-
166-
//guru?.ThrowGuruMeditation(sender, args);
174+
// TODO: guru?.ThrowGuruMeditation(sender, args);
167175

168176
/*
169-
170-
private async void ShowDialog_Click(object sender, RoutedEventArgs e)
171-
{
172-
ContentDialog dialog = new ContentDialog();
173-
174-
// XamlRoot must be set in the case of a ContentDialog running in a Desktop app
175-
dialog.XamlRoot = this.XamlRoot;
176-
dialog.Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style;
177-
dialog.Title = "Save your work?";
178-
dialog.PrimaryButtonText = "Save";
179-
dialog.SecondaryButtonText = "Don't Save";
180-
dialog.CloseButtonText = "Cancel";
181-
dialog.DefaultButton = ContentDialogButton.Primary;
182-
dialog.Content = new ContentDialogContent();
183-
184-
var result = await dialog.ShowAsync();
185-
}
186-
187-
*/
188-
189-
177+
private async void ShowDialog_Click(object sender, RoutedEventArgs e)
178+
{
179+
ContentDialog dialog = new ContentDialog();
180+
181+
// XamlRoot must be set in the case of a ContentDialog running in a Desktop app
182+
dialog.XamlRoot = this.XamlRoot;
183+
dialog.Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style;
184+
dialog.Title = "Save your work?";
185+
dialog.PrimaryButtonText = "Save";
186+
dialog.SecondaryButtonText = "Don't Save";
187+
dialog.CloseButtonText = "Cancel";
188+
dialog.DefaultButton = ContentDialogButton.Primary;
189+
dialog.Content = new ContentDialogContent();
190+
var result = await dialog.ShowAsync();
191+
}
192+
*/
193+
194+
195+
// sb.AppendJoin("\n", "Exception happened!", "line 1", "line 2");
190196
// if (args is not null)
191197
// {
192198
// // TODO: Exception happened!
193-
//
194199
// args.Handled = true;
195200
// }
196201
// else
@@ -201,29 +206,34 @@ private async void ShowDialog_Click(object sender, RoutedEventArgs e)
201206
// {
202207
// args?.Handled = true;
203208
// }
204-
// }
205209
}
206210
catch (Exception ex)
207211
{
208212
var dummy = ex.ToString();
209-
210-
211213
// TODO: Log inner exception
212214
}
213215
finally
214216
{
215-
args.Handled = true; // TODO: For test purposes only
216-
//args.Handled = !itIsComplicated; // TODO
217+
args.Handled = true; // TODO: For test purposes only
218+
//args.Handled = !itIsComplicated; // TODO
217219
}
218220
}
219221

220-
protected async override void OnLaunched(LaunchActivatedEventArgs args)
222+
private async void ShowDialog_Click(object sender, RoutedEventArgs e)
221223
{
222-
base.OnLaunched(args);
223-
224-
//GetService<IAppNotificationService>()?
225-
// .Show(string.Format("AppNotificationSamplePayload".GetLocalized(), AppContext.BaseDirectory));
226-
227-
await GetService<IActivationService>()?.ActivateAsync(args);
224+
var dialog = new ContentDialog
225+
{
226+
CloseButtonText = "Cancel",
227+
DefaultButton = ContentDialogButton.Primary,
228+
PrimaryButtonText = "Save all changes made.",
229+
SecondaryButtonText = "Don't save changes. Any progress made will be lost.",
230+
Style= Application.Current.Resources["DefaultContentDialogStyle"] as Style,
231+
Title = "Save your work?",
232+
};
233+
234+
// XamlRoot must be set in the case of a ContentDialog running in a Desktop app
235+
//dialog.XamlRoot = this.XamlRoot;
236+
//dialog.Content = new ContentDialogContent();
237+
_ = await dialog.ShowAsync();
228238
}
229239
}

src/electrifier/Behaviors/NavigationViewHeaderBehavior.cs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using electrifier.Contracts.Services;
1+
using System.Diagnostics;
2+
using electrifier.Contracts.Services;
23

34
using Microsoft.UI.Xaml;
45
using Microsoft.UI.Xaml.Controls;
@@ -25,14 +26,22 @@ public object DefaultHeader
2526
}
2627

2728
public static readonly DependencyProperty DefaultHeaderProperty =
28-
DependencyProperty.Register("DefaultHeader", typeof(object), typeof(NavigationViewHeaderBehavior), new PropertyMetadata(null, (d, e) => _current!.UpdateHeader()));
29+
DependencyProperty.Register(nameof(DefaultHeader), typeof(object), typeof(NavigationViewHeaderBehavior), new PropertyMetadata(null, (d, e) => _current!.UpdateHeader()));
2930

3031
public static NavigationViewHeaderMode GetHeaderMode(Page item) => (NavigationViewHeaderMode)item.GetValue(HeaderModeProperty);
3132

3233
public static void SetHeaderMode(Page item, NavigationViewHeaderMode value) => item.SetValue(HeaderModeProperty, value);
3334

3435
public static readonly DependencyProperty HeaderModeProperty =
35-
DependencyProperty.RegisterAttached("HeaderMode", typeof(bool), typeof(NavigationViewHeaderBehavior), new PropertyMetadata(NavigationViewHeaderMode.Always, (d, e) => _current!.UpdateHeader()));
36+
DependencyProperty.RegisterAttached(
37+
"HeaderMode",
38+
typeof(bool),
39+
typeof(NavigationViewHeaderBehavior),
40+
new PropertyMetadata(
41+
NavigationViewHeaderMode.Always,
42+
(
43+
d,
44+
e) => _current!.UpdateHeader()));
3645

3746
public static object GetHeaderContext(Page item) => item.GetValue(HeaderContextProperty);
3847

@@ -53,6 +62,9 @@ protected override void OnAttached()
5362
base.OnAttached();
5463

5564
var navigationService = App.GetService<INavigationService>();
65+
66+
Debug.Assert(navigationService != null, nameof(navigationService) + " != null");
67+
5668
navigationService.Navigated += OnNavigated;
5769

5870
_current = this;
@@ -63,17 +75,25 @@ protected override void OnDetaching()
6375
base.OnDetaching();
6476

6577
var navigationService = App.GetService<INavigationService>();
78+
79+
Debug.Assert(navigationService != null, nameof(navigationService) + " != null");
80+
6681
navigationService.Navigated -= OnNavigated;
6782
}
6883

6984
private void OnNavigated(object sender, NavigationEventArgs e)
7085
{
71-
if (sender is Frame frame && frame.Content is Page page)
86+
switch (sender)
7287
{
73-
_currentPage = page;
74-
75-
UpdateHeader();
76-
UpdateHeaderTemplate();
88+
case Frame { Content: Page page }:
89+
_currentPage = page;
90+
91+
UpdateHeader();
92+
UpdateHeaderTemplate();
93+
break;
94+
default:
95+
Debug.Fail("sender unknown");
96+
break;
7797
}
7898
}
7999

src/electrifier/Contracts/Services/ILocalSettingsService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using electrifier.Models;
2-
using electrifier.Models.Configuration.Global;
1+
using electrifier.Models.Configuration.Global;
32

43
namespace electrifier.Contracts.Services;
54

File renamed without changes.
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
{
2-
"profiles": {
3-
"electrifier (Package)": {
4-
"commandName": "MsixPackage"
5-
},
6-
"electrifier (Unpackaged)": {
7-
"commandName": "Project"
8-
}
1+
{
2+
"profiles": {
3+
"electrifier (Package)": {
4+
"commandName": "MsixPackage",
5+
"nativeDebugging": true
6+
},
7+
"electrifier (Unpackaged)": {
8+
"commandName": "Project"
99
}
10-
}
10+
}
11+
}

src/electrifier/Services/LocalSettingsService.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using electrifier.Contracts.Services;
22
using electrifier.Helpers;
3-
using electrifier.Models;
43
using Microsoft.Extensions.Options;
54
using Windows.Storage;
65
using electrifier.Models.Configuration.Global;

0 commit comments

Comments
 (0)