Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit78ff6da

Browse files
authored
feat: add support for notifications (#85)
Adds support for OS notifications, which I'll use to show errors handling URIs in a subsequent PR.[Screen Recording 2025-05-01 145532.mp4 <span>(uploaded via Graphite)</span> <img src="https://app.graphite.dev/api/v1/graphite/video/thumbnail/tCz4CxRU9jhAJ7zH8RTi/f838fb8a-6815-48a7-bd52-63d6a06ce742.mp4" />](https://app.graphite.dev/media/video/tCz4CxRU9jhAJ7zH8RTi/f838fb8a-6815-48a7-bd52-63d6a06ce742.mp4)
1 parent2495779 commit78ff6da

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

‎App/App.xaml.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
usingMicrosoft.Windows.AppLifecycle;
2222
usingSerilog;
2323
usingLaunchActivatedEventArgs=Microsoft.UI.Xaml.LaunchActivatedEventArgs;
24+
usingMicrosoft.Windows.AppNotifications;
2425

2526
namespaceCoder.Desktop.App;
2627

@@ -70,6 +71,7 @@ public App()
7071
services.AddOptions<MutagenControllerConfig>()
7172
.Bind(builder.Configuration.GetSection(MutagenControllerConfigSection));
7273
services.AddSingleton<ISyncSessionController,MutagenController>();
74+
services.AddSingleton<IUserNotifier,UserNotifier>();
7375

7476
// SignInWindow views and view models
7577
services.AddTransient<SignInViewModel>();
@@ -188,10 +190,14 @@ public void OnActivated(object? sender, AppActivationArguments args)
188190
_logger.LogWarning("URI activation with null data");
189191
return;
190192
}
191-
192193
HandleURIActivation(protoArgs.Uri);
193194
break;
194195

196+
caseExtendedActivationKind.AppNotification:
197+
varnotificationArgs=(args.DataasAppNotificationActivatedEventArgs)!;
198+
HandleNotification(null,notificationArgs);
199+
break;
200+
195201
default:
196202
_logger.LogWarning("activation for {kind}, which is unhandled",args.Kind);
197203
break;
@@ -204,6 +210,12 @@ public void HandleURIActivation(Uri uri)
204210
_logger.LogInformation("handling URI activation for {path}",uri.AbsolutePath);
205211
}
206212

213+
publicvoidHandleNotification(AppNotificationManager?sender,AppNotificationActivatedEventArgsargs)
214+
{
215+
// right now, we don't do anything other than log
216+
_logger.LogInformation("handled notification activation");
217+
}
218+
207219
privatestaticvoidAddDefaultConfig(IConfigurationBuilderbuilder)
208220
{
209221
varlogPath=Path.Combine(

‎App/Program.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
usingMicrosoft.UI.Dispatching;
66
usingMicrosoft.UI.Xaml;
77
usingMicrosoft.Windows.AppLifecycle;
8+
usingMicrosoft.Windows.AppNotifications;
89
usingWinRT;
910

1011
namespaceCoder.Desktop.App;
@@ -28,9 +29,9 @@ private static void Main(string[] args)
2829
{
2930
ComWrappersSupport.InitializeComWrappers();
3031
varmainInstance=GetMainInstance();
32+
varactivationArgs=AppInstance.GetCurrent().GetActivatedEventArgs();
3133
if(!mainInstance.IsCurrent)
3234
{
33-
varactivationArgs=AppInstance.GetCurrent().GetActivatedEventArgs();
3435
mainInstance.RedirectActivationToAsync(activationArgs).AsTask().Wait();
3536
return;
3637
}
@@ -58,6 +59,15 @@ private static void Main(string[] args)
5859

5960
// redirections via RedirectActivationToAsync above get routed to the App
6061
mainInstance.Activated+=app.OnActivated;
62+
varnotificationManager=AppNotificationManager.Default;
63+
notificationManager.NotificationInvoked+=app.HandleNotification;
64+
notificationManager.Register();
65+
if(activationArgs.Kind!=ExtendedActivationKind.Launch)
66+
{
67+
// this means we were activated without having already launched, so handle
68+
// the activation as well.
69+
app.OnActivated(null,activationArgs);
70+
}
6171
});
6272
}
6373
catch(Exceptione)

‎App/Services/UserNotifier.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
usingSystem;
2+
usingSystem.Threading.Tasks;
3+
usingMicrosoft.Windows.AppNotifications;
4+
usingMicrosoft.Windows.AppNotifications.Builder;
5+
6+
namespaceCoder.Desktop.App.Services;
7+
8+
publicinterfaceIUserNotifier:IAsyncDisposable
9+
{
10+
publicTaskShowErrorNotification(stringtitle,stringmessage);
11+
}
12+
13+
publicclassUserNotifier:IUserNotifier
14+
{
15+
privatereadonlyAppNotificationManager_notificationManager=AppNotificationManager.Default;
16+
17+
publicValueTaskDisposeAsync()
18+
{
19+
returnValueTask.CompletedTask;
20+
}
21+
22+
publicTaskShowErrorNotification(stringtitle,stringmessage)
23+
{
24+
varbuilder=newAppNotificationBuilder().AddText(title).AddText(message);
25+
_notificationManager.Show(builder.BuildNotification());
26+
returnTask.CompletedTask;
27+
}
28+
}
29+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp