Skip to content

Commit 1a83fb0

Browse files
committed
(breaking) Remove AppId customization
1 parent a043a32 commit 1a83fb0

14 files changed

+33
-200
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

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

5+
- Breaking Change: Removed customizable AppId
6+
57
- Breaking Change: Shoulder tap notification support has been removed
68

79
- Libraries: Microsoft.Windows.SDK.NET.Ref library bumped to 10.0.22621.28

Tests/Get-BTHistory.Tests.ps1

-27
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,5 @@ BeforeAll {
1212

1313
Describe 'Get-BTHistory' {
1414
if ($PlatformAvailable) {
15-
Context 'valid AppId, one previous toast' {
16-
Mock Test-Path { $true } -ModuleName BurntToast -Verifiable -ParameterFilter {
17-
$Path -eq 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
18-
}
19-
20-
It 'should not throw' {
21-
{ Get-BTHistory } | Should -Not -Throw
22-
}
23-
24-
It 'tested the correct path' {
25-
Assert-VerifiableMock
26-
}
27-
}
28-
}
29-
30-
Context 'invalid AppId' {
31-
Mock Test-Path { $false } -ModuleName BurntToast -Verifiable -ParameterFilter {
32-
$Path -eq 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\Script Checker'
33-
}
34-
35-
It 'should throw' {
36-
{ 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."
37-
}
38-
39-
It 'tested the correct path' {
40-
Assert-VerifiableMock
41-
}
4215
}
4316
}

Tests/New-BTAppId.Tests.ps1

-52
This file was deleted.

Tests/New-BTColumn.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Describe 'New-BTColumn' {
7575
}
7676

7777
It 'has consitent WhatIf response' {
78-
$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>".'
78+
$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>".'
7979
$Log | Should -Be $Expected
8080
}
8181
}

Tests/New-BurntToastNotification.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Describe 'New-BurntToastNotification' {
160160
}
161161

162162
It 'has consitent WhatIf response' {
163-
$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>".'
163+
$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>".'
164164
$Log | Should -Be $Expected
165165
}
166166
}

src/BurntToast.psd1

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
FunctionsToExport = 'Get-BTHeader',
1313
'Get-BTHistory',
1414
'New-BTAction',
15-
'New-BTAppId',
1615
'New-BTAudio',
1716
'New-BTBinding',
1817
'New-BTButton',

src/Public/Get-BTHeader.ps1

