mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
Basic bidirectional notifications working
This commit is contained in:
parent
73f23d0e5b
commit
15386ba756
@ -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()
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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());
|
||||
|
@ -10834,7 +10834,7 @@
|
||||
<value>NoControl</value>
|
||||
</data>
|
||||
<data name="lbl_create_shortcut.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>220, 235</value>
|
||||
<value>220, 237</value>
|
||||
</data>
|
||||
<data name="lbl_create_shortcut.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>343, 22</value>
|
||||
@ -10873,7 +10873,7 @@
|
||||
<value>NoControl</value>
|
||||
</data>
|
||||
<data name="cb_minimise_notification_area.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>234, 351</value>
|
||||
<value>234, 354</value>
|
||||
</data>
|
||||
<data name="cb_minimise_notification_area.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>332, 20</value>
|
||||
@ -10906,7 +10906,7 @@
|
||||
<value>Microsoft Sans Serif, 9.75pt</value>
|
||||
</data>
|
||||
<data name="lbl_version.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>12, 352</value>
|
||||
<value>12, 355</value>
|
||||
</data>
|
||||
<data name="lbl_version.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>25, 16</value>
|
||||
@ -10942,7 +10942,7 @@
|
||||
<value>Microsoft Sans Serif, 21.75pt</value>
|
||||
</data>
|
||||
<data name="btn_setup_game_shortcuts.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>212, 162</value>
|
||||
<value>212, 164</value>
|
||||
</data>
|
||||
<data name="btn_setup_game_shortcuts.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>360, 50</value>
|
||||
@ -10975,7 +10975,7 @@
|
||||
<value>NoControl</value>
|
||||
</data>
|
||||
<data name="btn_exit.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>700, 348</value>
|
||||
<value>700, 351</value>
|
||||
</data>
|
||||
<data name="btn_exit.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>75, 23</value>
|
||||
@ -63404,10 +63404,10 @@
|
||||
<value>218, 22</value>
|
||||
</data>
|
||||
<data name="exitToolStripMenuItem.Text" xml:space="preserve">
|
||||
<value>Close DisplayMagician</value>
|
||||
<value>Exit DisplayMagician</value>
|
||||
</data>
|
||||
<data name="mainContextMenuStrip.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>219, 126</value>
|
||||
<value>219, 148</value>
|
||||
</data>
|
||||
<data name="mainContextMenuStrip.Text" xml:space="preserve">
|
||||
<value>Text</value>
|
||||
|
Loading…
Reference in New Issue
Block a user