implement native notifications

This commit is contained in:
Jakob 2022-12-26 16:30:02 +01:00
parent b8ec8ab7b3
commit 88e7610a46
6 changed files with 33 additions and 14 deletions

View file

@ -1,4 +1,5 @@
using System; using Microsoft.Toolkit.Uwp.Notifications;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Configuration; using System.Configuration;
using System.Data; using System.Data;
@ -6,6 +7,7 @@ using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using Windows.Foundation.Collections;
namespace EnvyUpdate namespace EnvyUpdate
{ {
@ -14,5 +16,23 @@ namespace EnvyUpdate
/// </summary> /// </summary>
public partial class App : Application public partial class App : Application
{ {
protected override void OnStartup(StartupEventArgs e)
{
// Listen to notification activation
ToastNotificationManagerCompat.OnActivated += toastArgs =>
{
// Obtain the arguments from the notification
ToastArguments args = ToastArguments.Parse(toastArgs.Argument);
// Obtain any user input (text boxes, menu selections) from the notification
ValueSet userInput = toastArgs.UserInput;
// Need to dispatch to UI thread if performing UI operations
Application.Current.Dispatcher.Invoke(delegate
{
Util.ShowMain();
});
};
}
} }
} }

View file

@ -1,4 +1,5 @@
using System; using Microsoft.Toolkit.Uwp.Notifications;
using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -295,7 +296,10 @@ namespace EnvyUpdate
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{ {
if (MessageBox.Show(Properties.Resources.exit_confirm, "", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) if (MessageBox.Show(Properties.Resources.exit_confirm, "", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
ToastNotificationManagerCompat.Uninstall();
Application.Current.Shutdown(); Application.Current.Shutdown();
}
else else
e.Cancel = true; e.Cancel = true;
} }

View file

@ -1,4 +1,4 @@
using Notifications.Wpf; using Microsoft.Toolkit.Uwp.Notifications;
namespace EnvyUpdate namespace EnvyUpdate
{ {
@ -6,14 +6,9 @@ namespace EnvyUpdate
{ {
public static void ShowDrivUpdatePopup() public static void ShowDrivUpdatePopup()
{ {
var notificationManager = new NotificationManager(); var toast = new ToastContentBuilder();
toast.AddText(Properties.Resources.update_popup_message);
notificationManager.Show(new NotificationContent toast.Show();
{
Title = "EnvyUpdate",
Message = Properties.Resources.update_popup_message,
Type = NotificationType.Information
}, onClick: Util.ShowMain);
} }
} }
} }

View file

@ -250,7 +250,7 @@ namespace EnvyUpdate.Properties {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to A new driver update is available for your graphics card. Click for more info.. /// Looks up a localized string similar to A new driver update is available for your graphics card..
/// </summary> /// </summary>
public static string update_popup_message { public static string update_popup_message {
get { get {

View file

@ -181,6 +181,6 @@
<value>Aufgrund eines Programmfehlers musste EnvyUpdate deinstalliert werden. Bitte laden Sie die neuste Version erneut manuell herunter.</value> <value>Aufgrund eines Programmfehlers musste EnvyUpdate deinstalliert werden. Bitte laden Sie die neuste Version erneut manuell herunter.</value>
</data> </data>
<data name="update_popup_message" xml:space="preserve"> <data name="update_popup_message" xml:space="preserve">
<value>Eine neue Treiberversion ist verfügbar. Hier klicken für mehr Info.</value> <value>Eine neue Treiberversion ist verfügbar.</value>
</data> </data>
</root> </root>

View file

@ -181,6 +181,6 @@
<value>EnvyUpdate must be uninstalled because of an application bug. Please download the most recent version again.</value> <value>EnvyUpdate must be uninstalled because of an application bug. Please download the most recent version again.</value>
</data> </data>
<data name="update_popup_message" xml:space="preserve"> <data name="update_popup_message" xml:space="preserve">
<value>A new driver update is available for your graphics card. Click for more info.</value> <value>A new driver update is available for your graphics card.</value>
</data> </data>
</root> </root>