From 55c4efdc69a6f6236ab5b3fa10117918d0c9de7a Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 7 Apr 2023 13:29:55 +0200 Subject: [PATCH 1/2] Variables from User-Run moved --- Winget-AutoUpdate/User-Run.ps1 | 4 ---- Winget-AutoUpdate/functions/Start-NotifTask.ps1 | 7 +++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Winget-AutoUpdate/User-Run.ps1 b/Winget-AutoUpdate/User-Run.ps1 index e3f8151..9ecef3b 100644 --- a/Winget-AutoUpdate/User-Run.ps1 +++ b/Winget-AutoUpdate/User-Run.ps1 @@ -44,10 +44,6 @@ Get-NotifLocale #Set common variables $OnClickAction = "$WorkingDir\logs\updates.log" $Button1Text = $NotifLocale.local.outputs.output[11].message -#The variables afterwards are used within Start-NotifTask.ps1 -$Title = "Winget-AutoUpdate (WAU)" -$Balise = "Winget-AutoUpdate (WAU)" -$UserRun = $True if ($Logs) { if (Test-Path "$WorkingDir\logs\updates.log") { diff --git a/Winget-AutoUpdate/functions/Start-NotifTask.ps1 b/Winget-AutoUpdate/functions/Start-NotifTask.ps1 index e78062d..d01e128 100644 --- a/Winget-AutoUpdate/functions/Start-NotifTask.ps1 +++ b/Winget-AutoUpdate/functions/Start-NotifTask.ps1 @@ -14,6 +14,13 @@ function Start-NotifTask { [Switch]$ButtonDismiss = $false ) + $caller = Get-ChildItem $MyInvocation.PSCommandPath | Select-Object -Expand Name + if ($caller -eq "User-Run.ps1") { + $Title = "Winget-AutoUpdate (WAU)" + $Balise = "Winget-AutoUpdate (WAU)" + $UserRun = $True + } + if (($WAUConfig.WAU_NotificationLevel -eq "Full") -or ($WAUConfig.WAU_NotificationLevel -eq "SuccessOnly" -and $MessageType -eq "Success") -or ($UserRun)) { # XML Toast template creation From b9139542cedd3df959d86de0295cd5798496fdf6 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Mon, 10 Apr 2023 21:10:15 +0200 Subject: [PATCH 2/2] Better by Romain --- Winget-AutoUpdate/User-Run.ps1 | 10 +++++----- Winget-AutoUpdate/functions/Start-NotifTask.ps1 | 10 ++-------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Winget-AutoUpdate/User-Run.ps1 b/Winget-AutoUpdate/User-Run.ps1 index 9ecef3b..176fb26 100644 --- a/Winget-AutoUpdate/User-Run.ps1 +++ b/Winget-AutoUpdate/User-Run.ps1 @@ -53,7 +53,7 @@ if ($Logs) { #Not available yet $Message = $NotifLocale.local.outputs.output[5].message $MessageType = "warning" - Start-NotifTask -Message $Message -MessageType $MessageType + Start-NotifTask -Message $Message -MessageType $MessageType -UserRun } } elseif ($Help) { @@ -65,7 +65,7 @@ else { if (Test-WAUisRunning) { $Message = $NotifLocale.local.outputs.output[8].message $MessageType = "warning" - Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss + Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss -UserRun break } #Run scheduled task @@ -73,7 +73,7 @@ else { #Starting check - Send notification $Message = $NotifLocale.local.outputs.output[6].message $MessageType = "info" - Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss + Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss -UserRun #Sleep until the task is done While (Test-WAUisRunning) { Start-Sleep 3 @@ -91,12 +91,12 @@ else { $MessageType = "success" $Message = $NotifLocale.local.outputs.output[9].message } - Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss + Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss -UserRun } catch { #Check failed - Just send notification $Message = $NotifLocale.local.outputs.output[7].message $MessageType = "error" - Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss + Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss -UserRun } } diff --git a/Winget-AutoUpdate/functions/Start-NotifTask.ps1 b/Winget-AutoUpdate/functions/Start-NotifTask.ps1 index d01e128..6ffae41 100644 --- a/Winget-AutoUpdate/functions/Start-NotifTask.ps1 +++ b/Winget-AutoUpdate/functions/Start-NotifTask.ps1 @@ -11,16 +11,10 @@ function Start-NotifTask { [String]$Body, [String]$Button1Text, [String]$Button1Action, - [Switch]$ButtonDismiss = $false + [Switch]$ButtonDismiss = $false, + [Switch]$UserRun = $false ) - $caller = Get-ChildItem $MyInvocation.PSCommandPath | Select-Object -Expand Name - if ($caller -eq "User-Run.ps1") { - $Title = "Winget-AutoUpdate (WAU)" - $Balise = "Winget-AutoUpdate (WAU)" - $UserRun = $True - } - if (($WAUConfig.WAU_NotificationLevel -eq "Full") -or ($WAUConfig.WAU_NotificationLevel -eq "SuccessOnly" -and $MessageType -eq "Success") -or ($UserRun)) { # XML Toast template creation