From 74856cdecc7598715fd473e0cc7ea5543b63d9c9 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Mon, 24 Apr 2023 01:49:20 +0200 Subject: [PATCH] testing --- Winget-AutoUpdate/User-Run.ps1 | 38 ++++++++++++++----- Winget-AutoUpdate/Winget-Upgrade.ps1 | 2 +- .../functions/Invoke-UserApproval.ps1 | 13 +++++-- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Winget-AutoUpdate/User-Run.ps1 b/Winget-AutoUpdate/User-Run.ps1 index ff71dfb..a3e2057 100644 --- a/Winget-AutoUpdate/User-Run.ps1 +++ b/Winget-AutoUpdate/User-Run.ps1 @@ -61,13 +61,33 @@ elseif ($Help) { Start-Process "https://github.com/Romanitho/Winget-AutoUpdate" } elseif ($NotifApproved){ - #Create tag if user approve notif for requested updates - $WAUNotifApprovedPath = "$WingetUpdatePath\config\NotifApproved.txt" - New-Item $WAUNotifApprovedPath -Force - if ($NotifApproved -like "*system"){ + $MessageBody = "Do you want to update these apps ?`n`n" + $MessageBody += Get-Content "$WorkingDir/config/NotifContent.txt" -Raw + $Title = "Winget-AutoUpdate" + if ($NotifApproved -eq "wau:systemDialogBox"){ + Add-Type -AssemblyName PresentationCore,PresentationFramework + $Result = [System.Windows.MessageBox]::Show($MessageBody,$Title,4,32) + if ($Result -eq "Yes") { + $NotifApproved = "wau:system" + } + } + if ($NotifApproved -eq "wau:userDialogBox"){ + Add-Type -AssemblyName PresentationCore,PresentationFramework + $Result = [System.Windows.MessageBox]::Show($MessageBody,$Title,4,32) + if ($Result -eq "Yes") { + $NotifApproved = "wau:user" + } + } + if ($NotifApproved -eq "wau:system"){ + #Create tag if user approve notif for requested updates + $WAUNotifApprovedPath = "$WorkingDir\config\NotifApproved.txt" + New-Item $WAUNotifApprovedPath -Force Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction Stop | Start-ScheduledTask -ErrorAction Stop } - else{ + if ($NotifApproved -eq "wau:user"){ + #Create tag if user approve notif for requested updates + $WAUNotifApprovedPath = "$WorkingDir\config\NotifApproved.txt" + New-Item $WAUNotifApprovedPath -Force Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction Stop | Start-ScheduledTask -ErrorAction Stop } } @@ -77,7 +97,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 -UserRun + Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -UserRun break } #Run scheduled task @@ -85,7 +105,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 -UserRun + Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -UserRun #Sleep until the task is done While (Test-WAUisRunning) { Start-Sleep 3 @@ -105,13 +125,13 @@ else { } $IsUserApprovalEnable = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\" -Name WAU_UserApproval -ErrorAction SilentlyContinue).WAU_UserApproval if ($IsUserApprovalEnable -ne "1"){ - Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss -UserRun + Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -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 -UserRun + Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -UserRun } } diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index dbba189..461b7dc 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -243,7 +243,7 @@ if (Test-Network) { #Check for approved tag $WAUNotifApproved = "$WorkingDir/Config/NotifApproved.txt" if (Test-Path $WAUNotifApproved) { - Write-ToLog "-> User approved notification." + Write-ToLog "-> User approved notification." Remove-Item $WAUNotifApproved -Force -Confirm:$false } else { diff --git a/Winget-AutoUpdate/functions/Invoke-UserApproval.ps1 b/Winget-AutoUpdate/functions/Invoke-UserApproval.ps1 index fbcc78d..4b2f8c7 100644 --- a/Winget-AutoUpdate/functions/Invoke-UserApproval.ps1 +++ b/Winget-AutoUpdate/functions/Invoke-UserApproval.ps1 @@ -13,9 +13,11 @@ function Invoke-UserApproval ($outdated){ New-ItemProperty -LiteralPath $WAUClass -Name 'EditFlags' -Value '2162688' -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null New-ItemProperty -LiteralPath $WAUClassCmd -Name '(default)' -Value $WAUClassRun -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null $Button1Action = "wau:system" + $OnClickAction = "wau:systemDialogBox" } else{ $Button1Action = "wau:user" + $OnClickAction = "wau:userDialogBox" } $OutdatedApps = @() @@ -24,7 +26,7 @@ function Invoke-UserApproval ($outdated){ $toUpdate = Get-IncludedApps foreach ($app in $Outdated) { if (($toUpdate -contains $app.Id) -and $($app.Version) -ne "Unknown") { - $OutdatedApps += $app.Name + $OutdatedApps += "- $($app.Name)" } } } @@ -33,7 +35,7 @@ function Invoke-UserApproval ($outdated){ $toSkip = Get-ExcludedApps foreach ($app in $Outdated) { if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown") { - $OutdatedApps += $app.Name + $OutdatedApps += "- $($app.Name)" } } } @@ -41,7 +43,12 @@ function Invoke-UserApproval ($outdated){ $body = $OutdatedApps | Out-String if ($body) { #Ask user to update apps - Start-NotifTask -Title "New available updates" -Message "Do you want to update these apps ?" -Body $body -ButtonDismiss -Button1Text "Yes" -Button1Action $Button1Action -MessageType "info" + $Message = "Do you want to update these apps ?" + $body += "`nPlease save your work and close theses apps" + $WAUNotifContent = "$WorkingDir\config\NotifContent.txt" + New-Item -Path $WAUNotifContent -ItemType File -Force | Out-Null + Set-Content -Path $WAUNotifContent -Value $body + Start-NotifTask -Title "New available updates" -Message $Message -Body $body -ButtonDismiss -Button1Text "Yes" -Button1Action $Button1Action -OnClickAction $OnClickAction -MessageType "info" Return 0 } else {