From b5e161091db4c38713854cb77ebebff68c8d6d41 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Fri, 23 Aug 2024 00:53:13 +0200 Subject: [PATCH] user run --- Sources/Winget-AutoUpdate/User-Run.ps1 | 99 +++++++------------- Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 | 4 +- Sources/Wix/build.wxs | 8 +- 3 files changed, 42 insertions(+), 69 deletions(-) diff --git a/Sources/Winget-AutoUpdate/User-Run.ps1 b/Sources/Winget-AutoUpdate/User-Run.ps1 index 176fb26..094e132 100644 --- a/Sources/Winget-AutoUpdate/User-Run.ps1 +++ b/Sources/Winget-AutoUpdate/User-Run.ps1 @@ -3,26 +3,13 @@ Handle user interaction from shortcuts and show a Toast notification .DESCRIPTION -Act on shortcut run (DEFAULT: Check for updated Apps) - -.PARAMETER Logs -Open the Log file from Winget-AutoUpdate installation location - -.PARAMETER Help -Open the Web Help page -https://github.com/Romanitho/Winget-AutoUpdate +Act on shortcut run .EXAMPLE -.\user-run.ps1 -Logs +.\user-run.ps1 #> -[CmdletBinding()] -param( - [Parameter(Mandatory = $False)] [Switch] $Logs = $false, - [Parameter(Mandatory = $False)] [Switch] $Help = $false -) - function Test-WAUisRunning { If (((Get-ScheduledTask -TaskName 'Winget-AutoUpdate').State -eq 'Running') -or ((Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext').State -eq 'Running')) { Return $True @@ -45,58 +32,42 @@ Get-NotifLocale $OnClickAction = "$WorkingDir\logs\updates.log" $Button1Text = $NotifLocale.local.outputs.output[11].message -if ($Logs) { - if (Test-Path "$WorkingDir\logs\updates.log") { - Invoke-Item "$WorkingDir\logs\updates.log" - } - else { - #Not available yet - $Message = $NotifLocale.local.outputs.output[5].message +try { + #Check if WAU is currently running + if (Test-WAUisRunning) { + $Message = $NotifLocale.local.outputs.output[8].message $MessageType = "warning" - Start-NotifTask -Message $Message -MessageType $MessageType -UserRun - } -} -elseif ($Help) { - Start-Process "https://github.com/Romanitho/Winget-AutoUpdate" -} -else { - try { - #Check if WAU is currently running - if (Test-WAUisRunning) { - $Message = $NotifLocale.local.outputs.output[8].message - $MessageType = "warning" - Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss -UserRun - break - } - #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") { - $MessageType = "error" - $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 - } Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss -UserRun + break } - catch { - #Check failed - Just send notification - $Message = $NotifLocale.local.outputs.output[7].message + #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") { $MessageType = "error" - Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss -UserRun + $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 } + 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 } diff --git a/Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 index d403dd5..6696081 100644 --- a/Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -131,7 +131,7 @@ if (Test-Network) { if ($Winget) { if ($IsSystem) { - + #Get Current Version $WAUCurrentVersion = $WAUConfig.ProductVersion Write-ToLog "WAU current version: $WAUCurrentVersion" @@ -147,7 +147,7 @@ if (Test-Network) { #Get Available Version $Script:WAUAvailableVersion = Get-WAUAvailableVersion #Compare - if ([version]$WAUAvailableVersion -ne [version]$WAUCurrentVersion) { + if ([version]$WAUAvailableVersion -gt [version]$WAUCurrentVersion) { #If new version is available, update it Write-ToLog "WAU Available version: $WAUAvailableVersion" "Yellow" Update-WAU diff --git a/Sources/Wix/build.wxs b/Sources/Wix/build.wxs index 605cfb8..376b4a8 100644 --- a/Sources/Wix/build.wxs +++ b/Sources/Wix/build.wxs @@ -1,7 +1,9 @@ - + + + @@ -348,7 +350,7 @@ - + @@ -357,7 +359,7 @@ - +