diff --git a/DisplayMagician/DesktopNotificationActivator.cs b/DisplayMagician/DesktopNotificationActivator.cs index 10af164..9465146 100644 --- a/DisplayMagician/DesktopNotificationActivator.cs +++ b/DisplayMagician/DesktopNotificationActivator.cs @@ -7,7 +7,9 @@ using DesktopNotifications; using static DesktopNotifications.NotificationActivator; using System.Runtime.InteropServices; using System.Text; -using System.Threading.Tasks; +using System.Windows.Threading; +using Microsoft.QueryStringDotNET; +using System.Windows.Forms; namespace DisplayMagician { @@ -19,15 +21,15 @@ namespace DisplayMagician { public override void OnActivated(string invokedArgs, NotificationUserInput userInput, string appUserModelId) { - /*Application.Current.Dispatcher.Invoke(delegate + Dispatcher.CurrentDispatcher.Invoke(delegate { // Tapping on the top-level header launches with empty args - if (arguments.Length == 0) + /*if (arguments.Length == 0) { // Perform a normal launch OpenWindowIfNeeded(); return; - } + }*/ // Parse the query string (using NuGet package QueryString.NET) QueryString args = QueryString.Parse(invokedArgs); @@ -36,23 +38,25 @@ namespace DisplayMagician switch (args["action"]) { // Open the image - case "viewImage": + case "open": - // The URL retrieved from the toast args + MessageBox.Show("User just asked to open DisplayMagician"); + /*// The URL retrieved from the toast args string imageUrl = args["imageUrl"]; // Make sure we have a window open and in foreground OpenWindowIfNeeded(); // And then show the image - (App.Current.Windows[0] as MainWindow).ShowImage(imageUrl); + (App.Current.Windows[0] as MainWindow).ShowImage(imageUrl);*/ break; // Background: Quick reply to the conversation - case "reply": + case "exit": - // Get the response the user typed + MessageBox.Show("User just asked to exit DisplayMagician"); + /*// Get the response the user typed string msg = userInput["tbReply"]; // And send this message @@ -62,11 +66,31 @@ namespace DisplayMagician if (App.Current.Windows.Count == 0) { Application.Current.Shutdown(); - } + }*/ break; + + case "stop": + + MessageBox.Show("User just asked DisplayMagician to stop monitoring the game"); + /*// Get the response the user typed + string msg = userInput["tbReply"]; + + // And send this message + SendMessage(msg); + + // If there's no windows open, exit the app + if (App.Current.Windows.Count == 0) + { + Application.Current.Shutdown(); + }*/ + + break; + + default: + break; } - });*/ + }); } private void OpenWindowIfNeeded() diff --git a/DisplayMagician/Program.cs b/DisplayMagician/Program.cs index 61dfa0d..6d4285a 100644 --- a/DisplayMagician/Program.cs +++ b/DisplayMagician/Program.cs @@ -237,6 +237,9 @@ namespace DisplayMagician { Console.WriteLine($"Program/Main exception: Unable to execute application - {ex.Message}: {ex.StackTrace} - {ex.InnerException}"); } + // Remove all the notifications we have set as they don't matter now! + DesktopNotificationManagerCompat.History.Clear(); + // Shutdown NLog NLog.LogManager.Shutdown(); diff --git a/DisplayMagician/UIForms/MainForm.cs b/DisplayMagician/UIForms/MainForm.cs index 160c11f..a79bbcb 100644 --- a/DisplayMagician/UIForms/MainForm.cs +++ b/DisplayMagician/UIForms/MainForm.cs @@ -41,10 +41,6 @@ namespace DisplayMagician.UIForms notifyIcon.ContextMenuStrip = mainContextMenuStrip; RefreshNotifyIconMenus(); - /*WaitingForm testform = new WaitingForm(); - testform.Owner = this; - testform.Show();*/ - if (Program.AppProgramSettings.MinimiseOnStart) { // Make the form minimised on start @@ -52,6 +48,25 @@ namespace DisplayMagician.UIForms // Hide the application to notification area when the form is closed allowClose = false; cb_minimise_notification_area.Checked = true; + // Change the exit_button text to say 'Close' + btn_exit.Text = "&Close"; + + // Remind the user that DisplayMagician is running the in background + // Construct the toast content + ToastContentBuilder tcBuilder = new ToastContentBuilder() + .AddToastActivationInfo("notify=minimiseStart", ToastActivationType.Foreground) + .AddText("DisplayMagician has started minimised!", hintMaxLines: 1) + .AddButton("Open DisplayMagician", ToastActivationType.Background, "notify=minimiseStart&action=open"); + ToastContent toastContent = tcBuilder.Content; + // Make sure to use Windows.Data.Xml.Dom + var doc = new XmlDocument(); + doc.LoadXml(toastContent.GetContent()); + + // And create the toast notification + var toast = new ToastNotification(doc); + + // And then show it + DesktopNotifications.DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); } else { @@ -71,7 +86,7 @@ namespace DisplayMagician.UIForms else if (formToOpen is ShortcutLibraryForm) { var shortcutLibraryForm = new ShortcutLibraryForm(); - shortcutLibraryForm.ShowDialog(this); + shortcutLibraryForm.ShowDialog(this); } } @@ -98,6 +113,26 @@ namespace DisplayMagician.UIForms private void btn_exit_Click(object sender, EventArgs e) { + if (cb_minimise_notification_area.Checked) + { + // Tell the user that + // Construct the toast content + ToastContentBuilder tcBuilder = new ToastContentBuilder() + .AddToastActivationInfo("notify=stillRunning", ToastActivationType.Foreground) + .AddText("DisplayMagician is still running!", hintMaxLines: 1) + .AddText("You can exit the application by right-clicking on the DisplayMagician icon in the notification area of the taskbar.") + .AddButton("Exit DisplayMagician", ToastActivationType.Background, "notify=stillRunning&action=exit"); + ToastContent toastContent = tcBuilder.Content; + // Make sure to use Windows.Data.Xml.Dom + var doc = new XmlDocument(); + doc.LoadXml(toastContent.GetContent()); + + // And create the toast notification + var toast = new ToastNotification(doc); + + // And then show it + DesktopNotifications.DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); + } Application.Exit(); } @@ -264,6 +299,8 @@ namespace DisplayMagician.UIForms allowClose = false; // Enable the MinimiseOnStart setting Program.AppProgramSettings.MinimiseOnStart = true; + // Change the exit_button text to say 'Close' + btn_exit.Text = "&Close"; } else { @@ -273,6 +310,9 @@ namespace DisplayMagician.UIForms allowClose = true; // Disable the MinimiseOnStart setting Program.AppProgramSettings.MinimiseOnStart = false; + // Change the exit_button text to say 'Exit' + btn_exit.Text = "&Exit"; + } } @@ -399,66 +439,13 @@ namespace DisplayMagician.UIForms private void btn_toast_Click(object sender, EventArgs e) { - // Construct the toast content - ToastContent toastContent = new ToastContent() - { - // Arguments when the user taps body of toast - Launch = "DisplayMagician_Notification", - - Visual = new ToastVisual() - { - BindingGeneric = new ToastBindingGeneric() - { - Children = - { - new AdaptiveText() - { - Text = "Hello from DisplayMagician!" - }, - }, - - } - }, -/* - Actions = new ToastActionsCustom() - { - Inputs = - { - new ToastTextBox("tbReply") - { - PlaceholderContent = "Type a response" - } - }, - - Buttons = - { - // Note that there's no reason to specify background activation, since our COM - // activator decides whether to process in background or launch foreground window - new ToastButton("Reply", new QueryString() - { - { "action", "reply" }, - { "conversationId", conversationId.ToString() } - - }.ToString()), - - new ToastButton("Like", new QueryString() - { - { "action", "like" }, - { "conversationId", conversationId.ToString() } - - }.ToString()), - - new ToastButton("View", new QueryString() - { - { "action", "viewImage" }, - { "imageUrl", image } - - }.ToString()) - } - }*/ - }; - + ToastContentBuilder tcBuilder = new ToastContentBuilder() + .AddToastActivationInfo("notify=runningGame", ToastActivationType.Foreground) + .AddText("This is the notification title!", hintMaxLines: 1) + .AddText("This is the description") + .AddButton("Stop", ToastActivationType.Background, "notify=runningGame&action=stop"); + ToastContent toastContent = tcBuilder.Content; // Make sure to use Windows.Data.Xml.Dom var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); diff --git a/DisplayMagician/UIForms/MainForm.resx b/DisplayMagician/UIForms/MainForm.resx index 85aef8f..d66daf8 100644 --- a/DisplayMagician/UIForms/MainForm.resx +++ b/DisplayMagician/UIForms/MainForm.resx @@ -10834,7 +10834,7 @@ NoControl - 220, 235 + 220, 237 343, 22 @@ -10873,7 +10873,7 @@ NoControl - 234, 351 + 234, 354 332, 20 @@ -10906,7 +10906,7 @@ Microsoft Sans Serif, 9.75pt - 12, 352 + 12, 355 25, 16 @@ -10942,7 +10942,7 @@ Microsoft Sans Serif, 21.75pt - 212, 162 + 212, 164 360, 50 @@ -10975,7 +10975,7 @@ NoControl - 700, 348 + 700, 351 75, 23 @@ -63404,10 +63404,10 @@ 218, 22 - Close DisplayMagician + Exit DisplayMagician - 219, 126 + 219, 148 Text