wingetautoupdate/Winget-AutoUpdate/functions/Invoke-UserApproval.ps1

41 lines
1.5 KiB
PowerShell
Raw Normal View History

2023-02-06 18:16:01 +00:00
#Function to ask user consent before updating apps
2023-05-10 15:51:18 +00:00
function Invoke-UserApproval ($Apps){
2023-02-06 18:16:01 +00:00
2023-05-10 15:51:18 +00:00
$WAUNotifApproved = "$WorkingDir/Config/NotifApproved.txt"
$WAUNotifAppList = "$WorkingDir/Config/NotifAppList.csv"
#Check for approved file
if (Test-Path $WAUNotifApproved) {
Write-ToLog "-> User approved update notification."
$AppListToUpdate = Import-Csv $WAUNotifAppList
Remove-Item $WAUNotifApproved -Force -Confirm:$false
Remove-Item $WAUNotifAppList -Force -Confirm:$false
2023-02-06 18:16:01 +00:00
}
2023-05-10 15:51:18 +00:00
#Otherwise generate AppList and send notif
2023-02-06 18:16:01 +00:00
else {
2023-05-10 15:51:18 +00:00
Write-ToLog "-> Creating AppList user must approve"
$Apps | Export-Csv -Path $WAUNotifAppList -NoTypeInformation -Encoding UTF8
if ($IsSystem) {
$Button1Action = "wau:system"
$OnClickAction = "wau:systemDialogBox"
}
else{
$Button1Action = "wau:user"
$OnClickAction = "wau:userDialogBox"
2023-02-06 18:16:01 +00:00
}
#Ask user to update apps
2023-05-10 15:51:18 +00:00
$body = $Apps.Name | Out-String
2023-04-23 23:49:20 +00:00
$Message = "Do you want to update these apps ?"
$body += "`nPlease save your work and close theses apps"
Start-NotifTask -Title "New available updates" -Message $Message -Body $body -ButtonDismiss -Button1Text "Yes" -Button1Action $Button1Action -OnClickAction $OnClickAction -MessageType "info"
2023-05-10 15:51:18 +00:00
Write-ToLog "-> User approval requested. Waiting for user to approve available updates... Closing for now."
#Closing job, waiting for user approval
Exit 0
2023-02-06 18:16:01 +00:00
}
}