Restore dual mail and calendar app entries
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using Windows.ApplicationModel;
|
||||
using Wino.Core.Domain.Enums;
|
||||
|
||||
namespace Wino.Mail.WinUI.Activation;
|
||||
|
||||
internal static class AppEntryConstants
|
||||
{
|
||||
public const string MailApplicationId = "App";
|
||||
public const string CalendarApplicationId = "CalendarApp";
|
||||
public const string MailLaunchArgument = "--wino-mail";
|
||||
public const string CalendarLaunchArgument = "--wino-calendar";
|
||||
|
||||
public static string GetModeLaunchArgument(WinoApplicationMode mode)
|
||||
=> mode switch
|
||||
{
|
||||
WinoApplicationMode.Calendar => CalendarLaunchArgument,
|
||||
WinoApplicationMode.Contacts => "--mode=contacts",
|
||||
WinoApplicationMode.Settings => "--mode=settings",
|
||||
_ => MailLaunchArgument
|
||||
};
|
||||
|
||||
public static string? GetPackagedApplicationId(WinoApplicationMode mode)
|
||||
=> mode switch
|
||||
{
|
||||
WinoApplicationMode.Calendar => CalendarApplicationId,
|
||||
WinoApplicationMode.Mail => MailApplicationId,
|
||||
_ => null
|
||||
};
|
||||
|
||||
public static string GetAppUserModelId(string packageFamilyName, WinoApplicationMode mode)
|
||||
=> $"{packageFamilyName}!{GetPackagedApplicationId(mode) ?? MailApplicationId}";
|
||||
|
||||
public static string GetAppUserModelId(WinoApplicationMode mode)
|
||||
=> GetAppUserModelId(Package.Current.Id.FamilyName, mode);
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using Wino.Core.Domain.Enums;
|
||||
|
||||
namespace Wino.Mail.WinUI.Activation;
|
||||
@@ -6,87 +5,5 @@ namespace Wino.Mail.WinUI.Activation;
|
||||
internal static class AppModeActivationResolver
|
||||
{
|
||||
public static WinoApplicationMode Resolve(string? launchArguments, string? tileId, string? appId, WinoApplicationMode defaultMode = WinoApplicationMode.Mail)
|
||||
{
|
||||
if (TryResolveFromText(launchArguments, defaultMode, out var mode))
|
||||
return mode;
|
||||
|
||||
if (TryResolveFromText(tileId, defaultMode, out mode))
|
||||
return mode;
|
||||
|
||||
if (TryResolveFromText(appId, defaultMode, out mode))
|
||||
return mode;
|
||||
|
||||
return defaultMode;
|
||||
}
|
||||
|
||||
private static bool TryResolveFromText(string? value, WinoApplicationMode defaultMode, out WinoApplicationMode mode)
|
||||
{
|
||||
mode = defaultMode;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return false;
|
||||
|
||||
if (Contains(value, "--mode=toggle-default") ||
|
||||
Contains(value, "mode=toggle-default"))
|
||||
{
|
||||
mode = GetOpposite(defaultMode);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Contains(value, "wino-calendar") ||
|
||||
Contains(value, "--mode=calendar") ||
|
||||
Contains(value, "mode=calendar") ||
|
||||
Contains(value, "calendarapp") ||
|
||||
EqualsToken(value, "calendar"))
|
||||
{
|
||||
mode = WinoApplicationMode.Calendar;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Contains(value, "wino-contacts") ||
|
||||
Contains(value, "--mode=contacts") ||
|
||||
Contains(value, "mode=contacts") ||
|
||||
Contains(value, "contactsapp") ||
|
||||
EqualsToken(value, "contacts"))
|
||||
{
|
||||
mode = WinoApplicationMode.Contacts;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Contains(value, "wino-settings") ||
|
||||
Contains(value, "--mode=settings") ||
|
||||
Contains(value, "mode=settings") ||
|
||||
Contains(value, "settingsapp") ||
|
||||
EqualsToken(value, "settings"))
|
||||
{
|
||||
mode = WinoApplicationMode.Settings;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Contains(value, "wino-mail") ||
|
||||
Contains(value, "--mode=mail") ||
|
||||
Contains(value, "mode=mail") ||
|
||||
Contains(value, "mailapp") ||
|
||||
EqualsToken(value, "mail"))
|
||||
{
|
||||
mode = WinoApplicationMode.Mail;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool Contains(string source, string token)
|
||||
=> source.Contains(token, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
private static bool EqualsToken(string source, string token)
|
||||
=> string.Equals(source.Trim(), token, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
private static WinoApplicationMode GetOpposite(WinoApplicationMode defaultMode)
|
||||
=> defaultMode switch
|
||||
{
|
||||
WinoApplicationMode.Mail => WinoApplicationMode.Calendar,
|
||||
WinoApplicationMode.Calendar => WinoApplicationMode.Mail,
|
||||
_ => WinoApplicationMode.Mail
|
||||
};
|
||||
=> Wino.Core.Activation.AppModeActivationResolver.Resolve(launchArguments, tileId, appId, defaultMode);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
using Microsoft.Windows.AppNotifications;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Enums;
|
||||
|
||||
namespace Wino.Mail.WinUI.Activation;
|
||||
|
||||
internal static class ToastActivationResolver
|
||||
{
|
||||
public static bool TryParse(string? argument, out NotificationArguments toastArguments)
|
||||
{
|
||||
toastArguments = default!;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(argument))
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
var parsedArguments = NotificationArguments.Parse(argument);
|
||||
if (!ContainsKnownToastKey(parsedArguments))
|
||||
return false;
|
||||
|
||||
toastArguments = parsedArguments;
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ShouldBringToForeground(NotificationArguments toastArguments)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
private static bool ContainsKnownToastKey(NotificationArguments toastArguments)
|
||||
=> toastArguments.TryGetValue(Constants.ToastStoreUpdateActionKey, out string _) ||
|
||||
toastArguments.TryGetValue(Constants.ToastCalendarActionKey, out string _) ||
|
||||
toastArguments.TryGetValue(Constants.ToastActionKey, out string _);
|
||||
}
|
||||
Reference in New Issue
Block a user