Public/Advanced/Submit-BTNotification.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function Submit-BTNotification
{
    <#
        .SYNOPSIS
 
        .DESCRIPTION
 
        .INPUTS
        None
 
        .OUTPUTS
        None
         
        .EXAMPLE
 
        .EXAMPLE
 
        .EXAMPLE
 
        .LINK
        https://github.com/Windos/BurntToast
    #>


    [CmdletBinding()]
    param
    (
        [Parameter()]
        [Microsoft.Toolkit.Uwp.Notifications.ToastContent] $Content,

        [Parameter()]
        [string] $AppId = $Script:Config.AppId
    )

    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."
    }

    $null = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
    $null = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]

    $ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::new()
    $ToastXml.LoadXml($Content.GetContent())
    $Toast = [Windows.UI.Notifications.ToastNotification]::new($ToastXml)
    [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Show($Toast)
}