pull/339/head^2
Romain 2023-04-24 01:49:20 +02:00 committed by GitHub
parent 881ce2ddc1
commit 74856cdecc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 13 deletions

View File

@ -61,13 +61,33 @@ elseif ($Help) {
Start-Process "https://github.com/Romanitho/Winget-AutoUpdate" Start-Process "https://github.com/Romanitho/Winget-AutoUpdate"
} }
elseif ($NotifApproved){ elseif ($NotifApproved){
#Create tag if user approve notif for requested updates $MessageBody = "Do you want to update these apps ?`n`n"
$WAUNotifApprovedPath = "$WingetUpdatePath\config\NotifApproved.txt" $MessageBody += Get-Content "$WorkingDir/config/NotifContent.txt" -Raw
New-Item $WAUNotifApprovedPath -Force $Title = "Winget-AutoUpdate"
if ($NotifApproved -like "*system"){ 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 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 Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction Stop | Start-ScheduledTask -ErrorAction Stop
} }
} }
@ -77,7 +97,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 -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss -UserRun Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -UserRun
break break
} }
#Run scheduled task #Run scheduled task
@ -85,7 +105,7 @@ 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 -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 #Sleep until the task is done
While (Test-WAUisRunning) { While (Test-WAUisRunning) {
Start-Sleep 3 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 $IsUserApprovalEnable = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\" -Name WAU_UserApproval -ErrorAction SilentlyContinue).WAU_UserApproval
if ($IsUserApprovalEnable -ne "1"){ 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 { 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 -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss -UserRun Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -UserRun
} }
} }

View File

@ -243,7 +243,7 @@ if (Test-Network) {
#Check for approved tag #Check for approved tag
$WAUNotifApproved = "$WorkingDir/Config/NotifApproved.txt" $WAUNotifApproved = "$WorkingDir/Config/NotifApproved.txt"
if (Test-Path $WAUNotifApproved) { if (Test-Path $WAUNotifApproved) {
Write-ToLog "-> User approved notification." Write-ToLog "-> User approved notification."
Remove-Item $WAUNotifApproved -Force -Confirm:$false Remove-Item $WAUNotifApproved -Force -Confirm:$false
} }
else { else {

View File

@ -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 $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 New-ItemProperty -LiteralPath $WAUClassCmd -Name '(default)' -Value $WAUClassRun -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null
$Button1Action = "wau:system" $Button1Action = "wau:system"
$OnClickAction = "wau:systemDialogBox"
} }
else{ else{
$Button1Action = "wau:user" $Button1Action = "wau:user"
$OnClickAction = "wau:userDialogBox"
} }
$OutdatedApps = @() $OutdatedApps = @()
@ -24,7 +26,7 @@ function Invoke-UserApproval ($outdated){
$toUpdate = Get-IncludedApps $toUpdate = Get-IncludedApps
foreach ($app in $Outdated) { foreach ($app in $Outdated) {
if (($toUpdate -contains $app.Id) -and $($app.Version) -ne "Unknown") { 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 $toSkip = Get-ExcludedApps
foreach ($app in $Outdated) { foreach ($app in $Outdated) {
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown") { 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 $body = $OutdatedApps | Out-String
if ($body) { if ($body) {
#Ask user to update apps #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 Return 0
} }
else { else {