From c1ab49fb1d6234012c74dba6024d92c70d4d18fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Kaan=20K=C3=B6se?= Date: Sun, 5 Apr 2026 02:19:11 +0200 Subject: [PATCH] Snooze with background activation. --- Wino.Mail.WinUI/Program.cs | 41 +++++++++++++++++-- .../Services/NotificationBuilder.cs | 8 ++-- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/Wino.Mail.WinUI/Program.cs b/Wino.Mail.WinUI/Program.cs index c6247346..76b264be 100644 --- a/Wino.Mail.WinUI/Program.cs +++ b/Wino.Mail.WinUI/Program.cs @@ -3,9 +3,13 @@ using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; +using Microsoft.Toolkit.Uwp.Notifications; using Microsoft.UI.Dispatching; using Microsoft.UI.Xaml; +using Microsoft.Windows.AppNotifications; using Microsoft.Windows.AppLifecycle; +using Wino.Core.Domain; +using Wino.Core.Domain.Enums; namespace Wino.Mail.WinUI; @@ -177,9 +181,11 @@ public class Program CWMO_DEFAULT, INFINITE, 1, [redirectEventHandle], out uint handleIndex); - // Bring the window to the foreground - Process process = Process.GetProcessById((int)keyInstance.ProcessId); - SetForegroundWindow(process.MainWindowHandle); + if (ShouldBringWindowToForegroundAfterRedirection(args)) + { + Process process = Process.GetProcessById((int)keyInstance.ProcessId); + SetForegroundWindow(process.MainWindowHandle); + } } private static void OnActivated(object? sender, AppActivationArguments args) @@ -191,4 +197,33 @@ public class Program app.HandleRedirectedActivation(args); } } + + private static bool ShouldBringWindowToForegroundAfterRedirection(AppActivationArguments args) + { + if (args.Kind != ExtendedActivationKind.AppNotification || + args.Data is not AppNotificationActivatedEventArgs toastArgs) + { + return true; + } + + var toastArguments = ToastArguments.Parse(toastArgs.Argument); + + if (toastArguments.TryGetValue(Constants.ToastStoreUpdateActionKey, out string storeUpdateAction) && + storeUpdateAction == Constants.ToastStoreUpdateActionInstall) + { + return true; + } + + if (toastArguments.TryGetValue(Constants.ToastCalendarActionKey, out string calendarAction)) + { + return calendarAction == Constants.ToastCalendarNavigateAction; + } + + if (toastArguments.TryGetValue(Constants.ToastActionKey, out MailOperation mailAction)) + { + return mailAction == MailOperation.Navigate; + } + + return true; + } } diff --git a/Wino.Mail.WinUI/Services/NotificationBuilder.cs b/Wino.Mail.WinUI/Services/NotificationBuilder.cs index b30b6d12..529b872f 100644 --- a/Wino.Mail.WinUI/Services/NotificationBuilder.cs +++ b/Wino.Mail.WinUI/Services/NotificationBuilder.cs @@ -350,12 +350,12 @@ public class NotificationBuilder : INotificationBuilder var snoozeButton = new ToastButton() .SetContent(Translator.CalendarReminder_SnoozeAction) .SetImageUri(GetNotificationIconUri("calendar-snooze")) - .SetBackgroundActivation(); - - builder.AddButton(snoozeButton) .AddArgument(Constants.ToastCalendarActionKey, Constants.ToastCalendarSnoozeAction) .AddArgument(Constants.ToastCalendarItemIdKey, calendarItem.Id.ToString()) - .AddArgument(Constants.ToastModeKey, Constants.ToastModeCalendar); + .AddArgument(Constants.ToastModeKey, Constants.ToastModeCalendar) + .SetBackgroundActivation(); + + builder.AddButton(snoozeButton); } builder.AddButton(new ToastButton()