Skip to content

Commit

Permalink
Only check for support of events once, avoid multiple warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Windos committed Oct 4, 2020
1 parent a3707e1 commit 52115dc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 28 deletions.
1 change: 1 addition & 0 deletions BurntToast/BurntToast.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 3 additions & 10 deletions BurntToast/Public/New-BurntToastNotification.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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())" )) {
Expand Down
28 changes: 10 additions & 18 deletions BurntToast/Public/Submit-BTNotification.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 52115dc

Please sign in to comment.