private async void Button_Click(object sender, RoutedEventArgs e) { Debug.Write("button pressed"); MediaElement mediaElement = new MediaElement(); // Get the listener UserNotificationListenerAccessStatus accessStatus = await listener.RequestAccessAsync(); if (accessStatus != UserNotificationListenerAccessStatus.Allowed) { return; } // Get the toast notifications NotificationsProcessor.GetNotificationsAndProcessThem(); //Request / check background task access via BackgroundExecutionManager.RequestAccessAsync var requestStatus = await Windows.ApplicationModel.Background.BackgroundExecutionManager.RequestAccessAsync(); if (requestStatus != BackgroundAccessStatus.AlwaysAllowed) { } ApplicationData.Current.LocalSettings.Values["python"] = this.PythonPath.Text; ApplicationData.Current.LocalSettings.Values["command"] = this.NotificationPath.Text; // If background task isn't registered yet if (!BackgroundTaskRegistration.AllTasks. Any(i => i.Value.Name.Equals("UserNotificationChanged"))) { // Specify the background task var builder = new BackgroundTaskBuilder() { Name = "UserNotificationChanged" }; // Set the trigger for Listener, listening to Toast Notifications builder.SetTrigger(new UserNotificationChangedTrigger(NotificationKinds.Toast)); // Register the task builder.Register(); } button.IsEnabled = false; Python.IsEnabled = false; NotificationPythonFile.IsEnabled = false; }
internal static async Task SyncNotifications() { NotificationsProcessor.GetNotificationsAndProcessThem(); }