using System.Drawing; using System.Windows.Forms; namespace Futonizer.Services; /// /// Fires native Windows notifications (via a transient tray icon's balloon /// tip) to let the user know processing has finished, even if the app /// window isn't focused. /// public static class NotificationService { public static void ShowToast(string title, string message) { try { Icon icon; try { icon = System.Drawing.Icon.ExtractAssociatedIcon(Environment.ProcessPath!) ?? SystemIcons.Application; } catch { icon = SystemIcons.Application; } var notifyIcon = new NotifyIcon { Icon = icon, Visible = true, BalloonTipTitle = title, BalloonTipText = message, BalloonTipIcon = ToolTipIcon.Info, }; notifyIcon.BalloonTipClosed += (_, _) => notifyIcon.Dispose(); notifyIcon.BalloonTipClicked += (_, _) => notifyIcon.Dispose(); notifyIcon.ShowBalloonTip(5000); // Fallback in case neither event fires (e.g. notifications disabled). _ = Task.Delay(10000).ContinueWith(_ => notifyIcon.Dispose()); } catch { // Notifications are best-effort; never let a failure here affect the app. } } }