Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Full Change Log

- [v1.1.0](https://github.com/Windos/BurntToast/releases/download/v1.1.0/BurntToast.zip)

- Features and Improvements

- Add support for Important Notifications using the Urgent switch.

- Add support for setting button colors.

- Center align notification body text when using the IncomingCall scenario.

- [v1.0.1](https://github.com/Windos/BurntToast/releases/download/v1.0.1/BurntToast.zip)

- Bug Fixes
Expand Down
23 changes: 23 additions & 0 deletions Help/New-BTButton.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Up to five buttons can be added to a single Toast notification. Buttons may have
| `ActivationType`| Microsoft.Toolkit.Uwp.Notifications.ToastActivationType| Defines the activation type that triggers when the button is pressed. Defaults to Protocol. | No |
| `ImageUri` | String | Path or URI of an image icon to display next to the button label. | No |
| `Id` | String | Specifies an ID associated with another toast control (textbox or selection box). For standard buttons, this aligns the button next to a control; for snooze buttons, associates with a selection box. | No |
| `Color` | String (Green/Red) | If specified as `Green` or `Red`, the button will be visually styled as "Success" (green) or "Critical" (red) where supported. Use for representing positive/primary or destructive actions. | No |

## INPUTS

Expand Down Expand Up @@ -74,6 +75,28 @@ New-BTButton -Content 'View Picture' -Arguments $pic -ImageUri $pic

Button with a picture to the left, launches the image file.

## NOTES

To visually distinguish action buttons, you can set the `Color` parameter to `Green` or `Red`. This will render these buttons with a "Success" (green) or "Critical" (red) style in systems that support advanced toast button styling (Windows 11+). Useful for marking approve/submit (green) or destructive (red) actions.

## EXAMPLES

### Example 6

```powershell
New-BTButton -Content 'Approve' -Arguments 'approve' -Color Green
```

Creates a "Success" style (green) button intended for positive actions.

### Example 7

```powershell
New-BTButton -Content 'Delete' -Arguments 'delete' -Color Red
```

Creates a "Critical" style (red) button for destructive actions.

## LINKS

- [New-BTAction](New-BTAction.md)
Expand Down
2 changes: 1 addition & 1 deletion Help/New-BTContent.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The `New-BTContent` function creates a new `ToastContent` object, the root confi
| `Duration` | Microsoft.Toolkit.Uwp.Notifications.ToastDuration| Enum. How long the toast notification is displayed (Short/Long). | No |
| `Header` | Microsoft.Toolkit.Uwp.Notifications.ToastHeader | ToastHeader object, created via `New-BTHeader`, categorizing the toast in Action Center. | No |
| `Launch` | String | Data passed to the activation context when a toast is clicked. | No |
| `Scenario` | Microsoft.Toolkit.Uwp.Notifications.ToastScenario| Enum. Tells Windows to treat the toast as an alarm, reminder, or more (`ToastScenario`). | No |
| `Scenario` | Microsoft.Toolkit.Uwp.Notifications.ToastScenario| Enum. Tells Windows to treat the toast as an alarm, reminder, or more (`ToastScenario`). If the `IncomingCall` scenario is used, any main body text (no longer than a single line) will be center aligned. Will be ignored if toast is submitted with `-Urgent` switch on the `Submit-BTNotification` function, as the Urgent scenario takes precedence but cannot be set via this parameter. | No |
| `Visual` | Microsoft.Toolkit.Uwp.Notifications.ToastVisual | **Required.** ToastVisual object, created by `New-BTVisual`, representing the core content of the toast. | Yes |
| `ToastPeople` | Microsoft.Toolkit.Uwp.Notifications.ToastPeople | ToastPeople object, representing recipient/persons (optional, used for group chat/etc). | No |
| `CustomTimestamp`| DateTime | Optional timestamp for when the toast is considered created (affects Action Center sort order). | No |
Expand Down
10 changes: 10 additions & 0 deletions Help/New-BurntToastNotification.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Creates and displays a rich Toast Notification for Windows.

The `New-BurntToastNotification` function creates and displays a Toast Notification supporting text, images, sounds, progress bars, actions, snooze/dismiss, and more on Microsoft Windows 10+.
Parameter sets ensure mutual exclusivity (e.g., you cannot use Silent and Sound together).
The `-Urgent` switch will designate the toast as an "Important Notification" that can break through Focus Assist.

## PARAMETERS

Expand All @@ -32,6 +33,7 @@ Parameter sets ensure mutual exclusivity (e.g., you cannot use Silent and Sound
| `ActivatedAction` | ScriptBlock | Script block to invoke when the toast is activated (clicked). | No |
| `DismissedAction` | ScriptBlock | Script block to invoke when the toast is dismissed by the user. | No |
| `EventDataVariable`| String | The name of the global variable that will contain event data for use in event handler script blocks. | No |
| `Urgent` | Switch | Designates the toast as an "Important Notification" (scenario 'urgent'), allowing breakthrough of Focus Assist. | No |

## INPUTS

Expand Down Expand Up @@ -85,6 +87,14 @@ New-BurntToastNotification -Text 'Integration Complete' -Attribution 'Powered by

Displays a notification with attribution at the bottom, e.g., "Powered by BurntToast".

### Example: Important Notification with Urgent

```powershell
New-BurntToastNotification -Text 'Critical System Alert' -Urgent
```

Marks the notification as "Important", causing it to break through Focus Assist.

## LINKS

- [New-BTButton](New-BTButton.md)
Expand Down
5 changes: 4 additions & 1 deletion Help/Submit-BTNotification.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Submits a completed toast notification for display.
## DESCRIPTION

The `Submit-BTNotification` function submits a completed toast notification to the operating system's notification manager for display.
This function supports advanced scenarios such as event callbacks for user actions or toast dismissal, sequence numbering to ensure correct update order, unique identification for toast replacement, expiration control, and direct Action Center delivery.
This function supports advanced scenarios such as event callbacks for user actions or toast dismissal, sequence numbering to ensure correct update order, unique identification for toast replacement, expiration control, direct Action Center delivery, and designating a notification as "Important" (using the `-Urgent` switch) so that it can break through Focus Assist.

If a button in the toast is created using `New-BTButton` with the `-Color` parameter (`Green` or `Red`), Submit-BTNotification will ensure those buttons are visually styled as "Success" (green) or "Critical" (red) in capable environments. This allows you to clearly indicate primary/positive or destructive actions on the notification.

When a script block is supplied for any of the event actions (`ActivatedAction`, `DismissedAction`, or `FailedAction`), the function ensures that only one registration for a logically identical handler is allowed per notification event type. This is accomplished by normalizing and hashing the script block; the resulting hash uniquely identifies the action for event registration purposes. Attempting to register the same handler multiple times for a given event will not create a duplicate subscription, but instead will produce an informative warning.

Expand All @@ -27,6 +29,7 @@ Specifying `-EventDataVariable` implicitly enables the behavior of `-ReturnEvent
| `DataBinding` | Hashtable | Hashtable mapping strings to binding keys in a toast notification. Enables advanced updating scenarios. | No |
| `ExpirationTime` | DateTime | When the notification is no longer relevant and should be removed from the Action Center. | No |
| `SuppressPopup` | Switch | If set, the notification is delivered directly to the Action Center (bypassing immediate display). | No |
| `Urgent` | Switch | 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. | No |
| `ActivatedAction` | ScriptBlock | A script block executed if the user activates/clicks the toast notification. | No |
| `DismissedAction` | ScriptBlock | A script block executed if the user dismisses the toast notification. | No |
| `FailedAction` | ScriptBlock | A script block executed if the notification fails to display properly. | No |
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ See the [Chocolatey community package](https://chocolatey.org/packages/burnttoas

## Releases

### [v1.1.0](https://github.com/Windos/BurntToast/releases/download/v1.1.0/BurntToast.zip)

#### Features and Improvements

- Add support for Important Notifications using the Urgent switch.

- Add support for setting button colors.

- Center align notification body text when using the IncomingCall scenario.

### [v1.0.1](https://github.com/Windos/BurntToast/releases/download/v1.0.1/BurntToast.zip)

#### Bug Fixes
Expand Down
9 changes: 9 additions & 0 deletions Tests/New-BTButton.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,12 @@ Describe 'New-BTButton' {
}
}
}

Context 'custom button with color' {
It 'creates a button with green color without throwing' {
{ New-BTButton -Content 'Approve' -Arguments 'approve' -Color Green -WhatIf } | Should -Not -Throw
}
It 'creates a button with red color without throwing' {
{ New-BTButton -Content 'Delete' -Arguments 'delete' -Color Red -WhatIf } | Should -Not -Throw
}
}
6 changes: 6 additions & 0 deletions Tests/New-BurntToastNotification.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,9 @@ Context 'include attribution string' {
$Log | Should -Be $Expected
}
}

Context 'Urgent scenarios' {
It 'does not throw when using -Urgent' {
{ New-BurntToastNotification -Text 'Critical Alert' -Urgent -WhatIf } | Should -Not -Throw
}
}
6 changes: 6 additions & 0 deletions Tests/Submit-BTNotification.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ Describe 'Submit-BTNotification' {
$output | Should -Not -Contain "Duplicate or conflicting OnActivated ScriptBlock event detected"
}
}
Context 'Urgent scenario' {
It 'runs without error with -Urgent' {
$mockContent = [Activator]::CreateInstance([Microsoft.Toolkit.Uwp.Notifications.ToastContent])
{ Submit-BTNotification -Content $mockContent -Urgent -WhatIf } | Should -Not -Throw
}
}
}
11 changes: 9 additions & 2 deletions src/BurntToast.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@{
RootModule = 'BurntToast.psm1'
ModuleVersion = '1.0.1'
ModuleVersion = '1.1.0'
# Can only use CompatiblePSEditions if PowerShellVersion is set to 5.1, not sure about limiting this to that version yet.
# CompatiblePSEditions = @('Desktop')
GUID = '751a2aeb-a68f-422e-a2ea-376bdd81612a'
Expand Down Expand Up @@ -38,7 +38,14 @@
LicenseUri = 'https://github.com/Windos/BurntToast/blob/main/LICENSE'
ProjectUri = 'https://github.com/Windos/BurntToast'
IconUri = 'https://rawcdn.githack.com/Windos/BurntToast/3dd8dd7457552056da4bbd27880f8283e1116395/Media/BurntToast-Logo.png'
ReleaseNotes = '# 1.0.1
ReleaseNotes = '# 1.1.0

* Features and Improvements
* Add support for Important Notifications using the Urgent switch.
* Add support for setting button colors.
* Center align notification body text when using the IncomingCall scenario.

# 1.0.1

* Bug Fixes
* OnActivated events are "sticky"
Expand Down
28 changes: 24 additions & 4 deletions src/Public/New-BTButton.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
function New-BTButton {
<#
.SYNOPSIS
Creates a new clickable button for a Toast Notification.
Creates a new clickable button for a Toast Notification, with optional color styling.

.DESCRIPTION
The New-BTButton function creates a new button for a Toast Notification. Up to five buttons can be added to a single Toast notification.
Buttons may have display text, an icon, an optional activation type, argument string, or serve as system managed Dismiss/Snooze buttons.
Buttons may have display text, an icon, an optional activation type, argument string, serve as system managed Dismiss/Snooze buttons, and may optionally be rendered with colored button styles by specifying -Color.

If -Color is set to 'Green' or 'Red', the button will be displayed with a "Success" (green) or "Critical" (red) style in supported environments.

.PARAMETER Snooze
Switch. Creates a system-handled snooze button. When paired with a selection box on the toast, the snooze time is customizable.
Expand All @@ -28,6 +30,9 @@
.PARAMETER Id
String. Specifies an ID associated with another toast control (textbox or selection box). For standard buttons, this aligns the button next to a control, for snooze buttons it associates with a selection box.

.PARAMETER Color
String. Optional. If specified as 'Green' or 'Red', the button will be visually styled as "Success" (green) or "Critical" (red) where supported. Use for indicating primary/positive or destructive actions.

.INPUTS
None. You cannot pipe input to this function.

Expand Down Expand Up @@ -57,6 +62,14 @@
New-BTButton -Content 'View Picture' -Arguments $pic -ImageUri $pic
Button with a picture to the left, launches the image file.

.EXAMPLE
New-BTButton -Content 'Approve' -Arguments 'approve' -Color 'Green'
Creates a button with a green "Success" style intended for positive actions like approval.

.EXAMPLE
New-BTButton -Content 'Delete' -Arguments 'delete' -Color 'Red'
Creates a button with a red "Critical" style indicating a destructive action.

.LINK
https://github.com/Windos/BurntToast/blob/main/Help/New-BTButton.md
#>
Expand Down Expand Up @@ -97,7 +110,10 @@
[Parameter(ParameterSetName = 'Button')]
[Parameter(ParameterSetName = 'Snooze')]
[alias('TextBoxId', 'SelectionBoxId')]
[string] $Id
[string] $Id,

[ValidateSet('Green', 'Red')]
[string] $Color
)

switch ($PsCmdlet.ParameterSetName) {
Expand Down Expand Up @@ -125,7 +141,7 @@
if ($Id) {
$Button.SelectionBoxId = $Id
}

if ($ImageUri) {
$Button.ImageUri = $ImageUri
}
Expand All @@ -139,6 +155,10 @@
}
}

if ($Color) {
$Button = $Button.SetHintActionId($Color)
}

switch ($Button.GetType().Name) {
ToastButton { if($PSCmdlet.ShouldProcess("returning: [$($Button.GetType().Name)]:Content=$($Button.Content):Arguments=$($Button.Arguments):ActivationType=$($Button.ActivationType):ImageUri=$($Button.ImageUri):TextBoxId=$($Button.TextBoxId)")) { $Button }}
ToastButtonSnooze { if($PSCmdlet.ShouldProcess("returning: [$($Button.GetType().Name)]:CustomContent=$($Button.CustomContent):ImageUri=$($Button.ImageUri):SelectionBoxId=$($Button.SelectionBoxId)")) { $Button } }
Expand Down
2 changes: 2 additions & 0 deletions src/Public/New-BTContent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

.PARAMETER Scenario
Enum. Tells Windows to treat the toast as an alarm, reminder, or more (ToastScenario).
If the IncomingCall scenario is selected then any main body text on the toast notification, that is no longer than a single line in length, will be center aligned.
Will be ignored if toast is submitted with `-Urgent` switch on the Submit-BTNotification function, as the Urgent scenario takes precedence but cannot be set via this parameter.

.PARAMETER Visual
Required. ToastVisual object, created by New-BTVisual, representing the core content of the toast.
Expand Down
12 changes: 11 additions & 1 deletion src/Public/New-BurntToastNotification.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.DESCRIPTION
The New-BurntToastNotification function creates and displays a Toast Notification supporting text, images, sounds, progress bars, actions, snooze/dismiss, attribution, and more on Microsoft Windows 10+.
Parameter sets ensure mutual exclusivity (e.g., you cannot use Silent and Sound together).
The `-Urgent` switch will designate the toast as an "Important Notification" that can break through Focus Assist.

.PARAMETER Text
Up to 3 strings to show within the Toast Notification. The first is the title.
Expand Down Expand Up @@ -64,6 +65,9 @@
.PARAMETER EventDataVariable
The name of the global variable that will contain event data for use in event handler script blocks.

.PARAMETER Urgent
If set, designates the toast as an "Important Notification" (scenario 'urgent'), allowing it to break through Focus Assist.

.INPUTS
None. You cannot pipe input to this function.

Expand Down Expand Up @@ -186,7 +190,9 @@

[scriptblock] $DismissedAction,

[string] $EventDataVariable
[string] $EventDataVariable,

[switch] $Urgent
)

$ChildObjects = @()
Expand Down Expand Up @@ -300,6 +306,10 @@
$ToastSplat.Add('EventDataVariable', $EventDataVariable)
}

if ($Urgent) {
$ToastSplat.Add('Urgent', $true)
}

if ($PSCmdlet.ShouldProcess( "submitting: $($Content.GetContent())" )) {
Submit-BTNotification @ToastSplat
}
Expand Down
Loading