Skip to content

Commit

Permalink
Merge pull request #54 from Romanitho/Wix-V5
Browse files Browse the repository at this point in the history
add user-run.ps1 back
  • Loading branch information
Romanitho authored Aug 22, 2024
2 parents bde1d5e + b5e1610 commit 04a8c49
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 69 deletions.
99 changes: 35 additions & 64 deletions Sources/Winget-AutoUpdate/User-Run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions Sources/Winget-AutoUpdate/Winget-Upgrade.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ if (Test-Network) {
if ($Winget) {

if ($IsSystem) {

#Get Current Version
$WAUCurrentVersion = $WAUConfig.ProductVersion
Write-ToLog "WAU current version: $WAUCurrentVersion"
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions Sources/Wix/build.wxs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">

<!-- Product Config -->
<Package Language="1033" Name="Winget-AutoUpdate" Version="$(var.Version)" Manufacturer="Romanitho" UpgradeCode="BDDEA607-F4AF-4229-8610-16E3B6455FDC" InstallerVersion="200"><!-- Package Config -->
<Package Language="1033" Name="Winget-AutoUpdate" Version="$(var.Version)" Manufacturer="Romanitho" UpgradeCode="BDDEA607-F4AF-4229-8610-16E3B6455FDC" InstallerVersion="200">

<!-- Package Config -->
<SummaryInformation Description="WAU (x64) [$(var.Version)]" />
<Icon Id="icon.ico" SourceFile=".\files\icon.ico" />
<WixVariable Id="WixUIBannerBmp" Value=".\files\banner.bmp"></WixVariable>
Expand Down Expand Up @@ -348,7 +350,7 @@
<RegistryKey Root="HKCU" Key="SOFTWARE\[Manufacturer]\[ProductName]">
<RegistryValue Name="WAU_DesktopShortcut" Type="integer" Value="[DESKTOPSHORTCUT]" KeyPath="yes" />
</RegistryKey>
<Shortcut Id="DesktopShortcut" Name="Run WAU" Target="[System64Folder]conhost.exe" Arguments="--headless [System64Folder]schtasks.exe -run -tn WAU\Winget-AutoUpdate" Icon="icon.ico" />
<Shortcut Id="DesktopShortcut" Name="Run WAU" Target="[System64Folder]conhost.exe" Arguments="--headless powershell.exe -NoProfile -ExecutionPolicy Bypass -File &quot;[INSTALLDIR]User-Run.ps1&quot;" Icon="icon.ico" />
</Component>
</StandardDirectory>
<StandardDirectory Id="ProgramMenuFolder">
Expand All @@ -357,7 +359,7 @@
<RegistryKey Root="HKCU" Key="SOFTWARE\[Manufacturer]\[ProductName]">
<RegistryValue Name="WAU_StartMenuShortcut" Type="integer" Value="[STARTMENUSHORTCUT]" KeyPath="yes" />
</RegistryKey>
<Shortcut Id="StartMenuShortcut1" Name="Run WAU" Target="[System64Folder]conhost.exe" Arguments="--headless [System64Folder]schtasks.exe -run -tn WAU\Winget-AutoUpdate" Icon="icon.ico" />
<Shortcut Id="StartMenuShortcut1" Name="Run WAU" Target="[System64Folder]conhost.exe" Arguments="--headless powershell.exe -NoProfile -ExecutionPolicy Bypass -File &quot;[INSTALLDIR]User-Run.ps1&quot;" Icon="icon.ico" />
<Shortcut Id="StartMenuShortcut2" Name="Open log" Target="[INSTALLDIR]logs\updates.log" />
<RemoveFolder Id="WAU" On="uninstall" />
</Component>
Expand Down

0 comments on commit 04a8c49

Please sign in to comment.