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 static DesktopNotifications.NotificationActivator;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Windows.Threading;
|
||||||
|
using Microsoft.QueryStringDotNET;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace DisplayMagician
|
namespace DisplayMagician
|
||||||
{
|
{
|
||||||
@ -19,15 +21,15 @@ namespace DisplayMagician
|
|||||||
{
|
{
|
||||||
public override void OnActivated(string invokedArgs, NotificationUserInput userInput, string appUserModelId)
|
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
|
// Tapping on the top-level header launches with empty args
|
||||||
if (arguments.Length == 0)
|
/*if (arguments.Length == 0)
|
||||||
{
|
{
|
||||||
// Perform a normal launch
|
// Perform a normal launch
|
||||||
OpenWindowIfNeeded();
|
OpenWindowIfNeeded();
|
||||||
return;
|
return;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// Parse the query string (using NuGet package QueryString.NET)
|
// Parse the query string (using NuGet package QueryString.NET)
|
||||||
QueryString args = QueryString.Parse(invokedArgs);
|
QueryString args = QueryString.Parse(invokedArgs);
|
||||||
@ -36,23 +38,25 @@ namespace DisplayMagician
|
|||||||
switch (args["action"])
|
switch (args["action"])
|
||||||
{
|
{
|
||||||
// Open the image
|
// 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"];
|
string imageUrl = args["imageUrl"];
|
||||||
|
|
||||||
// Make sure we have a window open and in foreground
|
// Make sure we have a window open and in foreground
|
||||||
OpenWindowIfNeeded();
|
OpenWindowIfNeeded();
|
||||||
|
|
||||||
// And then show the image
|
// And then show the image
|
||||||
(App.Current.Windows[0] as MainWindow).ShowImage(imageUrl);
|
(App.Current.Windows[0] as MainWindow).ShowImage(imageUrl);*/
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Background: Quick reply to the conversation
|
// 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"];
|
string msg = userInput["tbReply"];
|
||||||
|
|
||||||
// And send this message
|
// And send this message
|
||||||
@ -62,11 +66,31 @@ namespace DisplayMagician
|
|||||||
if (App.Current.Windows.Count == 0)
|
if (App.Current.Windows.Count == 0)
|
||||||
{
|
{
|
||||||
Application.Current.Shutdown();
|
Application.Current.Shutdown();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
break;
|
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()
|
private void OpenWindowIfNeeded()
|
||||||
|
@ -237,6 +237,9 @@ namespace DisplayMagician {
|
|||||||
Console.WriteLine($"Program/Main exception: Unable to execute application - {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
|
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
|
// Shutdown NLog
|
||||||
NLog.LogManager.Shutdown();
|
NLog.LogManager.Shutdown();
|
||||||
|
|
||||||
|
@ -41,10 +41,6 @@ namespace DisplayMagician.UIForms
|
|||||||
notifyIcon.ContextMenuStrip = mainContextMenuStrip;
|
notifyIcon.ContextMenuStrip = mainContextMenuStrip;
|
||||||
RefreshNotifyIconMenus();
|
RefreshNotifyIconMenus();
|
||||||
|
|
||||||
/*WaitingForm testform = new WaitingForm();
|
|
||||||
testform.Owner = this;
|
|
||||||
testform.Show();*/
|
|
||||||
|
|
||||||
if (Program.AppProgramSettings.MinimiseOnStart)
|
if (Program.AppProgramSettings.MinimiseOnStart)
|
||||||
{
|
{
|
||||||
// Make the form minimised on start
|
// Make the form minimised on start
|
||||||
@ -52,6 +48,25 @@ namespace DisplayMagician.UIForms
|
|||||||
// Hide the application to notification area when the form is closed
|
// Hide the application to notification area when the form is closed
|
||||||
allowClose = false;
|
allowClose = false;
|
||||||
cb_minimise_notification_area.Checked = true;
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -98,6 +113,26 @@ namespace DisplayMagician.UIForms
|
|||||||
|
|
||||||
private void btn_exit_Click(object sender, EventArgs e)
|
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();
|
Application.Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,6 +299,8 @@ namespace DisplayMagician.UIForms
|
|||||||
allowClose = false;
|
allowClose = false;
|
||||||
// Enable the MinimiseOnStart setting
|
// Enable the MinimiseOnStart setting
|
||||||
Program.AppProgramSettings.MinimiseOnStart = true;
|
Program.AppProgramSettings.MinimiseOnStart = true;
|
||||||
|
// Change the exit_button text to say 'Close'
|
||||||
|
btn_exit.Text = "&Close";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -273,6 +310,9 @@ namespace DisplayMagician.UIForms
|
|||||||
allowClose = true;
|
allowClose = true;
|
||||||
// Disable the MinimiseOnStart setting
|
// Disable the MinimiseOnStart setting
|
||||||
Program.AppProgramSettings.MinimiseOnStart = false;
|
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)
|
private void btn_toast_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Construct the toast content
|
// Construct the toast content
|
||||||
ToastContent toastContent = new ToastContent()
|
ToastContentBuilder tcBuilder = new ToastContentBuilder()
|
||||||
{
|
.AddToastActivationInfo("notify=runningGame", ToastActivationType.Foreground)
|
||||||
// Arguments when the user taps body of toast
|
.AddText("This is the notification title!", hintMaxLines: 1)
|
||||||
Launch = "DisplayMagician_Notification",
|
.AddText("This is the description")
|
||||||
|
.AddButton("Stop", ToastActivationType.Background, "notify=runningGame&action=stop");
|
||||||
Visual = new ToastVisual()
|
ToastContent toastContent = tcBuilder.Content;
|
||||||
{
|
|
||||||
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())
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
};
|
|
||||||
|
|
||||||
// Make sure to use Windows.Data.Xml.Dom
|
// Make sure to use Windows.Data.Xml.Dom
|
||||||
var doc = new XmlDocument();
|
var doc = new XmlDocument();
|
||||||
doc.LoadXml(toastContent.GetContent());
|
doc.LoadXml(toastContent.GetContent());
|
||||||
|
@ -10834,7 +10834,7 @@
|
|||||||
<value>NoControl</value>
|
<value>NoControl</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="lbl_create_shortcut.Location" type="System.Drawing.Point, System.Drawing">
|
<data name="lbl_create_shortcut.Location" type="System.Drawing.Point, System.Drawing">
|
||||||
<value>220, 235</value>
|
<value>220, 237</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="lbl_create_shortcut.Size" type="System.Drawing.Size, System.Drawing">
|
<data name="lbl_create_shortcut.Size" type="System.Drawing.Size, System.Drawing">
|
||||||
<value>343, 22</value>
|
<value>343, 22</value>
|
||||||
@ -10873,7 +10873,7 @@
|
|||||||
<value>NoControl</value>
|
<value>NoControl</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="cb_minimise_notification_area.Location" type="System.Drawing.Point, System.Drawing">
|
<data name="cb_minimise_notification_area.Location" type="System.Drawing.Point, System.Drawing">
|
||||||
<value>234, 351</value>
|
<value>234, 354</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="cb_minimise_notification_area.Size" type="System.Drawing.Size, System.Drawing">
|
<data name="cb_minimise_notification_area.Size" type="System.Drawing.Size, System.Drawing">
|
||||||
<value>332, 20</value>
|
<value>332, 20</value>
|
||||||
@ -10906,7 +10906,7 @@
|
|||||||
<value>Microsoft Sans Serif, 9.75pt</value>
|
<value>Microsoft Sans Serif, 9.75pt</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="lbl_version.Location" type="System.Drawing.Point, System.Drawing">
|
<data name="lbl_version.Location" type="System.Drawing.Point, System.Drawing">
|
||||||
<value>12, 352</value>
|
<value>12, 355</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="lbl_version.Size" type="System.Drawing.Size, System.Drawing">
|
<data name="lbl_version.Size" type="System.Drawing.Size, System.Drawing">
|
||||||
<value>25, 16</value>
|
<value>25, 16</value>
|
||||||
@ -10942,7 +10942,7 @@
|
|||||||
<value>Microsoft Sans Serif, 21.75pt</value>
|
<value>Microsoft Sans Serif, 21.75pt</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="btn_setup_game_shortcuts.Location" type="System.Drawing.Point, System.Drawing">
|
<data name="btn_setup_game_shortcuts.Location" type="System.Drawing.Point, System.Drawing">
|
||||||
<value>212, 162</value>
|
<value>212, 164</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="btn_setup_game_shortcuts.Size" type="System.Drawing.Size, System.Drawing">
|
<data name="btn_setup_game_shortcuts.Size" type="System.Drawing.Size, System.Drawing">
|
||||||
<value>360, 50</value>
|
<value>360, 50</value>
|
||||||
@ -10975,7 +10975,7 @@
|
|||||||
<value>NoControl</value>
|
<value>NoControl</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="btn_exit.Location" type="System.Drawing.Point, System.Drawing">
|
<data name="btn_exit.Location" type="System.Drawing.Point, System.Drawing">
|
||||||
<value>700, 348</value>
|
<value>700, 351</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="btn_exit.Size" type="System.Drawing.Size, System.Drawing">
|
<data name="btn_exit.Size" type="System.Drawing.Size, System.Drawing">
|
||||||
<value>75, 23</value>
|
<value>75, 23</value>
|
||||||
@ -63404,10 +63404,10 @@
|
|||||||
<value>218, 22</value>
|
<value>218, 22</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="exitToolStripMenuItem.Text" xml:space="preserve">
|
<data name="exitToolStripMenuItem.Text" xml:space="preserve">
|
||||||
<value>Close DisplayMagician</value>
|
<value>Exit DisplayMagician</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="mainContextMenuStrip.Size" type="System.Drawing.Size, System.Drawing">
|
<data name="mainContextMenuStrip.Size" type="System.Drawing.Size, System.Drawing">
|
||||||
<value>219, 126</value>
|
<value>219, 148</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="mainContextMenuStrip.Text" xml:space="preserve">
|
<data name="mainContextMenuStrip.Text" xml:space="preserve">
|
||||||
<value>Text</value>
|
<value>Text</value>
|
||||||
|
Loading…
Reference in New Issue
Block a user