Skip to content

Instantly share code, notes, and snippets.

@Windos
Created March 17, 2021 11:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Windos/345f46dc31f01886aa198728ef165aa2 to your computer and use it in GitHub Desktop.
Save Windos/345f46dc31f01886aa198728ef165aa2 to your computer and use it in GitHub Desktop.
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()
@memphisraynz
Copy link

Did you ever work out how to get the selection choice back as a variable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment