How to consume a click-event without dll files in a Toast-Message?
GitHub30 opened this issue · 0 comments
GitHub30 commented
Invoke-WebRequest https://github.com/GitHub30/PoshWinRT/releases/download/1.2/PoshWinRT.dll -OutFile PoshWinRT.dll
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
<actions>
<input id="textBox" type="text"/>
<action content="Send" activationType="system" arguments="dismiss" />
</actions>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$toast = [Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime]::New($XmlDocument)
function WrapToastEvent {
param($target, $eventName)
Add-Type -Path PoshWinRT.dll
$wrapper = new-object "PoshWinRT.EventWrapper[Windows.UI.Notifications.ToastNotification,System.Object]"
$wrapper.Register($target, $eventName)
}
Register-ObjectEvent -InputObject (WrapToastEvent $toast 'Activated') -EventName FireEvent -Action {
Write-Host arguments:, $args[1].Result.arguments
Write-Host textBox:, $args[1].Result.userinput['textBox']
}
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($toast)
https://stackoverflow.com/questions/73237793/how-to-consume-a-click-event-in-a-toast-message
PowerShell 7.1
Invoke-WebRequest https://github.com/Windos/BurntToast/raw/main/BurntToast/lib/Microsoft.Windows.SDK.NET/WinRT.Runtime.dll -OutFile WinRT.Runtime.dll
Add-Type -Path WinRT.Runtime.dll
Invoke-WebRequest https://github.com/Windos/BurntToast/raw/main/BurntToast/lib/Microsoft.Windows.SDK.NET/Microsoft.Windows.SDK.NET.dll -OutFile Microsoft.Windows.SDK.NET.dll
Add-Type -Path Microsoft.Windows.SDK.NET.dll
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
<actions>
<input id="textBox" type="text"/>
<action content="Send" activationType="system" arguments="dismiss" />
</actions>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument]::New()
$XmlDocument.loadXml($xml)
$toast = [Windows.UI.Notifications.ToastNotification]::New($XmlDocument)
Register-ObjectEvent -InputObject $toast -EventName Activated -Action {
Write-Host $Event.SourceArgs.Arguments
Write-Host $Event.SourceArgs.UserInput.Value
}
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier().Show($toast)