Merge pull request #214 from Romanitho/New-Notif

Brand new notif task configuratrion
pull/224/head
Romain 2022-10-28 01:14:13 +02:00 committed by GitHub
commit ea3680d54b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 292 additions and 97 deletions

View File

@ -38,15 +38,16 @@ $Script:WorkingDir = $PSScriptRoot
. $WorkingDir\functions\Get-NotifLocale.ps1 . $WorkingDir\functions\Get-NotifLocale.ps1
. $WorkingDir\functions\Start-NotifTask.ps1 . $WorkingDir\functions\Start-NotifTask.ps1
#Get Toast Locale function
Get-NotifLocale
#Set common variables #Set common variables
$OnClickAction = "$WorkingDir\logs\updates.log" $OnClickAction = "$WorkingDir\logs\updates.log"
$Button1Text = $NotifLocale.local.outputs.output[11].message
$Title = "Winget-AutoUpdate (WAU)" $Title = "Winget-AutoUpdate (WAU)"
$Balise = "Winget-AutoUpdate (WAU)" $Balise = "Winget-AutoUpdate (WAU)"
$UserRun = $True $UserRun = $True
#Get Toast Locale function
Get-NotifLocale
if ($Logs) { if ($Logs) {
if ((Test-Path "$WorkingDir\logs\updates.log")) { if ((Test-Path "$WorkingDir\logs\updates.log")) {
Invoke-Item "$WorkingDir\logs\updates.log" Invoke-Item "$WorkingDir\logs\updates.log"
@ -55,7 +56,7 @@ if ($Logs) {
#Not available yet #Not available yet
$Message = $NotifLocale.local.outputs.output[5].message $Message = $NotifLocale.local.outputs.output[5].message
$MessageType = "warning" $MessageType = "warning"
Start-NotifTask $Title $Message $MessageType $Balise Start-NotifTask -Message $Message -MessageType $MessageType
} }
} }
elseif ($Help) { elseif ($Help) {
@ -67,7 +68,7 @@ else {
if (Test-WAUisRunning) { if (Test-WAUisRunning) {
$Message = $NotifLocale.local.outputs.output[8].message $Message = $NotifLocale.local.outputs.output[8].message
$MessageType = "warning" $MessageType = "warning"
Start-NotifTask $Title $Message $MessageType $Balise $OnClickAction Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss
break break
} }
#Run scheduled task #Run scheduled task
@ -75,19 +76,19 @@ else {
#Starting check - Send notification #Starting check - Send notification
$Message = $NotifLocale.local.outputs.output[6].message $Message = $NotifLocale.local.outputs.output[6].message
$MessageType = "info" $MessageType = "info"
Start-NotifTask $Title $Message $MessageType $Balise $OnClickAction Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss
#Sleep until the task is done #Sleep until the task is done
While (Test-WAUisRunning) { While (Test-WAUisRunning) {
Start-Sleep 3 Start-Sleep 3
} }
$Message = $NotifLocale.local.outputs.output[9].message $Message = $NotifLocale.local.outputs.output[9].message
$MessageType = "success" $MessageType = "success"
Start-NotifTask $Title $Message $MessageType $Balise $OnClickAction Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss
} }
catch { catch {
#Check failed - Just send notification #Check failed - Just send notification
$Message = $NotifLocale.local.outputs.output[7].message $Message = $NotifLocale.local.outputs.output[7].message
$MessageType = "error" $MessageType = "error"
Start-NotifTask $Title $Message $MessageType $Balise Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss
} }
} }

View File

@ -1,27 +1,135 @@
#Function to send notifications to user #Function to send notifications to user
function Start-NotifTask ($Title, $Message, $MessageType, $Balise, $OnClickAction) { function Start-NotifTask {
param(
[String]$Title = "Winget-AutoUpdate",
[String]$Message,
[String]$MessageType,
[String]$Balise = "WAU",
[String]$OnClickAction,
[String]$Body,
[String]$Button1Text,
[String]$Button1Action,
[Switch]$ButtonDismiss = $false
)
if (($WAUConfig.WAU_NotificationLevel -eq "Full") -or ($WAUConfig.WAU_NotificationLevel -eq "SuccessOnly" -and $MessageType -eq "Success") -or ($UserRun)) { if (($WAUConfig.WAU_NotificationLevel -eq "Full") -or ($WAUConfig.WAU_NotificationLevel -eq "SuccessOnly" -and $MessageType -eq "Success") -or ($UserRun)) {
#Prepare OnClickAction (if set) # XML Toast template creation
if ($OnClickAction) { [xml]$ToastTemplate = New-Object system.Xml.XmlDocument
$ToastOnClickAction = "activationType='protocol' launch='$OnClickAction'" $ToastTemplate.LoadXml("<?xml version=`"1.0`" encoding=`"utf-8`"?><toast></toast>")
# Creation of visual node
$XMLvisual = $ToastTemplate.CreateElement("visual")
# Creation of a binding node
$XMLbinding = $ToastTemplate.CreateElement("binding")
$XMLvisual.AppendChild($XMLbinding) | Out-Null
$XMLbindingAtt1 = ($ToastTemplate.CreateAttribute("template"))
$XMLbindingAtt1.Value = "ToastGeneric"
$XMLbinding.Attributes.Append($XMLbindingAtt1) | Out-Null
$XMLimagepath = "$WorkingDir\icons\$MessageType.png"
if (Test-Path $XMLimagepath){
# Creation of a image node
$XMLimage = $ToastTemplate.CreateElement("image")
$XMLbinding.AppendChild($XMLimage) | Out-Null
$XMLimageAtt1 = $ToastTemplate.CreateAttribute("placement")
$XMLimageAtt1.Value = "appLogoOverride"
$XMLimage.Attributes.Append($XMLimageAtt1) | Out-Null
$XMLimageAtt2 = $ToastTemplate.CreateAttribute("src")
$XMLimageAtt2.Value = "$WorkingDir\icons\$MessageType.png"
$XMLimage.Attributes.Append($XMLimageAtt2) | Out-Null
} }
#Add XML variables if ($Title){
[xml]$ToastTemplate = @" # Creation of a text node
<toast $ToastOnClickAction> $XMLtitle = $ToastTemplate.CreateElement("text")
<visual> $XMLtitleText = $ToastTemplate.CreateTextNode($Title)
<binding template="ToastImageAndText03"> $XMLtitle.AppendChild($XMLtitleText) | Out-Null
<text id="1">$Title</text> $XMLbinding.AppendChild($XMLtitle) | Out-Null
<text id="2">$Message</text> }
<image id="1" src="$WorkingDir\icons\$MessageType.png" />
</binding> if ($Message){
</visual> # Creation of a text node
<tag>$Balise</tag> $XMLtext = $ToastTemplate.CreateElement("text")
</toast> $XMLtextText = $ToastTemplate.CreateTextNode($Message)
"@ $XMLtext.AppendChild($XMLtextText) | Out-Null
$XMLbinding.AppendChild($XMLtext) | Out-Null
}
if ($Body){
# Creation of a group node
$XMLgroup = $ToastTemplate.CreateElement("group")
$XMLbinding.AppendChild($XMLgroup) | Out-Null
# Creation of a subgroup node
$XMLsubgroup = $ToastTemplate.CreateElement("subgroup")
$XMLgroup.AppendChild($XMLsubgroup) | Out-Null
# Creation of a text node
$XMLcontent = $ToastTemplate.CreateElement("text")
$XMLcontentText = $ToastTemplate.CreateTextNode($Body)
$XMLcontent.AppendChild($XMLcontentText) | Out-Null
$XMLsubgroup.AppendChild($XMLcontent) | Out-Null
$XMLcontentAtt1 = $ToastTemplate.CreateAttribute("hint-style")
$XMLcontentAtt1.Value = "body"
$XMLcontent.Attributes.Append($XMLcontentAtt1) | Out-Null
$XMLcontentAtt2 = $ToastTemplate.CreateAttribute("hint-wrap")
$XMLcontentAtt2.Value = "true"
$XMLcontent.Attributes.Append($XMLcontentAtt2) | Out-Null
}
# Creation of actions node
$XMLactions = $ToastTemplate.CreateElement("actions")
if ($Button1Text) {
# Creation of action node
$XMLaction = $ToastTemplate.CreateElement("action")
$XMLactions.AppendChild($XMLaction) | Out-Null
$XMLactionAtt1 = $ToastTemplate.CreateAttribute("content")
$XMLactionAtt1.Value = $Button1Text
$XMLaction.Attributes.Append($XMLactionAtt1) | Out-Null
if ($Button1Action){
$XMLactionAtt2 = $ToastTemplate.CreateAttribute("arguments")
$XMLactionAtt2.Value = $Button1Action
$XMLaction.Attributes.Append($XMLactionAtt2) | Out-Null
$XMLactionAtt3 = $ToastTemplate.CreateAttribute("activationType")
$XMLactionAtt3.Value = "Protocol"
$XMLaction.Attributes.Append($XMLactionAtt3) | Out-Null
}
}
if ($ButtonDismiss) {
# Creation of action node
$XMLaction = $ToastTemplate.CreateElement("action")
$XMLactions.AppendChild($XMLaction) | Out-Null
$XMLactionAtt1 = $ToastTemplate.CreateAttribute("content")
$XMLactionAtt1.Value = ""
$XMLaction.Attributes.Append($XMLactionAtt1) | Out-Null
$XMLactionAtt2 = $ToastTemplate.CreateAttribute("arguments")
$XMLactionAtt2.Value = "dismiss"
$XMLaction.Attributes.Append($XMLactionAtt2) | Out-Null
$XMLactionAtt3 = $ToastTemplate.CreateAttribute("activationType")
$XMLactionAtt3.Value = "system"
$XMLaction.Attributes.Append($XMLactionAtt3) | Out-Null
}
# Creation of tag node
$XMLtag = $ToastTemplate.CreateElement("tag")
$XMLtagText = $ToastTemplate.CreateTextNode($Balise)
$XMLtag.AppendChild($XMLtagText) | Out-Null
# Add the visual node to the xml
$ToastTemplate.LastChild.AppendChild($XMLvisual) | Out-Null
$ToastTemplate.LastChild.AppendChild($XMLactions) | Out-Null
$ToastTemplate.LastChild.AppendChild($XMLtag) | Out-Null
if ($OnClickAction){
$ToastTemplate.toast.SetAttribute("activationType", "Protocol") | Out-Null
$ToastTemplate.toast.SetAttribute("launch", $OnClickAction) | Out-Null
}
#if not "Interactive" user, run as system #if not "Interactive" user, run as system
if ($IsSystem) { if ($IsSystem) {

View File

@ -55,12 +55,15 @@ function Test-Network {
#Send Warning Notif if no connection for 5 min #Send Warning Notif if no connection for 5 min
if ($timeout -eq 300) { if ($timeout -eq 300) {
#Log
Write-Log "Notify 'No connection' sent." "Yellow" Write-Log "Notify 'No connection' sent." "Yellow"
#Notif
$Title = $NotifLocale.local.outputs.output[0].title $Title = $NotifLocale.local.outputs.output[0].title
$Message = $NotifLocale.local.outputs.output[0].message $Message = $NotifLocale.local.outputs.output[0].message
$MessageType = "warning" $MessageType = "warning"
$Balise = "connection" $Balise = "Connection"
Start-NotifTask $Title $Message $MessageType $Balise Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Balise $Balise
} }
} }
@ -69,11 +72,14 @@ function Test-Network {
#Send Timeout Notif if no connection for 30 min #Send Timeout Notif if no connection for 30 min
Write-Log "Timeout. No internet connection !" "Red" Write-Log "Timeout. No internet connection !" "Red"
#Notif
$Title = $NotifLocale.local.outputs.output[1].title $Title = $NotifLocale.local.outputs.output[1].title
$Message = $NotifLocale.local.outputs.output[1].message $Message = $NotifLocale.local.outputs.output[1].message
$MessageType = "error" $MessageType = "error"
$Balise = "connection" $Balise = "Connection"
Start-NotifTask $Title $Message $MessageType $Balise Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Balise $Balise
return $false return $false
} }

View File

@ -3,7 +3,10 @@
Function Update-App ($app) { Function Update-App ($app) {
#Get App Info #Get App Info
$OnClickAction = Get-AppInfo $app.Id $ReleaseNoteURL = Get-AppInfo $app.Id
if ($ReleaseNoteURL){
$Button1Text = $NotifLocale.local.outputs.output[10].message
}
#Send available update notification #Send available update notification
Write-Log "Updating $($app.Name) from $($app.Version) to $($app.AvailableVersion)..." "Cyan" Write-Log "Updating $($app.Name) from $($app.Version) to $($app.AvailableVersion)..." "Cyan"
@ -11,7 +14,7 @@ Function Update-App ($app) {
$Message = $NotifLocale.local.outputs.output[2].message -f $($app.Version), $($app.AvailableVersion) $Message = $NotifLocale.local.outputs.output[2].message -f $($app.Version), $($app.AvailableVersion)
$MessageType = "info" $MessageType = "info"
$Balise = $($app.Name) $Balise = $($app.Name)
Start-NotifTask $Title $Message $MessageType $Balise $OnClickAction Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Balise $Balise -Button1Action $ReleaseNoteURL -Button1Text $Button1Text
#Winget upgrade #Winget upgrade
Write-Log "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray" Write-Log "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray"
@ -84,7 +87,7 @@ Function Update-App ($app) {
$Message = $NotifLocale.local.outputs.output[3].message -f $($app.AvailableVersion) $Message = $NotifLocale.local.outputs.output[3].message -f $($app.AvailableVersion)
$MessageType = "success" $MessageType = "success"
$Balise = $($app.Name) $Balise = $($app.Name)
Start-NotifTask $Title $Message $MessageType $Balise $OnClickAction Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Balise $Balise -Button1Action $ReleaseNoteURL -Button1Text $Button1Text
$Script:InstallOK += 1 $Script:InstallOK += 1
@ -99,7 +102,7 @@ Function Update-App ($app) {
$Message = $NotifLocale.local.outputs.output[4].message $Message = $NotifLocale.local.outputs.output[4].message
$MessageType = "error" $MessageType = "error"
$Balise = $($app.Name) $Balise = $($app.Name)
Start-NotifTask $Title $Message $MessageType $Balise $OnClickAction Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Balise $Balise -Button1Action $ReleaseNoteURL -Button1Text $Button1Text
} }

View File

@ -3,13 +3,13 @@
function Update-WAU { function Update-WAU {
$OnClickAction = "https://github.com/Romanitho/Winget-AutoUpdate/releases" $OnClickAction = "https://github.com/Romanitho/Winget-AutoUpdate/releases"
$Button1Text = $NotifLocale.local.outputs.output[10].message
#Send available update notification #Send available update notification
$Title = $NotifLocale.local.outputs.output[2].title -f "Winget-AutoUpdate" $Title = $NotifLocale.local.outputs.output[2].title -f "Winget-AutoUpdate"
$Message = $NotifLocale.local.outputs.output[2].message -f $WAUCurrentVersion, $WAUAvailableVersion $Message = $NotifLocale.local.outputs.output[2].message -f $WAUCurrentVersion, $WAUAvailableVersion
$MessageType = "info" $MessageType = "info"
$Balise = "Winget-AutoUpdate" Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text
Start-NotifTask $Title $Message $MessageType $Balise $OnClickAction
#Run WAU update #Run WAU update
try { try {
@ -53,8 +53,7 @@ function Update-WAU {
$Title = $NotifLocale.local.outputs.output[3].title -f "Winget-AutoUpdate" $Title = $NotifLocale.local.outputs.output[3].title -f "Winget-AutoUpdate"
$Message = $NotifLocale.local.outputs.output[3].message -f $WAUAvailableVersion $Message = $NotifLocale.local.outputs.output[3].message -f $WAUAvailableVersion
$MessageType = "success" $MessageType = "success"
$Balise = "Winget-AutoUpdate" Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text
Start-NotifTask $Title $Message $MessageType $Balise $OnClickAction
#Rerun with newer version #Rerun with newer version
Write-Log "Re-run WAU" Write-Log "Re-run WAU"
@ -70,8 +69,7 @@ function Update-WAU {
$Title = $NotifLocale.local.outputs.output[4].title -f "Winget-AutoUpdate" $Title = $NotifLocale.local.outputs.output[4].title -f "Winget-AutoUpdate"
$Message = $NotifLocale.local.outputs.output[4].message $Message = $NotifLocale.local.outputs.output[4].message
$MessageType = "error" $MessageType = "error"
$Balise = "Winget-AutoUpdate" Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text
Start-NotifTask $Title $Message $MessageType $Balise $OnClickAction
Write-Log "WAU Update failed" "Red" Write-Log "WAU Update failed" "Red"
} }

View File

@ -49,6 +49,13 @@
<output id="9"> <output id="9">
<!--Manual check for updated apps completed--> <!--Manual check for updated apps completed-->
<message>Die manuelle suche nach Updates wurde abgeschlossen.</message> <message>Die manuelle suche nach Updates wurde abgeschlossen.</message>
<output id="10">
<!--See changelog-->
<message>See changelog</message>
</output>
<output id="11">
<!--Open log file-->
<message>Open log file</message>
</output> </output>
</outputs> </outputs>
</local> </local>

View File

@ -50,5 +50,13 @@
<!--Manual check for updated apps completed--> <!--Manual check for updated apps completed-->
<message>Manual check for updated apps completed...</message> <message>Manual check for updated apps completed...</message>
</output> </output>
<output id="10">
<!--See changelog-->
<message>See changelog</message>
</output>
<output id="11">
<!--Open log file-->
<message>Open log file</message>
</output>
</outputs> </outputs>
</local> </local>

View File

@ -50,5 +50,13 @@
<!--Manual check for updated apps completed--> <!--Manual check for updated apps completed-->
<message>Manual check for updated apps completed...</message> <message>Manual check for updated apps completed...</message>
</output> </output>
<output id="10">
<!--See changelog-->
<message>See changelog</message>
</output>
<output id="11">
<!--Open log file-->
<message>Open log file</message>
</output>
</outputs> </outputs>
</local> </local>

View File

@ -50,5 +50,13 @@
<!--Manual check for updated apps completed--> <!--Manual check for updated apps completed-->
<message>Manual check for updated apps completed...</message> <message>Manual check for updated apps completed...</message>
</output> </output>
<output id="10">
<!--See changelog-->
<message>See changelog</message>
</output>
<output id="11">
<!--Open log file-->
<message>Open log file</message>
</output>
</outputs> </outputs>
</local> </local>

View File

@ -50,5 +50,13 @@
<!--Manual check for updated apps completed--> <!--Manual check for updated apps completed-->
<message>Recherche de mises à jour terminée.</message> <message>Recherche de mises à jour terminée.</message>
</output> </output>
<output id="10">
<!--See changelog-->
<message>Consulter le journal des modifications</message>
</output>
<output id="11">
<!--Open log file-->
<message>Ouvrir le fichier log</message>
</output>
</outputs> </outputs>
</local> </local>

View File

@ -50,5 +50,13 @@
<!--Manual check for updated apps completed--> <!--Manual check for updated apps completed-->
<message>A frissített alkalmazások kézi ellenőrzése befejeződött...</message> <message>A frissített alkalmazások kézi ellenőrzése befejeződött...</message>
</output> </output>
<output id="10">
<!--See changelog-->
<message>See changelog</message>
</output>
<output id="11">
<!--Open log file-->
<message>Open log file</message>
</output>
</outputs> </outputs>
</local> </local>

View File

@ -50,5 +50,13 @@
<!--Manual check for updated apps completed--> <!--Manual check for updated apps completed-->
<message>Manual check for updated apps completed...</message> <message>Manual check for updated apps completed...</message>
</output> </output>
<output id="10">
<!--See changelog-->
<message>See changelog</message>
</output>
<output id="11">
<!--Open log file-->
<message>Open log file</message>
</output>
</outputs> </outputs>
</local> </local>

View File

@ -50,5 +50,13 @@
<!--Manual check for updated apps completed--> <!--Manual check for updated apps completed-->
<message>Manual check for updated apps completed...</message> <message>Manual check for updated apps completed...</message>
</output> </output>
<output id="10">
<!--See changelog-->
<message>See changelog</message>
</output>
<output id="11">
<!--Open log file-->
<message>Open log file</message>
</output>
</outputs> </outputs>
</local> </local>

View File

@ -50,5 +50,13 @@
<!--Manual check for updated apps completed--> <!--Manual check for updated apps completed-->
<message>Manual check for updated apps completed...</message> <message>Manual check for updated apps completed...</message>
</output> </output>
<output id="10">
<!--See changelog-->
<message>See changelog</message>
</output>
<output id="11">
<!--Open log file-->
<message>Open log file</message>
</output>
</outputs> </outputs>
</local> </local>

View File

@ -50,5 +50,13 @@
<!--Manual check for updated apps completed--> <!--Manual check for updated apps completed-->
<message>Manuell koll efter uppdaterade appar slutförd...</message> <message>Manuell koll efter uppdaterade appar slutförd...</message>
</output> </output>
<output id="10">
<!--See changelog-->
<message>See changelog</message>
</output>
<output id="11">
<!--Open log file-->
<message>Open log file</message>
</output>
</outputs> </outputs>
</local> </local>