2022-10-11 14:55:17 +00:00
|
|
|
<#
|
2023-10-03 08:18:00 +00:00
|
|
|
.SYNOPSIS
|
|
|
|
Handle user interaction from shortcuts and show a Toast notification
|
2022-10-11 14:55:17 +00:00
|
|
|
|
2023-10-03 08:18:00 +00:00
|
|
|
.DESCRIPTION
|
2024-09-13 20:06:18 +00:00
|
|
|
Act on shortcut run
|
2022-10-11 14:55:17 +00:00
|
|
|
|
2023-10-03 08:18:00 +00:00
|
|
|
.EXAMPLE
|
2024-09-13 20:06:18 +00:00
|
|
|
.\user-run.ps1
|
2022-10-11 14:55:17 +00:00
|
|
|
|
|
|
|
#>
|
|
|
|
|
2023-10-03 08:18:00 +00:00
|
|
|
function Test-WAUisRunning {
|
|
|
|
If (((Get-ScheduledTask -TaskName 'Winget-AutoUpdate').State -eq 'Running') -or ((Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext').State -eq 'Running')) {
|
|
|
|
Return $True
|
|
|
|
}
|
2022-10-17 12:23:14 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 14:55:17 +00:00
|
|
|
<# MAIN #>
|
|
|
|
|
|
|
|
#Get Working Dir
|
2022-10-11 16:06:21 +00:00
|
|
|
$Script:WorkingDir = $PSScriptRoot
|
2022-10-11 14:55:17 +00:00
|
|
|
|
2022-10-17 12:23:14 +00:00
|
|
|
#Load external functions
|
2022-10-11 16:04:25 +00:00
|
|
|
. $WorkingDir\functions\Get-NotifLocale.ps1
|
|
|
|
. $WorkingDir\functions\Start-NotifTask.ps1
|
2022-10-11 14:55:17 +00:00
|
|
|
|
2022-10-26 23:52:40 +00:00
|
|
|
#Get Toast Locale function
|
|
|
|
Get-NotifLocale
|
|
|
|
|
2022-10-11 14:55:17 +00:00
|
|
|
#Set common variables
|
2023-10-03 08:18:00 +00:00
|
|
|
$OnClickAction = "$WorkingDir\logs\updates.log"
|
2022-10-26 23:26:02 +00:00
|
|
|
$Button1Text = $NotifLocale.local.outputs.output[11].message
|
2022-10-11 14:55:17 +00:00
|
|
|
|
2024-09-13 20:06:18 +00:00
|
|
|
try {
|
|
|
|
#Check if WAU is currently running
|
|
|
|
if (Test-WAUisRunning) {
|
|
|
|
$Message = $NotifLocale.local.outputs.output[8].message
|
2023-10-03 08:18:00 +00:00
|
|
|
$MessageType = "warning"
|
|
|
|
Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss -UserRun
|
2024-09-13 20:06:18 +00:00
|
|
|
break
|
2023-10-03 08:18:00 +00:00
|
|
|
}
|
2024-09-13 20:06:18 +00:00
|
|
|
#Run scheduled task
|
|
|
|
Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction Stop | Start-ScheduledTask -ErrorAction Stop
|
|
|
|
#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
|
|
|
|
#Sleep until the task is done
|
|
|
|
While (Test-WAUisRunning) {
|
|
|
|
Start-Sleep 3
|
|
|
|
}
|
|
|
|
|
|
|
|
#Test if there was a list_/winget_error
|
|
|
|
if (Test-Path "$WorkingDir\logs\error.txt") {
|
2023-10-03 08:18:00 +00:00
|
|
|
$MessageType = "error"
|
2024-09-13 20:06:18 +00:00
|
|
|
$Critical = Get-Content "$WorkingDir\logs\error.txt" -Raw
|
|
|
|
$Critical = $Critical.Trim()
|
|
|
|
$Critical = $Critical.Substring(0, [Math]::Min($Critical.Length, 50))
|
|
|
|
$Message = "Critical:`n$Critical..."
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$MessageType = "success"
|
|
|
|
$Message = $NotifLocale.local.outputs.output[9].message
|
2023-10-03 08:18:00 +00:00
|
|
|
}
|
2024-09-13 20:06:18 +00:00
|
|
|
Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss -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
|
2022-10-11 14:55:17 +00:00
|
|
|
}
|