Merge branch 'user-approval' into temp

pull/329/head
Romain 2023-04-23 11:29:18 +02:00 committed by GitHub
commit fbce63eba4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 89 additions and 4 deletions

View File

@ -269,7 +269,7 @@ function Install-WingetAutoUpdate {
}
}
# Set dummy regkeys for notification name and icon
# Set regkeys for notification name, icon and actions
& reg add "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /v DisplayName /t REG_EXPAND_SZ /d "Application Update" /f | Out-Null
& reg add "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /v IconUri /t REG_EXPAND_SZ /d %SystemRoot%\system32\@WindowsUpdateToastIcon.png /f | Out-Null
@ -298,7 +298,12 @@ function Install-WingetAutoUpdate {
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 03:00:00
# Set up the task, and register it
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings -Trigger $taskTriggers
if ($taskTriggers) {
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings -Trigger $taskTriggers
}
else {
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
}
Register-ScheduledTask -TaskName 'Winget-AutoUpdate' -InputObject $task -Force | Out-Null
if ($InstallUserContext) {
@ -440,6 +445,7 @@ function Uninstall-WingetAutoUpdate {
Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
& reg delete "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /f | Out-Null
& reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" /f | Out-Null
& reg delete "HKLM\Software\Classes\WAU" /f | Out-Null
if ((Test-Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)")) {
Remove-Item -Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)" -Recurse -Force | Out-Null

View File

@ -20,7 +20,9 @@ https://github.com/Romanitho/Winget-AutoUpdate
[CmdletBinding()]
param(
[Parameter(Mandatory = $False)] [Switch] $Logs = $false,
[Parameter(Mandatory = $False)] [Switch] $Help = $false
[Parameter(Mandatory = $False)] [Switch] $Help = $false,
[Parameter(Mandatory = $False)] [Switch] $NotifApprovedAsSystem = $false,
[Parameter(Mandatory = $False)] [Switch] $NotifApprovedAsUser = $false
)
function Test-WAUisRunning {
@ -59,6 +61,18 @@ if ($Logs) {
elseif ($Help) {
Start-Process "https://github.com/Romanitho/Winget-AutoUpdate"
}
elseif ($NotifApprovedAsUser){
#Create tag if user approve notif for requested updates
$WAUNotifApprovedPath = "$WingetUpdatePath\config\NotifApproved.txt"
New-Item $WAUNotifApprovedPath -Force
Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
}
elseif ($NotifApprovedAsSystem){
#Create tag if user approve notif for requested updates
$WAUNotifApprovedPath = "$WingetUpdatePath\config\NotifApproved.txt"
New-Item $WAUNotifApprovedPath -Force
Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
}
else {
try {
#Check if WAU is currently running

View File

@ -52,6 +52,7 @@ try {
Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
& reg delete "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /f | Out-Null
& reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" /f | Out-Null
& reg delete "HKLM\Software\Classes\WAU" /f | Out-Null
if (Test-Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate") {
& reg delete "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" /f | Out-Null
}

View File

@ -214,6 +214,20 @@ function Invoke-PostUpdateActions {
}
}
#Add WAU Class to run if not exesting
$WAUClass = "HKLM:\Software\Classes\WAU"
if (!(Test-Path $WAUClass)) {
$WAUClassRun = "Wscript.exe ""$WorkingDir\Invisible.vbs"" ""C:\Windows\System32\schtasks.exe /run /tn Winget-AutoUpdate"""
New-Item "HKLM:\Software\Classes\$($ActionType)\shell\open\command" -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -LiteralPath $WAUClass -Name 'URL Protocol' -Value '' -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -LiteralPath $WAUClass -Name '(default)' -Value "URL:$($ActionType)" -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -LiteralPath $WAUClass -Name 'EditFlags' -Value '2162688' -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -LiteralPath "$WAUClass\shell\open\command" -Name '(default)' -Value $WAUClassRun -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null
#log
Write-Log "-> WAU Notification Action declared." "green"
}
#Reset WAU_UpdatePostActions Value
$WAUConfig | New-ItemProperty -Name WAU_PostUpdateActions -Value 0 -Force

View File

@ -0,0 +1,50 @@
#Function to ask user consent before updating apps
function Invoke-UserApproval ($outdated){
#Create / Update WAU Class for notification action
$WAUClass = "HKLM:\Software\Classes\WAU"
$WAUClassCmd = "$WAUClass\shell\open\command"
if ($IsSystem){
$WAUClassRun = "Wscript.exe ""$WingetUpdatePath\Invisible.vbs"" ""powershell.exe -NoProfile -ExecutionPolicy Bypass -File '$WingetUpdatePath\User-Run.ps1' -NotifApprovedAsSystem"
}
else{
$WAUClassRun = "Wscript.exe ""$WingetUpdatePath\Invisible.vbs"" ""powershell.exe -NoProfile -ExecutionPolicy Bypass -File '$WingetUpdatePath\User-Run.ps1' -NotifApprovedAsUser"
}
New-Item $WAUClassCmd -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -LiteralPath $WAUClass -Name 'URL Protocol' -Value '' -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -LiteralPath $WAUClass -Name '(default)' -Value "URL:$($ActionType)" -PropertyType String -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
$OutdatedApps = @()
#If White List
if ($WAUConfig.WAU_UseWhiteList -eq 1) {
$toUpdate = Get-IncludedApps
foreach ($app in $Outdated) {
if (($toUpdate -contains $app.Id) -and $($app.Version) -ne "Unknown") {
$OutdatedApps += $app.Name
}
}
}
#If Black List or default
else {
$toSkip = Get-ExcludedApps
foreach ($app in $Outdated) {
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown") {
$OutdatedApps += $app.Name
}
}
}
$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 "wau:1" -MessageType "info"
Return 0
}
else {
Return 1
}
}

View File

@ -15,7 +15,7 @@ function Start-NotifTask {
[Switch]$UserRun = $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 (!$IsSystem)) {
# XML Toast template creation
[xml]$ToastTemplate = New-Object system.Xml.XmlDocument