Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DesktopToast.Wpf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ private async Task<string> 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
};
Expand All @@ -161,6 +162,7 @@ private async Task<string> ShowInteractiveToastAsync()
ToastXml = ComposeInteractiveToast(),
ShortcutFileName = "DesktopToast.Wpf.lnk",
ShortcutTargetFilePath = Assembly.GetExecutingAssembly().Location,
MaximumDuration = TimeSpan.FromSeconds(10),
AppId = "DesktopToast.Wpf",
ActivatorId = typeof(NotificationActivator).GUID
};
Expand Down
10 changes: 8 additions & 2 deletions DesktopToast/ToastManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static async Task<ToastResult> ShowAsync(ToastRequest request)
if (document == null)
return ToastResult.Invalid;

return await ShowBaseAsync(document, request.AppId);
return await ShowBaseAsync(document, request.AppId, request.MaximumDuration);
}

/// <summary>
Expand Down Expand Up @@ -331,11 +331,17 @@ private static async Task CheckInstallShortcut(ToastRequest request)
/// </summary>
/// <param name="document">Toast document</param>
/// <param name="appId">AppUserModelID</param>
/// <param name="maximumDuration">Optional maximum duration</param>
/// <returns>Result of showing a toast</returns>
private static async Task<ToastResult> ShowBaseAsync(XmlDocument document, string appId)
private static async Task<ToastResult> 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<ToastResult>();

TypedEventHandler<ToastNotification, object> activated = (sender, e) =>
Expand Down
5 changes: 5 additions & 0 deletions DesktopToast/ToastRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ public string ShortcutIconFilePath
[DataMember]
public TimeSpan WaitingDuration { get; set; }

/// <summary>
/// Maximum toast display duration (optional)
/// </summary>
public TimeSpan MaximumDuration { get; set; }

#endregion

#region Internal Property
Expand Down