From 52115dcb61bf91e8686daed5102a26ea7e1a8555 Mon Sep 17 00:00:00 2001 From: Josh King Date: Mon, 5 Oct 2020 10:05:07 +1300 Subject: [PATCH] Only check for support of events once, avoid multiple warnings --- BurntToast/BurntToast.psd1 | 1 + .../Public/New-BurntToastNotification.ps1 | 13 ++------- BurntToast/Public/Submit-BTNotification.ps1 | 28 +++++++------------ CHANGES.md | 2 ++ README.md | 2 ++ 5 files changed, 18 insertions(+), 28 deletions(-) diff --git a/BurntToast/BurntToast.psd1 b/BurntToast/BurntToast.psd1 index 6ebf286..7b3c1e5 100644 --- a/BurntToast/BurntToast.psd1 +++ b/BurntToast/BurntToast.psd1 @@ -46,6 +46,7 @@ * Fix: Error when running Update-BTNotification on PowerShell 6.0+ (#120) * Fix: Error when using actionable toast parameters on any version (#122) +* Fix: Multiple warnings about events not being supported when specifying multiple event types. # 0.8.2 diff --git a/BurntToast/Public/New-BurntToastNotification.ps1 b/BurntToast/Public/New-BurntToastNotification.ps1 index b8ade29..808077d 100644 --- a/BurntToast/Public/New-BurntToastNotification.ps1 +++ b/BurntToast/Public/New-BurntToastNotification.ps1 @@ -268,20 +268,13 @@ $ToastSplat.Add('DataBinding', $DataBinding) } + # Toast events may not be supported, this check happens inside Submit-BTNotification if ($ActivatedAction) { - if ($Script:ActionsSupported) { - $ToastSplat.Add('ActivatedAction', $ActivatedAction) - } else { - Write-Warning $Script:UnsupportedEvents - } + $ToastSplat.Add('ActivatedAction', $ActivatedAction) } if ($DismissedAction) { - if ($Script:ActionsSupported) { - $ToastSplat.Add('DismissedAction', $DismissedAction) - } else { - Write-Warning $Script:UnsupportedEvents - } + $ToastSplat.Add('DismissedAction', $DismissedAction) } if($PSCmdlet.ShouldProcess( "submitting: $($Content.GetContent())" )) { diff --git a/BurntToast/Public/Submit-BTNotification.ps1 b/BurntToast/Public/Submit-BTNotification.ps1 index 7aeb0a3..efb752f 100644 --- a/BurntToast/Public/Submit-BTNotification.ps1 +++ b/BurntToast/Public/Submit-BTNotification.ps1 @@ -149,25 +149,17 @@ $Toast.Data.SequenceNumber = $SequenceNumber } - if ($ActivatedAction) { + if ($ActivatedAction -or $DismissedAction -or $FailedAction) { if ($Script:ActionsSupported) { - Register-ObjectEvent -InputObject $Toast -EventName Activated -Action $ActivatedAction |Out-Null - } else { - Write-Warning $Script:UnsupportedEvents - } - } - - if ($DismissedAction) { - if ($Script:ActionsSupported) { - Register-ObjectEvent -InputObject $Toast -EventName Dismissed -Action $DismissedAction | Out-Null - } else { - Write-Warning $Script:UnsupportedEvents - } - } - - if ($FailedAction) { - if ($Script:ActionsSupported) { - Register-ObjectEvent -InputObject $Toast -EventName Failed -Action $FailedAction | Out-Null + if ($ActivatedAction) { + Register-ObjectEvent -InputObject $Toast -EventName Activated -Action $ActivatedAction |Out-Null + } + if ($DismissedAction) { + Register-ObjectEvent -InputObject $Toast -EventName Dismissed -Action $DismissedAction | Out-Null + } + if ($FailedAction) { + Register-ObjectEvent -InputObject $Toast -EventName Failed -Action $FailedAction | Out-Null + } } else { Write-Warning $Script:UnsupportedEvents } diff --git a/CHANGES.md b/CHANGES.md index 7f3dbf6..f6c4f89 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,8 @@ - Fix: Error when using actionable toast parameters on any version ([#122](https://github.com/Windos/BurntToast/issues/122)) + - Fix: Multiple warnings about events not being supported when specifying multiple event types. + - [v0.8.2](https://github.com/Windos/BurntToast/releases/download/v0.8.2/BurntToast.zip) - Add: AdaptiveGroups are now usable via New-BTColumn diff --git a/README.md b/README.md index 28493e9..7b8fb44 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,8 @@ if you using Powershell 6 or later, extract into `$env:userprofile\Documents\Pow - Fix: Error when using actionable toast parameters on any version ([#122](https://github.com/Windos/BurntToast/issues/122)) + - Fix: Multiple warnings about events not being supported when specifying multiple event types. + - [v0.8.2](https://github.com/Windos/BurntToast/releases/download/v0.8.2/BurntToast.zip) - Add: AdaptiveGroups are now usable via New-BTColumn