diff --git a/DesktopToast.Wpf/MainWindow.xaml.cs b/DesktopToast.Wpf/MainWindow.xaml.cs index a2c0482..647ddc3 100644 --- a/DesktopToast.Wpf/MainWindow.xaml.cs +++ b/DesktopToast.Wpf/MainWindow.xaml.cs @@ -138,6 +138,7 @@ private async Task ShowToastAsync() ToastLogoFilePath = string.Format("file:///{0}", Path.GetFullPath("Resources/toast128.png")), ShortcutFileName = "DesktopToast.Wpf.lnk", ShortcutTargetFilePath = Assembly.GetExecutingAssembly().Location, + MaximumDuration = TimeSpan.FromSeconds(10), AppId = "DesktopToast.Wpf", ActivatorId = typeof(NotificationActivator).GUID // For Action Center of Windows 10 }; @@ -161,6 +162,7 @@ private async Task ShowInteractiveToastAsync() ToastXml = ComposeInteractiveToast(), ShortcutFileName = "DesktopToast.Wpf.lnk", ShortcutTargetFilePath = Assembly.GetExecutingAssembly().Location, + MaximumDuration = TimeSpan.FromSeconds(10), AppId = "DesktopToast.Wpf", ActivatorId = typeof(NotificationActivator).GUID }; diff --git a/DesktopToast/ToastManager.cs b/DesktopToast/ToastManager.cs index feb9b20..3ff04aa 100644 --- a/DesktopToast/ToastManager.cs +++ b/DesktopToast/ToastManager.cs @@ -38,7 +38,7 @@ public static async Task ShowAsync(ToastRequest request) if (document == null) return ToastResult.Invalid; - return await ShowBaseAsync(document, request.AppId); + return await ShowBaseAsync(document, request.AppId, request.MaximumDuration); } /// @@ -331,11 +331,17 @@ private static async Task CheckInstallShortcut(ToastRequest request) /// /// Toast document /// AppUserModelID + /// Optional maximum duration /// Result of showing a toast - private static async Task ShowBaseAsync(XmlDocument document, string appId) + private static async Task ShowBaseAsync(XmlDocument document, string appId, TimeSpan maximumDuration = default(TimeSpan)) { // Create a toast and prepare to handle toast events. var toast = new ToastNotification(document); + if (maximumDuration != default(TimeSpan)) + { + toast.ExpirationTime = DateTime.Now + maximumDuration; + } + var tcs = new TaskCompletionSource(); TypedEventHandler activated = (sender, e) => diff --git a/DesktopToast/ToastRequest.cs b/DesktopToast/ToastRequest.cs index 4ededbb..1aeae3a 100644 --- a/DesktopToast/ToastRequest.cs +++ b/DesktopToast/ToastRequest.cs @@ -148,6 +148,11 @@ public string ShortcutIconFilePath [DataMember] public TimeSpan WaitingDuration { get; set; } + /// + /// Maximum toast display duration (optional) + /// + public TimeSpan MaximumDuration { get; set; } + #endregion #region Internal Property