commit 5d0cbfb94aff7338a90b59cf4fcf8eb1ac1a5e6d parent ea9abbc68ef978a230f6cd1cf630e9cb9019dcef Author: Minerva_juppiter <ryouturn@gmail.com> Date: Thu, 4 Apr 2024 19:40:41 +0900 通知が残っていた場合に起動直後に削除するプログラムを追加 Diffstat:
| M | App.xaml.cs | | | 36 | ++++++++++++++++++++++++++++++++++-- |
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/App.xaml.cs b/App.xaml.cs @@ -1,4 +1,8 @@ -using System.Windows; +using System.Diagnostics; +using System.Windows; +using Windows.ApplicationModel; +using Windows.UI.Notifications; +using Windows.UI.Notifications.Management; namespace BusynessNotification { @@ -11,7 +15,7 @@ namespace BusynessNotification public partial class App : System.Windows.Application { - protected override void OnStartup(StartupEventArgs e) + protected override async void OnStartup(StartupEventArgs e) { base.OnStartup(e); ///ここにスタートアップ時の処理を記述 @@ -24,6 +28,34 @@ namespace BusynessNotification }; notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(NotifyIcon_Click); + ///通知の中にBusynessNotificationからの通知が残っていれば削除する + ///get the listener + UserNotificationListener userNotificationListener = UserNotificationListener.Current; + ///and request access the the user's notification + UserNotificationListenerAccessStatus userNotificationListenerAccessStatus = await userNotificationListener.RequestAccessAsync(); + if(userNotificationListenerAccessStatus != UserNotificationListenerAccessStatus.Allowed) + { + + } + ///get the toast notification + IReadOnlyList<UserNotification> notifs = await userNotificationListener.GetNotificationsAsync(NotificationKinds.Toast); + int i = 0; + + Debug.WriteLine("length of notification is " + notifs.Count); + Debug.WriteLine("notifis is " + notifs[0]); + + while (notifs.Count >= i+1) + { + Debug.WriteLine("notifiChech is called"); + UserNotification notification = notifs[i]; + Debug.WriteLine(notification.AppInfo.DisplayInfo.DisplayName); + if(notification.AppInfo.DisplayInfo.DisplayName == "BusynessNotification") + { + userNotificationListener.RemoveNotification(notification.Id); + } + i++; + } + ObserveUseage observeUseage = new(); observeUseage.Controller(); }