Windos/BurntToast

Curly Braces when "Reminder" pops up

Ig3l opened this issue · 8 comments

Ig3l commented

Hey there,

I'm digging into this awesome tool at the moment and I came around a bug.

I'm triggering a reminder, that the device hasn't rebooted for a specifc time with a Snooze Button.
The first time I fire up the Notification I have a good presentation of my toast:

image

Then I press the Snooze Button and wait for it to appear again. This time the text has curly braces around the text:

image

I am using Windows 10 1903 for my tests but it also happens on 1809.

Here is my code:

[int]$Uptime_hours = ((get-date) - (gcim Win32_OperatingSystem).LastBootUpTime).TotalHours

if ($Uptime_hours -gt 95)
{

$Text1 = New-BTText -Content "It's time for a reboot" -Style Header
$Text2 = New-BTText -Content "Your device is running for: $Uptime_Hours hours" -Style Body
$Image1 = New-BTImage -Source 'C:\Temp\Images\BurntToast.png' -AppLogoOverride -Crop Circle

$Binding = New-BTBinding -Children $Text1, $Text2 -AppLogoOverride $Image1
$Visual = New-BTVisual -BindingGeneric $Binding


$Button1 = New-BTButton -Snooze -Content "Snooze" -Id 'Toast_Uptime_Snooze'
$Action1 = New-BTAction -Buttons $Button1
$Content = New-BTContent -Visual $Visual -Actions $Action1


Submit-BTNotification -Content $Content -UniqueIdentifier "Toast_Uptime"
}

Ahh... this is an interesting interaction with the updatable values in toasts (I'm working on a blog post about this in general.)

I'll have a deeper look and see if there's a fix or at least a work around.

Nice use for a snooze button, btw!

Ig3l commented

Just found a "workaround"!

I converted my toast to an XML and "toasted" it like you described here:

https://toastit.dev/2018/08/21/crouton-8-i-like-your-code-but-i-dont-want-it-on-all-my-computers/

The curly braces are gone :) Sadly, I have to come up with another placeholder for language specifics :/
I'm using two hashtables (en-us / de-de ) and gather the current UI Language beforehand to determine in which language the Toast should be displayed.

PS: I had to alter your "CleanContent a little because "Header" and "Body" styles were not cleaned up:

$CleanContent = $CleanContent.Replace('">{', '">')

OT: Can I easily define the amount of time a Toast is snoozed? I think 10min is too disturbing. Otherwise I have to create a selection box along with pre defined times.

Ah, good call. That used to built directly into the module, but it was removed in order to make updatable toasts work... going to need to figure out how to ensure snoozed toasts work without manually having to clean them up!

Unless it's mysteriously working on your system and not mine, those styles aren't doing anything (see this issue, conveniently the one where the updatable toasts were also sorted out). Your first text object will always be your heading automatically and any extra text will automatically be the body, all specifying a style does is add extra crud to the XML (as you've seen).

Unfortunately it's not possible to set the snooze time without a selectionbox, otherwise it uses the stock standard system standard.

Here's a sample for how to set up the selection box and tie it through to your button:

$15mins = New-BTSelectionBoxItem -Id 30 -Content '30 Minutes'
$60mins = New-BTSelectionBoxItem -Id 60 -Content '1 Hour'
$240mins = New-BTSelectionBoxItem -Id 240 -Content '4 Hours'
$1440mins = New-BTSelectionBoxItem -Id 1440 -Content '1 Day'

$Input = New-BTInput -DefaultSelectionBoxItemId 30 -Id 'SnoozeSelection' -Items $15mins, $60mins, $240mins, $1440mins

$Text1 = New-BTText -Content "It's time for a reboot"
$Text2 = New-BTText -Content "Your device is running for: $Uptime_Hours hours"
$Image1 = New-BTImage -Source 'C:\Temp\Images\BurntToast.png' -AppLogoOverride -Crop Circle

$Binding = New-BTBinding -Children $Text1, $Text2 -AppLogoOverride $Image1
$Visual = New-BTVisual -BindingGeneric $Binding


$Button1 = New-BTButton -Snooze -Content "Snooze" -Id 'SnoozeSelection'
$Action1 = New-BTAction -Buttons $Button1 -Inputs $Input


$Content = New-BTContent -Visual $Visual -Actions $Action1

Submit-BTNotification -Content $Content -UniqueIdentifier "Toast_Uptime"

Key is that the ID for each selection box item is the number of minute to snooze if that option is selected.

Bundle those up into an "Input" through which you can define the default and then give the group and Id.

When it comes to your button, give it the same Id as what you gave the Input / group of selection box items.

Finally, the inputs added to your action.


Will aim to have an "official" solution in place for the next release for the curly braces. Thanks again for the report!

@Ig3l what's the output of your $PSVersionTable?


Notes to myself: it looks like the snooze is stripping a lot of metadata from the original toast.

MissingMeta

  • To-Do: See if scheduled toasts suffer from the same behaviour
  • To-Do: See if older / newer versions of Windows 10 have the same behaviour
  • To-Do: Also try older / newer versions of the UWP toolkit. Not expected to be cause as this is happening after XML generated and passed to the OS.
Ig3l commented

Thanks for the input! :) really appreciate your work!

For the Styles - no, they don't seem to work but that's not a big deal. The Toast work as intended!

Well, thanks for the code! That makes it easy to understand :)

Here is the info of my $Psversiontable

image

PSVersion 5.1.18362.145
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.18362.145
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

PS: Rergarding you to-dos: The issue is happening on both Win10 1903 and 1809 (+ 1809 has the Snooze button in the bottom right of the toast whereas 1903 uses the whole space available)

Couple things to be aware of...

If you're going to include the system uptime in the notification, then the snooze button will result in inaccurate snoozed notifications since the actual uptime will not get recalculated. For instance, a notification says "uptime is 100 hours" and you snooze it for 4 hours. When it comes back, it will still say "uptime is 100 hours" even though the actual uptime is now 104 hours. While you dynamically created the content for the initial toast, the scheduled toast created by the snooze button is a static copy of that original toast.

Also, if the user snoozes the notification for 4 hours, but then they reboot 1 hour later, you'll get another erroneous behavior. 3 hours after the reboot (4 hours since the initial snooze), the snooze duration will expire and the 100 hour uptime notification will display again reminding them to reboot, even though they just rebooted. The only way to prevent something like this is to have a logon script that checks for any reboot reminder scheduled toasts and programmatically deletes them.

For these reasons, I chose to omit snooze buttons from my reboot reminders.

Ig3l commented

Thanks for the input @jholl016 ! Didn't think of this, yet blush

Turns out, this Toast is burned...onto a new one!

v0.7.2 has shipped and the curly braces should be gone. Please do let me know if that's not the case!