Files
AmiReel/Services/RenderNotifier.cs
T
klevze a590904e89 Add video preview, source crop, find-videos, and render toasts
Bring the Video tab closer to Shorts with 4K preview stills and crop
modes (none, auto, center, plus the visual editor). Settings store a
default source folder so Find videos can collect output.avi sequences.
Cap the FFmpeg log with auto-scroll, hide repeat spam, and show a
Windows notification when a video or short finishes or fails.
2026-08-16 09:20:56 +02:00

67 lines
2.3 KiB
C#

using Microsoft.Windows.AppNotifications;
using Microsoft.Windows.AppNotifications.Builder;
namespace AmiReel.Services;
/// <summary>Shows a Windows app notification when a Video or Shorts render finishes, fails, or is cancelled.</summary>
public static class RenderNotifier
{
public static void Register()
{
try
{
AppNotificationManager.Default.NotificationInvoked -= OnNotificationInvoked;
AppNotificationManager.Default.NotificationInvoked += OnNotificationInvoked;
AppNotificationManager.Default.Register();
}
catch
{
// Notifications are unavailable when the process is elevated or has no identity.
}
}
public static void ShowCompleted(bool shorts) => Show(DescribeCompleted(shorts));
public static void ShowFailed(string summary) => Show(DescribeFailed(summary));
public static void ShowCancelled() => Show(DescribeCancelled());
internal static (string Title, string Body) DescribeCompleted(bool shorts) => shorts
? ("Short complete", "The YouTube Short was rendered successfully.")
: ("Render complete", "The AmiReel render completed successfully.");
internal static (string Title, string Body) DescribeFailed(string summary)
{
string body = string.IsNullOrWhiteSpace(summary)
? "The render failed."
: summary.ReplaceLineEndings(" ");
if (body.Length > 180)
body = body[..177] + "...";
return ("Render failed", body);
}
internal static (string Title, string Body) DescribeCancelled() =>
("Render cancelled", "The render was cancelled.");
private static void Show((string Title, string Body) content)
{
try
{
AppNotification notification = new AppNotificationBuilder()
.AddText(content.Title)
.AddText(content.Body)
.BuildNotification();
AppNotificationManager.Default.Show(notification);
}
catch
{
// Show fails silently when notifications are unsupported.
}
}
private static void OnNotificationInvoked(AppNotificationManager sender, AppNotificationActivatedEventArgs args)
{
App.MainWindowInstance?.DispatcherQueue.TryEnqueue(() => App.MainWindowInstance.Activate());
}
}