From 701f6f0b1c41080fb1125ff96f479acbc5470336 Mon Sep 17 00:00:00 2001
From: F K <54195004+fredjk-gh@users.noreply.github.com>
Date: Sat, 18 Dec 2021 16:27:23 -0500
Subject: [PATCH] Add new Rendering controls for notifications, add missing
forwarding (#47)
Plugins authors can now optionally specify what ways their notifications are rendered (subject, of course, to user preferences/settings). The default is to render notifications in all available channels. Examples:
- Show native pop-up window only (ie. no voice/plugin notifiers)
- Disallow other plugin notifiers
This does not support selection of notifier plugins.
Furthermore, persistent notification updates were not previously being forwarded to anything but the native popup notifier. Now plugins and native voice are also supported (subject to user preferences) and respect the new rendering controls added here. There is currently no concept of closing notifications for the native voice or plugin-based notifiers.
---
.../PluginManagement/PluginCore.cs | 29 +++++++++++++++----
ObservatoryFramework/EventArgs.cs | 14 +++++++++
2 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/ObservatoryCore/PluginManagement/PluginCore.cs b/ObservatoryCore/PluginManagement/PluginCore.cs
index 3da0cb8..90f119b 100644
--- a/ObservatoryCore/PluginManagement/PluginCore.cs
+++ b/ObservatoryCore/PluginManagement/PluginCore.cs
@@ -36,15 +36,18 @@ namespace Observatory.PluginManagement
if (!LogMonitor.GetInstance.ReadAllInProgress())
{
- var handler = Notification;
- handler?.Invoke(this, notificationArgs);
+ if (notificationArgs.Rendering.HasFlag(NotificationRendering.PluginNotifier))
+ {
+ var handler = Notification;
+ handler?.Invoke(this, notificationArgs);
+ }
- if (Properties.Core.Default.NativeNotify)
+ if (Properties.Core.Default.NativeNotify && notificationArgs.Rendering.HasFlag(NotificationRendering.NativeVisual))
{
guid = NativePopup.InvokeNativeNotification(notificationArgs);
}
- if (Properties.Core.Default.VoiceNotify)
+ if (Properties.Core.Default.VoiceNotify && notificationArgs.Rendering.HasFlag(NotificationRendering.NativeVocal))
{
NativeVoice.EnqueueAndAnnounce(notificationArgs);
}
@@ -60,7 +63,23 @@ namespace Observatory.PluginManagement
public void UpdateNotification(Guid id, NotificationArgs notificationArgs)
{
- NativePopup.UpdateNotification(id, notificationArgs);
+ if (!LogMonitor.GetInstance.ReadAllInProgress())
+ {
+
+ if (notificationArgs.Rendering.HasFlag(NotificationRendering.PluginNotifier))
+ {
+ var handler = Notification;
+ handler?.Invoke(this, notificationArgs);
+ }
+
+ if (notificationArgs.Rendering.HasFlag(NotificationRendering.NativeVisual))
+ NativePopup.UpdateNotification(id, notificationArgs);
+
+ if (Properties.Core.Default.VoiceNotify && notificationArgs.Rendering.HasFlag(NotificationRendering.NativeVocal))
+ {
+ NativeVoice.EnqueueAndAnnounce(notificationArgs);
+ }
+ }
}
///
diff --git a/ObservatoryFramework/EventArgs.cs b/ObservatoryFramework/EventArgs.cs
index ea48664..c0e3064 100644
--- a/ObservatoryFramework/EventArgs.cs
+++ b/ObservatoryFramework/EventArgs.cs
@@ -54,5 +54,19 @@ namespace Observatory.Framework
/// Specify window Y position as a percentage from upper left corner (overrides Core setting). Default -1.0 (use Core setting).
///
public double YPos = -1.0;
+ ///
+ /// Specifies the desired renderings of the notification.
+ ///
+ public NotificationRendering Rendering = NotificationRendering.All;
+ }
+
+ [Flags]
+ public enum NotificationRendering
+ {
+ // These need to be multiples of 2 as they're used via masking.
+ NativeVisual = 1,
+ NativeVocal = 2,
+ PluginNotifier = 4,
+ All = (NativeVisual | NativeVocal | PluginNotifier)
}
}