|
48 | 48 | .PARAMETER EventDataVariable |
49 | 49 | If specified, assigns the $Event variable from notification callbacks to this global variable name (e.g., -EventDataVariable MyVar gives $global:MyVar in handlers). Implies ReturnEventData. |
50 | 50 |
|
| 51 | + .PARAMETER Urgent |
| 52 | + If set, designates the toast as an "Important Notification" (scenario 'urgent') which can break through Focus Assist, ensuring the notification is delivered even when user focus mode is enabled. |
| 53 | +
|
51 | 54 | .INPUTS |
52 | 55 | None. You cannot pipe input to this function. |
53 | 56 |
|
|
71 | 74 | [hashtable] $DataBinding, |
72 | 75 | [datetime] $ExpirationTime, |
73 | 76 | [switch] $SuppressPopup, |
| 77 | + [switch] $Urgent, |
74 | 78 | [scriptblock] $ActivatedAction, |
75 | 79 | [scriptblock] $DismissedAction, |
76 | 80 | [scriptblock] $FailedAction, |
|
84 | 88 |
|
85 | 89 | $ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::new() |
86 | 90 |
|
| 91 | + $ToastXmlContent = $Content.GetContent() |
| 92 | + |
87 | 93 | if (-not $DataBinding) { |
88 | | - $CleanContent = $Content.GetContent() -Replace '<text(.*?)>{', '<text$1>' |
89 | | - $CleanContent = $CleanContent.Replace('}</text>', '</text>') |
90 | | - $CleanContent = $CleanContent.Replace('="{', '="') |
91 | | - $CleanContent = $CleanContent.Replace('}" ', '" ') |
92 | | - |
93 | | - $ToastXml.LoadXml($CleanContent) |
94 | | - } else { |
95 | | - $ToastXml.LoadXml($Content.GetContent()) |
| 94 | + $ToastXmlContent = $ToastXmlContent -replace '<text(.*?)>{', '<text$1>' |
| 95 | + $ToastXmlContent = $ToastXmlContent.Replace('}</text>', '</text>') |
| 96 | + $ToastXmlContent = $ToastXmlContent.Replace('="{', '="') |
| 97 | + $ToastXmlContent = $ToastXmlContent.Replace('}" ', '" ') |
96 | 98 | } |
97 | 99 |
|
| 100 | + $ToastXml.LoadXml($ToastXmlContent) |
| 101 | + |
| 102 | + # I've been unable to redirect the error from adjusting attributes on the Toast XML |
| 103 | + # to just direct it to null, and so I'm temporarily changing the Error Action |
| 104 | + # Preference and then changing it back to what it was originally. |
| 105 | + $PrevErrorActionPref = $ErrorActionPreference |
| 106 | + $ErrorActionPreference = 'SilentlyContinue' |
| 107 | + |
| 108 | + if ($Urgent) { |
| 109 | + $ToastXml.GetElementsByTagName('toast')[0].SetAttribute('scenario', 'urgent') |
| 110 | + } |
| 111 | + |
| 112 | + $ErrorActionPreference = $PrevErrorActionPref |
| 113 | + |
98 | 114 | $Toast = [Windows.UI.Notifications.ToastNotification]::new($ToastXml) |
99 | 115 |
|
100 | 116 | if ($DataBinding) { |
|
0 commit comments