public void Uninstall() { try { // Useful utility to allow users to remove HandBrake from Windows Settings. this.notifier = null; ToastNotificationManagerCompat.Uninstall(); isInitialised = false; } catch (Exception exc) { Debug.WriteLine(exc); } }
private void Setup() { bool encode = this.userSettingService.GetUserSetting <bool>(UserSettingConstants.NotifyOnEncodeDone); bool queue = this.userSettingService.GetUserSetting <bool>(UserSettingConstants.NotifyOnQueueDone); if (encode || queue) { if (isInitialised) { return; } this.notifier = ToastNotificationManagerCompat.CreateToastNotifier(); isInitialised = true; ToastNotificationManagerCompat.OnActivated += toastArgs => { // Obtain the arguments from the notification ToastArguments args = ToastArguments.Parse(toastArgs.Argument); // Remove any notifications that are clicked System.Collections.Generic.KeyValuePair <string, string> tag = args.FirstOrDefault(); if (!string.IsNullOrEmpty(tag.Value)) { try { ToastNotificationManagerCompat.History.Remove(tag.Value); } catch (Exception exc) { Debug.WriteLine(exc); } } // Need to dispatch to UI thread if performing UI operations Application.Current.Dispatcher.Invoke(delegate { Window w = Application.Current.MainWindow; if (w != null) { w.WindowState = WindowState.Normal; w.BringIntoView(); } }); }; } }
/// <summary> /// </summary> /// <param name="applicationContext"></param> public WindowsNotificationManager(WindowsApplicationContext?applicationContext = null) { _applicationContext = applicationContext ?? WindowsApplicationContext.FromCurrentProcess(); _launchActionPromise = new TaskCompletionSource <string>(); if (ToastNotificationManagerCompat.WasCurrentProcessToastActivated()) { ToastNotificationManagerCompat.OnActivated += OnAppActivated; if (_launchActionPromise.Task.Wait(LaunchNotificationWaitMs)) { LaunchActionId = _launchActionPromise.Task.Result; } } _toastNotifier = ToastNotificationManagerCompat.CreateToastNotifier(); _notifications = new Dictionary <ToastNotification, Notification>(); }