Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.7.1 #95

Merged
merged 21 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions Azure-Pipelines/BurntToast-Template.psm1
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@

$WinMajorVersion = (Get-CimInstance -ClassName Win32_OperatingSystem -Property Version).Version.Split('.')[0]

if ($WinMajorVersion -ge 10)
{
if ($WinMajorVersion -ge 10) {
$Library = @( Get-ChildItem -Path $PSScriptRoot\lib\*.dll -Recurse -ErrorAction SilentlyContinue )

# Add one class from each expected DLL here:
$LibraryMap = @{
'Microsoft.Toolkit.Uwp.Notifications.dll' = 'Microsoft.Toolkit.Uwp.Notifications.ToastContent'
}

$Script:Config = Get-Content -Path $PSScriptRoot\config.json -ErrorAction SilentlyContinue | ConvertFrom-Json
$Script:DefaultImage = "$PSScriptRoot$($Script:Config.AppLogo)"
$Script:DefaultImage = if ($Script:Config.AppLogo -match '^[.\\]') {
"$PSScriptRoot$($Script:Config.AppLogo)"
} else {
$Script:Config.AppLogo
}

Foreach($Type in $Library)
{
Try {
Add-Type -Path $Type.FullName
} Catch {
foreach ($Type in $Library) {
try {
if (-not ($LibraryMap[$Type.Name] -as [type])) {
Add-Type -Path $Type.FullName -ErrorAction Stop
}
} catch {
Write-Error -Message "Failed to load library $($Type.FullName): $_"
}
}

Export-ModuleMember -Alias 'Toast'
Export-ModuleMember -Function $PublicFunctions

# Register default AppId
New-BTAppId

$null = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
}
else
{
} else {
throw 'This version of BurntToast will only work on Windows 10. If you would like to use BurntToast on Windows 8, please use version 0.4'
}
2 changes: 0 additions & 2 deletions Azure-Pipelines/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ if($Test.IsPresent) {

$RelevantFiles = (Get-ChildItem ./BurntToast -Recurse -Include "*.psm1","*.ps1").FullName

$RelevantFiles = (Get-ChildItem ./BurntToast -Recurse -Include "*.psm1","*.ps1").FullName

if ($env:TF_BUILD) {
$res = Invoke-Pester "./Tests" -OutputFormat NUnitXml -OutputFile TestResults.xml -CodeCoverage $RelevantFiles -PassThru
if ($res.FailedCount -gt 0) { throw "$($res.FailedCount) tests failed." }
Expand Down
25 changes: 13 additions & 12 deletions BurntToast/BurntToast.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@{
RootModule = 'BurntToast.psm1'
ModuleVersion = '0.7.0'
ModuleVersion = '0.7.1'
# Can only use CompatiblePSEditions if PowerShellVersion is set to 5.1, not sure about limiting this to that version yet.
# CompatiblePSEditions = @('Desktop')
GUID = '751a2aeb-a68f-422e-a2ea-376bdd81612a'
Expand Down Expand Up @@ -40,18 +40,19 @@
LicenseUri = 'https://github.com/Windos/BurntToast/blob/master/LICENSE'
ProjectUri = 'https://github.com/Windos/BurntToast'
IconUri = 'https://raw.githubusercontent.com/Windos/BurntToast/master/Media/BurntToast-Logo.png'
ReleaseNotes = '# 0.7.0
ReleaseNotes = '# 0.7.1

* HEADLINE FEATURE: My People "Shoulder Tap" notifications have been implemented
* You can now specify images on the network via UNC paths. Fix for #56
* We''re now properly supporting bindable text, and removing the curly braces more gracefully
* Get a list of all toasts you''ve sent, which have not been dismissed by the user, using Get-BTHistory
* Remove toasts you''ve sent, using Remove-BTNotification
* Set expiration times on toasts using the new ExpirationTime parameter on New-BurntToastNotification and Submit-BTNotification
* Toasts which have expired are removed from the Action Center
* Send toasts directly to the Action Center, and avoid showing them on screen, with the new SuppressPopup switch on New-BurntToastNotification and Submit-BTNotification
* You can now adjust a toasts timestamp (both past and future) using the CustomTimestamp parameter on New-BurntToastNotification and New-BTContent
* If not specified, the system uses the time at which the toast was received and this may not accuratly reflect the intent of the notification
* Update: Microsoft Community Toolkit to 6.0.0
* New: Support relative paths on images
* New: "ScheduledToast" switch added to `Get-BTHistory` which returns scheduled or snoozed toast notifications
* Enhancement: Libraries only loaded on module import if libraries not already loaded
* Enhancement: Validate that image paths exist
* Fix: Reverted to XML clean up to remove curly braces if databindings are not being used (Issue #72)

## Known Issues

* Regardless of what snooze option is chosen, a snoozed toast will re-appear after 9 minutes
* Cause is unknown and isn''t unique to v0.7.1, will be investigated while working on v0.7.2
'
}
}
Expand Down
44 changes: 22 additions & 22 deletions BurntToast/BurntToast.psm1
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
$WinMajorVersion = (Get-CimInstance -ClassName Win32_OperatingSystem -Property Version).Version.Split('.')[0]

if ($WinMajorVersion -ge 10)
{
$Public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue )
if ($WinMajorVersion -ge 10) {
$Public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue )
$Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue )
$Library = @( Get-ChildItem -Path $PSScriptRoot\lib\*.dll -Recurse -ErrorAction SilentlyContinue )

# Add one class from each expected DLL here:
$LibraryMap = @{
'Microsoft.Toolkit.Uwp.Notifications.dll' = 'Microsoft.Toolkit.Uwp.Notifications.ToastContent'
}

$Script:Config = Get-Content -Path $PSScriptRoot\config.json -ErrorAction SilentlyContinue | ConvertFrom-Json
$Script:DefaultImage = "$PSScriptRoot$($Script:Config.AppLogo)"
$Script:DefaultImage = if ($Script:Config.AppLogo -match '^[.\\]') {
"$PSScriptRoot$($Script:Config.AppLogo)"
} else {
$Script:Config.AppLogo
}

Foreach($Import in @($Public + $Private))
{
Try
{
foreach ($Import in @($Public + $Private)) {
try {
. $Import.FullName
}
Catch
{
} catch {
Write-Error -Message "Failed to import function $($Import.FullName): $_"
}
}

Foreach($Type in $Library)
{
Try
{
Add-Type -Path $Type.FullName
}
Catch
{
foreach ($Type in $Library) {
try {
if (-not ($LibraryMap[$Type.Name] -as [type])) {
Add-Type -Path $Type.FullName -ErrorAction Stop
}
} catch {
Write-Error -Message "Failed to load library $($Type.FullName): $_"
}
}
Expand All @@ -40,8 +42,6 @@ if ($WinMajorVersion -ge 10)
New-BTAppId

$null = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
}
else
{
} else {
throw 'This version of BurntToast will only work on Windows 10. If you would like to use BurntToast on Windows 8, please use version 0.4'
}
6 changes: 5 additions & 1 deletion BurntToast/Private/Optimize-BTImageSource.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ function Optimize-BTImageSource {

$NewFilePath
} else {
$Source
try {
(Get-Item -Path $Source -ErrorAction Stop).FullName
} catch {
Write-Warning -Message "The image source '$Source' doesn't exist, failed back to icon."
}
}
}
20 changes: 15 additions & 5 deletions BurntToast/Public/Get-BTHistory.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ function Get-BTHistory {

The object returned includes tag and group information which can be used with the Remove-BTNotification function to clear specific notification from the Action Center.

Using the ScheduledToast switch you can get all toast notifications that have been scheduled to display, whether by scheduling outright or snoozing.

.INPUTS
STRING

.OUTPUTS
TODO
ToastNotification
ScheduledToastNotification

.EXAMPLE
Get-BTHistory
Expand All @@ -28,18 +31,25 @@ function Get-BTHistory {
# A string that uniquely identifies a toast notification. Submitting a new toast with the same identifier as a previous toast will replace the previous toast.
#
# This is useful when updating the progress of a process, using a progress bar, or otherwise correcting/updating the information on a toast.
[string] $UniqueIdentifier
[string] $UniqueIdentifier,

# Specified that you need to see scheduled toast notifications, rather the those in the Action Center.
[switch] $ScheduledToast
)

if (!(Test-Path -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\$AppId")) {
throw "The AppId $AppId is not present in the registry, please run New-BTAppId to avoid inconsistent Toast behaviour."
} else {
$History = [Windows.UI.Notifications.ToastNotificationManager]::History.GetHistory($AppId)
$Toasts = if ($ScheduledToast) {
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).GetScheduledToastNotifications()
} else {
[Windows.UI.Notifications.ToastNotificationManager]::History.GetHistory($AppId)
}

if ($UniqueIdentifier) {
$History | Where-Object {$_.Tag -eq $UniqueIdentifier -or $_.Group -eq $UniqueIdentifier}
$Toasts | Where-Object {$_.Tag -eq $UniqueIdentifier -or $_.Group -eq $UniqueIdentifier}
} else {
$History
$Toasts
}
}
}
100 changes: 56 additions & 44 deletions BurntToast/Public/Submit-BTNotification.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,73 +57,85 @@

$ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::new()

$ToastXml.LoadXml($Content.GetContent())
$Toast = [Windows.UI.Notifications.ToastNotification]::new($ToastXml)

if ($UniqueIdentifier) {
$Toast.Group = $UniqueIdentifier
$Toast.Tag = $UniqueIdentifier
}

if ($ExpirationTime) {
$Toast.ExpirationTime = $ExpirationTime
}

if ($SuppressPopup.IsPresent) {
$Toast.SuppressPopup = $SuppressPopup
if (-not $DataBinding) {
$CleanContent = $Content.GetContent().Replace('<text>{', '<text>')
$CleanContent = $CleanContent.Replace('}</text>', '</text>')
$CleanContent = $CleanContent.Replace('="{', '="')
$CleanContent = $CleanContent.Replace('}" ', '" ')

$ToastXml.LoadXml($CleanContent)
} else {
$ToastXml.LoadXml($Content.GetContent())
}

$DataDictionary = New-Object 'system.collections.generic.dictionary[string,string]'
$Toast = [Windows.UI.Notifications.ToastNotification]::new($ToastXml)

if ($DataBinding) {
foreach ($Key in $DataBinding.Keys) {
$DataDictionary.Add($Key, $DataBinding.$Key)
}
}

foreach ($Child in $Content.Visual.BindingGeneric.Children) {
if ($Child.GetType().Name -eq 'AdaptiveText') {
$BindingName = $Child.Text.BindingName
$DataDictionary = New-Object 'system.collections.generic.dictionary[string,string]'

if (!$DataDictionary.ContainsKey($BindingName)) {
$DataDictionary.Add($BindingName, $BindingName)
if ($DataBinding) {
foreach ($Key in $DataBinding.Keys) {
$DataDictionary.Add($Key, $DataBinding.$Key)
}
} elseif ($Child.GetType().Name -eq 'AdaptiveProgressBar') {
if ($Child.Title) {
$BindingName = $Child.Title.BindingName
}

foreach ($Child in $Content.Visual.BindingGeneric.Children) {
if ($Child.GetType().Name -eq 'AdaptiveText') {
$BindingName = $Child.Text.BindingName

if (!$DataDictionary.ContainsKey($BindingName)) {
$DataDictionary.Add($BindingName, $BindingName)
}
}
} elseif ($Child.GetType().Name -eq 'AdaptiveProgressBar') {
if ($Child.Title) {
$BindingName = $Child.Title.BindingName

if ($Child.Value) {
$BindingName = $Child.Value.BindingName
if (!$DataDictionary.ContainsKey($BindingName)) {
$DataDictionary.Add($BindingName, $BindingName)
}
}

if (!$DataDictionary.ContainsKey($BindingName)) {
$DataDictionary.Add($BindingName, $BindingName)
if ($Child.Value) {
$BindingName = $Child.Value.BindingName

if (!$DataDictionary.ContainsKey($BindingName)) {
$DataDictionary.Add($BindingName, $BindingName)
}
}
}

if ($Child.ValueStringOverride) {
$BindingName = $Child.ValueStringOverride.BindingName
if ($Child.ValueStringOverride) {
$BindingName = $Child.ValueStringOverride.BindingName

if (!$DataDictionary.ContainsKey($BindingName)) {
$DataDictionary.Add($BindingName, $BindingName)
if (!$DataDictionary.ContainsKey($BindingName)) {
$DataDictionary.Add($BindingName, $BindingName)
}
}
}

if ($Child.Status) {
$BindingName = $Child.Status.BindingName
if ($Child.Status) {
$BindingName = $Child.Status.BindingName

if (!$DataDictionary.ContainsKey($BindingName)) {
$DataDictionary.Add($BindingName, $BindingName)
if (!$DataDictionary.ContainsKey($BindingName)) {
$DataDictionary.Add($BindingName, $BindingName)
}
}
}
}

$Toast.Data = [Windows.UI.Notifications.NotificationData]::new($DataDictionary)
}

$Toast.Data = [Windows.UI.Notifications.NotificationData]::new($DataDictionary)
if ($UniqueIdentifier) {
$Toast.Group = $UniqueIdentifier
$Toast.Tag = $UniqueIdentifier
}

if ($ExpirationTime) {
$Toast.ExpirationTime = $ExpirationTime
}

if ($SuppressPopup.IsPresent) {
$Toast.SuppressPopup = $SuppressPopup
}

if ($SequenceNumber) {
$Toast.Data.SequenceNumber = $SequenceNumber
Expand Down
Binary file not shown.
Loading