Skip to content

Commit

Permalink
(breaking) Remove AppId customization
Browse files Browse the repository at this point in the history
  • Loading branch information
Windos committed Apr 25, 2024
1 parent fc719b8 commit a4e1633
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 200 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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

- Breaking Change: Removed customizable AppId

- Breaking Change: Shoulder tap notification support has been removed

- Libraries: Microsoft.Windows.SDK.NET.Ref library bumped to 10.0.22621.28
Expand Down
27 changes: 0 additions & 27 deletions Tests/Get-BTHistory.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,5 @@ BeforeAll {

Describe 'Get-BTHistory' {
if ($PlatformAvailable) {
Context 'valid AppId, one previous toast' {
Mock Test-Path { $true } -ModuleName BurntToast -Verifiable -ParameterFilter {
$Path -eq 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
}

It 'should not throw' {
{ Get-BTHistory } | Should -Not -Throw
}

It 'tested the correct path' {
Assert-VerifiableMock
}
}
}

Context 'invalid AppId' {
Mock Test-Path { $false } -ModuleName BurntToast -Verifiable -ParameterFilter {
$Path -eq 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\Script Checker'
}

It 'should throw' {
{ Get-BTHistory -AppId 'Script Checker' } | Should -Throw "The AppId Script Checker is not present in the registry, please run New-BTAppId to avoid inconsistent Toast behaviour."
}

It 'tested the correct path' {
Assert-VerifiableMock
}
}
}
52 changes: 0 additions & 52 deletions Tests/New-BTAppId.Tests.ps1

This file was deleted.

2 changes: 1 addition & 1 deletion Tests/New-BTColumn.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Describe 'New-BTColumn' {
Remove-Item tmp.log
}
It 'has consitent WhatIf response' {
$Expected = 'What if: Performing the operation "Submit-BTNotification" on target "submitting: [ToastNotification] with AppId {1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe, Id , Sequence Number and XML: <?xml version="1.0" encoding="utf-8"?><toast><visual><binding template="ToastGeneric"><text>{Now Playing}</text><group><subgroup hint-weight="4"><text hint-style="base">{Title:}</text><text hint-style="base">{Album:}</text><text hint-style="base">{Artist:}</text></subgroup><subgroup hint-weight="6"><text hint-style="baseSubtle">{soft focus}</text><text hint-style="baseSubtle">{Birocratic}</text><text hint-style="baseSubtle">{beets 4 (2017)}</text></subgroup></group></binding></visual></toast>".'
$Expected = 'What if: Performing the operation "Submit-BTNotification" on target "submitting: [ToastNotification] with Id , Sequence Number and XML: <?xml version="1.0" encoding="utf-8"?><toast><visual><binding template="ToastGeneric"><text>{Now Playing}</text><group><subgroup hint-weight="4"><text hint-style="base">{Title:}</text><text hint-style="base">{Album:}</text><text hint-style="base">{Artist:}</text></subgroup><subgroup hint-weight="6"><text hint-style="baseSubtle">{soft focus}</text><text hint-style="baseSubtle">{Birocratic}</text><text hint-style="baseSubtle">{beets 4 (2017)}</text></subgroup></group></binding></visual></toast>".'
$Log | Should -Be $Expected
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/New-BurntToastNotification.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Describe 'New-BurntToastNotification' {
Remove-Item tmp.log
}
It 'has consitent WhatIf response' {
$Expected = 'What if: Performing the operation "Submit-BTNotification" on target "submitting: [ToastNotification] with AppId {1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe, Id , Sequence Number and XML: <?xml version="1.0" encoding="utf-8"?><toast><visual><binding template="ToastGeneric"><text>{Default Notification}</text><text placement="attribution">via Pester</text></binding></visual></toast>".'
$Expected = 'What if: Performing the operation "Submit-BTNotification" on target "submitting: [ToastNotification] with Id , Sequence Number and XML: <?xml version="1.0" encoding="utf-8"?><toast><visual><binding template="ToastGeneric"><text>{Default Notification}</text><text placement="attribution">via Pester</text></binding></visual></toast>".'
$Log | Should -Be $Expected
}
}
Expand Down
1 change: 0 additions & 1 deletion src/BurntToast.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
FunctionsToExport = 'Get-BTHeader',
'Get-BTHistory',
'New-BTAction',
'New-BTAppId',
'New-BTAudio',
'New-BTBinding',
'New-BTButton',
Expand Down
7 changes: 1 addition & 6 deletions src/Public/Get-BTHeader.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ function Get-BTHeader {
[cmdletBinding(DefaultParametersetName = 'All',
HelpUri='https://github.com/Windos/BurntToast/blob/main/Help/Get-BTHeader.md')]
param (
# Specifies the AppId of the 'application' or process that spawned the toast notification.
[string] $AppId = $Script:Config.AppId,

# A string that uniquely identifies a toast notification to retrieve the Header for
[Parameter(Mandatory,
ParametersetName = 'ByToastId')]
Expand All @@ -43,9 +40,7 @@ function Get-BTHeader {
[string] $Id
)

$HistoryParams = @{
'AppId' = $AppId
}
$HistoryParams = @{}
if ($PSCmdlet.ParameterSetName -eq 'ByToastId') { $HistoryParams['UniqueIdentifier'] = $ToastUniqueIdentifier}

$HeaderIds = New-Object -TypeName "System.Collections.ArrayList"
Expand Down
33 changes: 13 additions & 20 deletions src/Public/Get-BTHistory.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ function Get-BTHistory {

[cmdletBinding(HelpUri='https://github.com/Windos/BurntToast/blob/main/Help/Get-BTHistory.md')]
param (
# Specifies the AppId of the 'application' or process that spawned the toast notification.
[string] $AppId = $Script:Config.AppId,

# A string that uniquely identifies a toast notification. Submitting a new toast with the same identifier as a previous toast will replace the previous toast.
#
# This is useful when updating the progress of a process, using a progress bar, or otherwise correcting/updating the information on a toast.
Expand All @@ -38,23 +35,19 @@ function Get-BTHistory {
[switch] $ScheduledToast
)

if (!(Test-Path -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\$AppId")) {
throw "The AppId $AppId is not present in the registry, please run New-BTAppId to avoid inconsistent Toast behaviour."
if ($Script:ActionsSupported) {
Write-Warning -Message 'The output from this function in some versions of PowerShell is not useful. Unfortunately this is expected at this time.'
}

$Toasts = if ($ScheduledToast) {
[Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]::CreateToastNotifier().GetScheduledToastNotifications()
} else {
[Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]::History.GetHistory()
}

if ($UniqueIdentifier) {
$Toasts | Where-Object {$_.Tag -eq $UniqueIdentifier -or $_.Group -eq $UniqueIdentifier}
} else {
if ($Script:ActionsSupported) {
Write-Warning -Message 'The output from this function in some versions of PowerShell is not useful. Unfortunately this is expected at this time.'
}

$Toasts = if ($ScheduledToast) {
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).GetScheduledToastNotifications()
} else {
[Windows.UI.Notifications.ToastNotificationManager]::History.GetHistory($AppId)
}

if ($UniqueIdentifier) {
$Toasts | Where-Object {$_.Tag -eq $UniqueIdentifier -or $_.Group -eq $UniqueIdentifier}
} else {
$Toasts
}
$Toasts
}
}
53 changes: 0 additions & 53 deletions src/Public/New-BTAppId.ps1

This file was deleted.

6 changes: 1 addition & 5 deletions src/Public/New-BurntToastNotification.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@

#TODO: [ValidateScript({ Test-ToastImage -Path $_ })]

# Specifies the AppId of the 'application' or process that spawned the toast notification.
[string] $AppId = $Script:Config.AppId,

# Specifies the path to an image that will override the default image displayed with a Toast Notification.
[String] $AppLogo,

Expand Down Expand Up @@ -156,7 +153,7 @@
ParameterSetName = 'Sound-Button')]
[Microsoft.Toolkit.Uwp.Notifications.IToastButton[]] $Button,

# Specify the Toast Header object created using the New-BTHeader function, for seperation/categorization of toasts from the same AppId.
# Specify the Toast Header object created using the New-BTHeader function, for seperation/categorization of toasts from the same application.
[Microsoft.Toolkit.Uwp.Notifications.ToastHeader] $Header,

# Specify one or more Progress Bar object created using the New-BTProgressBar function.
Expand Down Expand Up @@ -262,7 +259,6 @@

$ToastSplat = @{
Content = $Content
AppId = $AppId
}

if ($UniqueIdentifier) {
Expand Down
27 changes: 11 additions & 16 deletions src/Public/Remove-BTNotification.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Remove-BTNotification {
.DESCRIPTION
The Remove-BTNotification function removes toast notifications from the Action Center.
If no parameters are specified, all toasts (for the default AppId) will be removed.
If no parameters are specified, all toasts (for the current application) will be removed.
Tags and Groups for Toasts can be found using the Get-BTHistory function.
Expand All @@ -30,9 +30,6 @@ function Remove-BTNotification {
SupportsShouldProcess = $true,
HelpUri = 'https://github.com/Windos/BurntToast/blob/main/Help/Remove-BTNotification.md')]
param (
# Specifies the AppId of the 'application' or process that spawned the toast notification.
[string] $AppId = $Script:Config.AppId,

# Specifies the tag, which identifies a given toast notification.
[Parameter(ParameterSetName = 'Individual')]
[string] $Tag,
Expand All @@ -48,28 +45,26 @@ function Remove-BTNotification {
)

if ($UniqueIdentifier) {
if($PSCmdlet.ShouldProcess("Tag: $UniqueIdentifier, Group: $UniqueIdentifier, AppId: $AppId", 'Selectively removing notifications')) {
[Windows.UI.Notifications.ToastNotificationManager]::History.Remove($UniqueIdentifier, $UniqueIdentifier, $AppId)
if($PSCmdlet.ShouldProcess("Tag: $UniqueIdentifier, Group: $UniqueIdentifier", 'Selectively removing notifications')) {
[Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]::History.Remove($UniqueIdentifier, $UniqueIdentifier)
}
} elseif (!(Test-Path -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\$AppId")) {
Write-Warning -Message "The AppId $AppId is not present in the registry, please run New-BTAppId to avoid inconsistent Toast behaviour."
}

if ($Tag -and $Group) {
if($PSCmdlet.ShouldProcess("Tag: $Tag, Group: $Group, AppId: $AppId", 'Selectively removing notifications')) {
[Windows.UI.Notifications.ToastNotificationManager]::History.Remove($Tag, $Group, $AppId)
if($PSCmdlet.ShouldProcess("Tag: $Tag, Group: $Group", 'Selectively removing notifications')) {
[Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]::History.Remove($Tag, $Group)
}
} elseif ($Tag) {
if($PSCmdlet.ShouldProcess("Tag: $Tag, AppId: $AppId", 'Selectively removing notifications')) {
[Windows.UI.Notifications.ToastNotificationManager]::History.Remove($Tag, $AppId)
if($PSCmdlet.ShouldProcess("Tag: $Tag", 'Selectively removing notifications')) {
[Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]::History.Remove($Tag)
}
} elseif ($Group) {
if($PSCmdlet.ShouldProcess("Group: $Group, AppId: $AppId", 'Selectively removing notifications')) {
[Windows.UI.Notifications.ToastNotificationManager]::History.RemoveGroup($Group, $AppId)
if($PSCmdlet.ShouldProcess("Group: $Group", 'Selectively removing notifications')) {
[Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]::History.RemoveGroup($Group)
}
} else {
if($PSCmdlet.ShouldProcess("AppId: $AppId", 'Clearing all notifications')) {
[Windows.UI.Notifications.ToastNotificationManager]::History.Clear($AppId)
if($PSCmdlet.ShouldProcess("All", 'Clearing all notifications')) {
[Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]::History.Clear()
}
}
}
9 changes: 1 addition & 8 deletions src/Public/Submit-BTNotification.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
# This is useful when updating the progress of a process, using a progress bar, or otherwise correcting/updating the information on a toast.
[string] $UniqueIdentifier,

# Specifies the AppId of the 'application' or process that spawned the toast notification.
[string] $AppId = $Script:Config.AppId,

# A hashtable that binds strings to keys in a toast notification. In order to update a toast, the original toast needs to include a databinding hashtable.
[hashtable] $DataBinding,

Expand All @@ -56,10 +53,6 @@
[scriptblock] $FailedAction
)

if (!(Test-Path -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\$AppId")) {
Write-Warning -Message "The AppId $AppId is not present in the registry, please run New-BTAppId to avoid inconsistent Toast behaviour."
}

if (-not $IsWindows) {
$null = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]
}
Expand Down Expand Up @@ -166,7 +159,7 @@
}
}

if($PSCmdlet.ShouldProcess( "submitting: [$($Toast.GetType().Name)] with AppId $AppId, Id $UniqueIdentifier, Sequence Number $($Toast.Data.SequenceNumber) and XML: $($Content.GetContent())")) {
if($PSCmdlet.ShouldProcess( "submitting: [$($Toast.GetType().Name)] with Id $UniqueIdentifier, Sequence Number $($Toast.Data.SequenceNumber) and XML: $($Content.GetContent())")) {
[Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]::CreateToastNotifier().Show($Toast)
}
}
11 changes: 2 additions & 9 deletions src/Public/Update-BTNotification.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,10 @@
# This is useful when updating the progress of a process, using a progress bar, or otherwise correcting/updating the information on a toast.
[string] $UniqueIdentifier,

# Specifies the AppId of the 'application' or process that spawned the toast notification.
[string] $AppId = $Script:Config.AppId,

# A hashtable that binds strings to keys in a toast notification. In order to update a toast, the original toast needs to include a databinding hashtable.
[hashtable] $DataBinding
)

if (!(Test-Path -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\$AppId")) {
Write-Warning -Message "The AppId $AppId is not present in the registry, please run New-BTAppId to avoid inconsistent Toast behaviour."
}

if (-not $IsWindows) {
$null = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]
}
Expand All @@ -73,7 +66,7 @@
$ToastData.SequenceNumber = $SequenceNumber
}

if($PSCmdlet.ShouldProcess("AppId: $AppId, UniqueId: $UniqueIdentifier", 'Updating notification')) {
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Update($ToastData, $UniqueIdentifier, $UniqueIdentifier)
if($PSCmdlet.ShouldProcess("UniqueId: $UniqueIdentifier", 'Updating notification')) {
[Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]::CreateToastNotifier().Update($ToastData, $UniqueIdentifier, $UniqueIdentifier)
}
}
1 change: 0 additions & 1 deletion src/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"AppId": "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\WindowsPowerShell\\v1.0\\powershell.exe",
"AppLogo": "\\Images\\BurntToast.png"
}

0 comments on commit a4e1633

Please sign in to comment.