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"
}
elseif ($NotifApproved){
$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 = "$WingetUpdatePath\config\NotifApproved.txt"
$WAUNotifApprovedPath = "$WorkingDir\config\NotifApproved.txt"
New-Item $WAUNotifApprovedPath -Force
if ($NotifApproved -like "*system"){
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
}
}

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 $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 {