Snooze with background activation.

This commit is contained in:
Burak Kaan Köse
2026-04-05 02:19:11 +02:00
parent 6013865fca
commit c1ab49fb1d
2 changed files with 42 additions and 7 deletions
+36 -1
View File
@@ -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,10 +181,12 @@ public class Program
CWMO_DEFAULT, INFINITE, 1,
[redirectEventHandle], out uint handleIndex);
// Bring the window to the foreground
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;
}
}
@@ -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()