From cbb44e878f5570c1559f5a4688c62d7ffb08ba7c Mon Sep 17 00:00:00 2001 From: Ben Whitmore Date: Sun, 10 Jan 2021 22:48:34 +0000 Subject: [PATCH] Minor Tweak for XML Append Removed duplicate code in If/Else statement to add actions to $ToastTemplate XML --- Toast_Notify.ps1 | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/Toast_Notify.ps1 b/Toast_Notify.ps1 index 94adf1c..2f97acf 100644 --- a/Toast_Notify.ps1 +++ b/Toast_Notify.ps1 @@ -35,12 +35,9 @@ BadgeImage.jpg HeroImage.jpg CustomMessage.xml -.PARAMETER XMLScriptDirSource +.PARAMETER XMLSource Specify the name of the XML file to read. The XML file must exist in the same directory as Toast_Notify.ps1. If no parameter is passed, it is assumed the XML file is called CustomMessage.xml. -.PARAMETER XMLOtherSource -Specify the location of the Custom XML file used for the Toast when it is not in the same directory as the Toast_Notify.ps1 script - .PARAMETER Snooze Add a snooze option to the Toast @@ -237,8 +234,8 @@ If (([System.Security.Principal.WindowsIdentity]::GetCurrent()).Name -eq $Logged "@ -#Build XML ActionTemplateSnooze (Used when $Snooze is passed as a parameter) -[xml]$ActionTemplateSnooze =@" + #Build XML ActionTemplateSnooze (Used when $Snooze is passed as a parameter) + [xml]$ActionTemplateSnooze = @" @@ -255,8 +252,8 @@ If (([System.Security.Principal.WindowsIdentity]::GetCurrent()).Name -eq $Logged "@ -#Build XML ActionTemplate (Used when $Snooze is not passed as a parameter) -[xml]$ActionTemplate = @" + #Build XML ActionTemplate (Used when $Snooze is not passed as a parameter) + [xml]$ActionTemplate = @" @@ -268,16 +265,17 @@ If (([System.Security.Principal.WindowsIdentity]::GetCurrent()).Name -eq $Logged #If the Snooze parameter was passed, add additional XML elements to Toast If ($Snooze) { - #Add Snooze Actions to $ToastTemplate + #Define default and snooze actions to be added $ToastTemplate $Action_Node = $ActionTemplateSnooze.toast.actions - [void]$ToastTemplate.toast.AppendChild($ToastTemplate.ImportNode($Action_Node, $true)) - - } else { - - #Add Actions to $ToastTemplate - $Action_Node = $ActionTemplate.toast.actions - [void]$ToastTemplate.toast.AppendChild($ToastTemplate.ImportNode($Action_Node, $true)) } + else { + + #Define default actions to be added $ToastTemplate + $Action_Node = $ActionTemplate.toast.actions + } + + #Append actions to $ToastTemplate + [void]$ToastTemplate.toast.AppendChild($ToastTemplate.ImportNode($Action_Node, $true)) #Prepare XML $ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::New()