Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rough mock-up of actionable toasts in PowerShell 5.1
Add-Type -Path 'C:\temp\microsoft.toolkit.uwp.notifications.7.0.0\lib\net461\Microsoft.Toolkit.Uwp.Notifications.dll'
$CompatMgr = [Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]
Register-ObjectEvent -InputObject $CompatMgr -EventName OnActivated -Action {
if ($Event.SourceArgs.Argument -eq 'SubmitButton') {
switch ($Event.SourceArgs.UserInput.Value) {
Item1 {
$Text1 = 'GIF: Picard Facepalm'
$ImagePath = 'C:\Demos\Gifs\facepalm.gif'
}
Item2 {
$Text1 = 'GIF: Get It Girl'
$ImagePath = 'C:\Demos\Gifs\get-it-girl.gif'
}
Item3 {
$Text1 = 'GIF: Seinfeld - Oh, right right right'
$ImagePath = 'C:\Demos\Gifs\oh-right.gif'
}
Item4 {
$Text1 = 'GIF: Bob Ross?'
$ImagePath = 'C:\Demos\Gifs\bob-ross.gif'
}
}
$ContentBuilder = [Microsoft.Toolkit.Uwp.Notifications.ToastContentBuilder]::new()
$null = $ContentBuilder.AddText($Text1)
$null = $ContentBuilder.AddAppLogoOverride('C:\Program Files\PowerShell\7-preview\assets\Powershell_av_colors.ico', 'None')
$null = $ContentBuilder.AddHeroImage($ImagePath)
$null = $ContentBuilder.SetToastDuration('Long')
$null = $ContentBuilder.AddAudio($null, $null, $true)
$ContentBuilder.Show()
}
}
$ContentBuilder = [Microsoft.Toolkit.Uwp.Notifications.ToastContentBuilder]::new()
$null = $ContentBuilder.AddText('New Batch of Gifs')
$null = $ContentBuilder.AddAppLogoOverride('C:\Program Files\PowerShell\7-preview\assets\Powershell_av_colors.ico', 'None')
$Choices = @()
$Choices += [ValueTuple[string, string]]::new('Item1', 'Picard Facepalm')
$Choices += [ValueTuple[string, string]]::new('Item2', 'Get It Girl')
$Choices += [ValueTuple[string, string]]::new('Item3', 'Seinfeld - Oh, right right right')
$Choices += [ValueTuple[string, string]]::new('Item4', 'Bob Ross?')
$null = $ContentBuilder.AddComboBox('Selection001', 'Select a GIF to view now', 'Item1', $Choices)
$null = $ContentBuilder.AddButton('Submit', 'Background', 'SubmitButton')
$null = $ContentBuilder.AddButton([Microsoft.Toolkit.Uwp.Notifications.ToastButtonDismiss]::new())
$ContentBuilder.Show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment