pull/329/head^2
romanitho 2023-02-06 19:16:01 +01:00
parent 65bfd5bafc
commit eea0a0ee53
4 changed files with 91 additions and 15 deletions

View File

@ -271,13 +271,6 @@ function Install-WingetAutoUpdate {
# 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
$WAUClass = "HKLM:\Software\Classes\WAU"
$WAUClassRun = "Wscript.exe ""$WingetUpdatePath\Invisible.vbs"" ""C:\Windows\System32\schtasks.exe /run /tn Winget-AutoUpdate"""
New-Item "$WAUClass\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
# Settings for the scheduled task for Updates
$taskAction = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$($WingetUpdatePath)\winget-upgrade.ps1`""

View File

@ -1,6 +1,6 @@
<#
.SYNOPSIS
Handle user interaction from shortcuts and show a Toast
Handle user interaction from shortcuts and Toast
.DESCRIPTION
Act on shortcut run (DEFAULT: Check for updated Apps)
@ -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 {
@ -44,9 +46,6 @@ Get-NotifLocale
#Set common variables
$OnClickAction = "$WorkingDir\logs\updates.log"
$Button1Text = $NotifLocale.local.outputs.output[11].message
$Title = "Winget-AutoUpdate (WAU)"
$Balise = "Winget-AutoUpdate (WAU)"
$UserRun = $True
if ($Logs) {
if (Test-Path "$WorkingDir\logs\updates.log") {
@ -62,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

@ -41,7 +41,7 @@ if ($IsSystem) {
else {
[int32] $MaxLogFiles = $MaxLogFiles
}
# Maximum size of log file.
$MaxLogSize = $WAUConfig.WAU_MaxLogSize
if (!$MaxLogSize) {
@ -136,7 +136,7 @@ if (Test-Network) {
}
}
}
#Get External ModsPath if run as System
if ($WAUConfig.WAU_ModsPath) {
Write-Log "WAU uses External Mods from: $($WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/"))"
@ -219,6 +219,28 @@ if (Test-Network) {
$Log | out-file -filepath $LogFile -Append
}
#Ask for user if configured
if ($WAUConfig.WAU_UserApproval -eq 1){
Write-Log "User Approval feature enabled."
#Check for approved tag
$WAUNotifApproved = "$WorkingDir/Config/NotifApproved.txt"
if (!(Test-Path $WAUNotifApproved)) {
$UserApprovalReturn = Invoke-UserApproval $outdated
if ($UserApprovalReturn -eq 0){
Write-Log "-> User approval requested. Waiting for user to approve available updates..."
#Closing job, waiting for user approval
Exit 0
}
else{
Write-log "-> No update to request to user."
}
}
else {
Write-Log "-> User approved notification."
}
}
#Count good update installations
$Script:InstallOK = 0
@ -297,7 +319,7 @@ if (Test-Network) {
elseif (!$UserScheduledTask){
Write-Log "User context execution not installed..."
}
}
}
}
}
else {

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
}
}