Created
March 17, 2021 11:36
-
-
Save Windos/345f46dc31f01886aa198728ef165aa2 to your computer and use it in GitHub Desktop.
Rough mock-up of actionable toasts in PowerShell 5.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Did you ever work out how to get the selection choice back as a variable?