+1-6
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ function Get-BTHeader {
2222
[cmdletBinding(DefaultParametersetName = 'All',
2323
HelpUri='https://github.com/Windos/BurntToast/blob/main/Help/Get-BTHeader.md')]
2424
param (
25-
# Specifies the AppId of the 'application' or process that spawned the toast notification.
26-
[string] $AppId = $Script:Config.AppId,
27-
2825
# A string that uniquely identifies a toast notification to retrieve the Header for
2926
[Parameter(Mandatory,
3027
ParametersetName = 'ByToastId')]
@@ -43,9 +40,7 @@ function Get-BTHeader {
4340
[string] $Id
4441
)
4542

46-
$HistoryParams = @{
47-
'AppId' = $AppId
48-
}
43+
$HistoryParams = @{}
4944
if ($PSCmdlet.ParameterSetName -eq 'ByToastId') { $HistoryParams['UniqueIdentifier'] = $ToastUniqueIdentifier}
5045

5146
$HeaderIds = New-Object -TypeName "System.Collections.ArrayList"

src/Public/Get-BTHistory.ps1

+13-20
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ function Get-BTHistory {
2626

2727
[cmdletBinding(HelpUri='https://github.com/Windos/BurntToast/blob/main/Help/Get-BTHistory.md')]
2828
param (
29-
# Specifies the AppId of the 'application' or process that spawned the toast notification.
30-
[string] $AppId = $Script:Config.AppId,
31-
3229
# 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.
3330
#
3431
# This is useful when updating the progress of a process, using a progress bar, or otherwise correcting/updating the information on a toast.
@@ -38,23 +35,19 @@ function Get-BTHistory {
3835
[switch] $ScheduledToast
3936
)
4037

41-
if (!(Test-Path -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\$AppId")) {
42-
throw "The AppId $AppId is not present in the registry, please run New-BTAppId to avoid inconsistent Toast behaviour."
38+
if ($Script:ActionsSupported) {
39+
Write-Warning -Message 'The output from this function in some versions of PowerShell is not useful. Unfortunately this is expected at this time.'
40+
}
41+
42+
$Toasts = if ($ScheduledToast) {
43+
[Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]::CreateToastNotifier().GetScheduledToastNotifications()
44+
} else {
45+
[Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]::History.GetHistory()
46+
}
47+
48+
if ($UniqueIdentifier) {
49+
$Toasts | Where-Object {$_.Tag -eq $UniqueIdentifier -or $_.Group -eq $UniqueIdentifier}
4350
} else {
44-
if ($Script:ActionsSupported) {
45-
Write-Warning -Message 'The output from this function in some versions of PowerShell is not useful. Unfortunately this is expected at this time.'
46-
}
47-
48-
$Toasts = if ($ScheduledToast) {
49-
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).GetScheduledToastNotifications()
50-
} else {
51-
[Windows.UI.Notifications.ToastNotificationManager]::History.GetHistory($AppId)
52-
}
53-
54-
if ($UniqueIdentifier) {
55-
$Toasts | Where-Object {$_.Tag -eq $UniqueIdentifier -or $_.Group -eq $UniqueIdentifier}
56-
} else {
57-
$Toasts
58-
}
51+
$Toasts
5952
}
6053
}

src/Public/New-BTAppId.ps1

-53
This file was deleted.

src/Public/New-BurntToastNotification.ps1

+1-5
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@
8383

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

86-
# Specifies the AppId of the 'application' or process that spawned the toast notification.
87-
[string] $AppId = $Script:Config.AppId,
88-
8986
# Specifies the path to an image that will override the default image displayed with a Toast Notification.
9087
[String] $AppLogo,
9188

@@ -156,7 +153,7 @@
156153
ParameterSetName = 'Sound-Button')]
157154
[Microsoft.Toolkit.Uwp.Notifications.IToastButton[]] $Button,
158155

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

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

263260
$ToastSplat = @{
264261
Content = $Content
265-
AppId = $AppId
266262
}
267263

268264
if ($UniqueIdentifier) {

src/Public/Remove-BTNotification.ps1

+11-16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function Remove-BTNotification {
66
.DESCRIPTION
77
The Remove-BTNotification function removes toast notifications from the Action Center.
88
9-
If no parameters are specified, all toasts (for the default AppId) will be removed.
9+
If no parameters are specified, all toasts (for the current application) will be removed.
1010
1111
Tags and Groups for Toasts can be found using the Get-BTHistory function.
1212
@@ -30,9 +30,6 @@ function Remove-BTNotification {
3030
SupportsShouldProcess = $true,
3131
HelpUri = 'https://github.com/Windos/BurntToast/blob/main/Help/Remove-BTNotification.md')]
3232
param (
33-
# Specifies the AppId of the 'application' or process that spawned the toast notification.
34-
[string] $AppId = $Script:Config.AppId,
35-
3633
# Specifies the tag, which identifies a given toast notification.
3734
[Parameter(ParameterSetName = 'Individual')]
3835
[string] $Tag,
@@ -48,28 +45,26 @@ function Remove-BTNotification {
4845
)
4946

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

5853
if ($Tag -and $Group) {
59-
if($PSCmdlet.ShouldProcess("Tag: $Tag, Group: $Group, AppId: $AppId", 'Selectively removing notifications')) {
60-
[Windows.UI.Notifications.ToastNotificationManager]::History.Remove($Tag, $Group, $AppId)
54+
if($PSCmdlet.ShouldProcess("Tag: $Tag, Group: $Group", 'Selectively removing notifications')) {
55+
[Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]::History.Remove($Tag, $Group)
6156
}
6257
} elseif ($Tag) {
63-
if($PSCmdlet.ShouldProcess("Tag: $Tag, AppId: $AppId", 'Selectively removing notifications')) {
64-
[Windows.UI.Notifications.ToastNotificationManager]::History.Remove($Tag, $AppId)
58+
if($PSCmdlet.ShouldProcess("Tag: $Tag", 'Selectively removing notifications')) {
59+
[Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]::History.Remove($Tag)
6560
}
6661
} elseif ($Group) {
67-
if($PSCmdlet.ShouldProcess("Group: $Group, AppId: $AppId", 'Selectively removing notifications')) {
68-
[Windows.UI.Notifications.ToastNotificationManager]::History.RemoveGroup($Group, $AppId)
62+
if($PSCmdlet.ShouldProcess("Group: $Group", 'Selectively removing notifications')) {
63+
[Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]::History.RemoveGroup($Group)
6964
}
7065
} else {
71-
if($PSCmdlet.ShouldProcess("AppId: $AppId", 'Clearing all notifications')) {
72-
[Windows.UI.Notifications.ToastNotificationManager]::History.Clear($AppId)
66+
if($PSCmdlet.ShouldProcess("All", 'Clearing all notifications')) {
67+
[Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]::History.Clear()
7368
}
7469
}
7570
}

src/Public/Submit-BTNotification.ps1

+1-8
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
# This is useful when updating the progress of a process, using a progress bar, or otherwise correcting/updating the information on a toast.
3838
[string] $UniqueIdentifier,
3939

40-
# Specifies the AppId of the 'application' or process that spawned the toast notification.
41-
[string] $AppId = $Script:Config.AppId,
42-
4340
# 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.
4441
[hashtable] $DataBinding,
4542

@@ -56,10 +53,6 @@
5653
[scriptblock] $FailedAction
5754
)
5855

59-
if (!(Test-Path -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\$AppId")) {
60-
Write-Warning -Message "The AppId $AppId is not present in the registry, please run New-BTAppId to avoid inconsistent Toast behaviour."
61-
}
62-
6356
if (-not $IsWindows) {
6457
$null = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]
6558
}
@@ -166,7 +159,7 @@
166159
}
167160
}
168161

169-
if($PSCmdlet.ShouldProcess( "submitting: [$($Toast.GetType().Name)] with AppId $AppId, Id $UniqueIdentifier, Sequence Number $($Toast.Data.SequenceNumber) and XML: $($Content.GetContent())")) {
162+
if($PSCmdlet.ShouldProcess( "submitting: [$($Toast.GetType().Name)] with Id $UniqueIdentifier, Sequence Number $($Toast.Data.SequenceNumber) and XML: $($Content.GetContent())")) {
170163
[Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]::CreateToastNotifier().Show($Toast)
171164
}
172165
}

src/Public/Update-BTNotification.ps1

+2-9
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,10 @@
4444
# This is useful when updating the progress of a process, using a progress bar, or otherwise correcting/updating the information on a toast.
4545
[string] $UniqueIdentifier,
4646

47-
# Specifies the AppId of the 'application' or process that spawned the toast notification.
48-
[string] $AppId = $Script:Config.AppId,
49-
5047
# 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.
5148
[hashtable] $DataBinding
5249
)
5350

54-
if (!(Test-Path -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\$AppId")) {
55-
Write-Warning -Message "The AppId $AppId is not present in the registry, please run New-BTAppId to avoid inconsistent Toast behaviour."
56-
}
57-
5851
if (-not $IsWindows) {
5952
$null = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]
6053
}
@@ -73,7 +66,7 @@
7366
$ToastData.SequenceNumber = $SequenceNumber
7467
}
7568

76-
if($PSCmdlet.ShouldProcess("AppId: $AppId, UniqueId: $UniqueIdentifier", 'Updating notification')) {
77-
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Update($ToastData, $UniqueIdentifier, $UniqueIdentifier)
69+
if($PSCmdlet.ShouldProcess("UniqueId: $UniqueIdentifier", 'Updating notification')) {
70+
[Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]::CreateToastNotifier().Update($ToastData, $UniqueIdentifier, $UniqueIdentifier)
7871
}
7972
}

src/config.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"AppId": "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\WindowsPowerShell\\v1.0\\powershell.exe",
32
"AppLogo": "\\Images\\BurntToast.png"
43
}

0 commit comments

Comments
 (0)