From ecc2d531ebdcf1f9f4086e471227812761c17789 Mon Sep 17 00:00:00 2001 From: "jonas@geiger-natur.de" Date: Sun, 5 Jan 2025 17:19:16 +0100 Subject: [PATCH] show message only if files exist --- DownloadsFileSync.ps1 | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/DownloadsFileSync.ps1 b/DownloadsFileSync.ps1 index f70d2ec..4654c7f 100644 --- a/DownloadsFileSync.ps1 +++ b/DownloadsFileSync.ps1 @@ -39,25 +39,28 @@ while ($true) { $counter++ } - - #NOTIFICATION - [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null - $template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02) - $toastXml = [xml] $template.GetXml() - $toastXml.GetElementsByTagName("text").Item(0).AppendChild($toastXml.CreateTextNode("Files synchronized")) > $null - $toastXml.GetElementsByTagName("text").Item(1).AppendChild($toastXml.CreateTextNode("$($counter) of $($files.Count)")) > $null + if($files.Count -gt 0) + { + #NOTIFICATION + [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null + $template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02) - $xml = New-Object Windows.Data.Xml.Dom.XmlDocument - $xml.LoadXml($toastXml.OuterXml) + $toastXml = [xml] $template.GetXml() + $toastXml.GetElementsByTagName("text").Item(0).AppendChild($toastXml.CreateTextNode("Files synchronized")) > $null + $toastXml.GetElementsByTagName("text").Item(1).AppendChild($toastXml.CreateTextNode("$($counter) of $($files.Count)")) > $null - $toast = [Windows.UI.Notifications.ToastNotification]::new($xml) - $toast.Tag = "DownloadsFileSync" - $toast.Group = "DownloadsFileSync" - $toast.ExpirationTime = [DateTimeOffset]::Now.AddMinutes(1) + $xml = New-Object Windows.Data.Xml.Dom.XmlDocument + $xml.LoadXml($toastXml.OuterXml) - $notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("DownloadsFileSync") - $notifier.Show($toast); + $toast = [Windows.UI.Notifications.ToastNotification]::new($xml) + $toast.Tag = "DownloadsFileSync" + $toast.Group = "DownloadsFileSync" + $toast.ExpirationTime = [DateTimeOffset]::Now.AddMinutes(1) + + $notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("DownloadsFileSync") + $notifier.Show($toast); + } #START-SLEEP