From c7495059fd4b2d1096a2934bfd914691b462f1cf Mon Sep 17 00:00:00 2001 From: Chris Titus Tech Date: Thu, 18 Sep 2025 10:26:11 -0500 Subject: [PATCH] Offline Capabilities --- Compile.ps1 | 2 +- .../Test-WinUtilInternetConnection.ps1 | 26 ++++++++++++++++ scripts/main.ps1 | 30 ++++++++++++++++++- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 functions/private/Test-WinUtilInternetConnection.ps1 diff --git a/Compile.ps1 b/Compile.ps1 index d4bb3718..fc6290b3 100644 --- a/Compile.ps1 +++ b/Compile.ps1 @@ -51,7 +51,7 @@ Update-Progress "Pre-req: Running Preprocessor..." 0 $preprocessingFilePath = ".\tools\Invoke-Preprocessing.ps1" . $preprocessingFilePath -$excludedFiles = @('.\.git\', '.\.gitignore', '.\.gitattributes', '.\.github\CODEOWNERS', '.\LICENSE', "$preprocessingFilePath", '*.png', '*.exe','.\.preprocessor_hashes.json') +$excludedFiles = @('.\.git\', '.\binary\', '.\.gitignore', '.\.gitattributes', '.\.github\CODEOWNERS', '.\LICENSE', "$preprocessingFilePath", '*.png', '*.exe','.\.preprocessor_hashes.json') $msg = "Pre-req: Code Formatting" Invoke-Preprocessing -WorkingDir "$workingdir" -ExcludedFiles $excludedFiles -ProgressStatusMessage $msg diff --git a/functions/private/Test-WinUtilInternetConnection.ps1 b/functions/private/Test-WinUtilInternetConnection.ps1 new file mode 100644 index 00000000..17ef23d2 --- /dev/null +++ b/functions/private/Test-WinUtilInternetConnection.ps1 @@ -0,0 +1,26 @@ +function Test-WinUtilInternetConnection { + <# + .SYNOPSIS + Tests if the computer has internet connectivity + .OUTPUTS + Boolean - True if connected, False if offline + #> + try { + # Test multiple reliable endpoints + $testSites = @( + "8.8.8.8", # Google DNS + "1.1.1.1", # Cloudflare DNS + "208.67.222.222" # OpenDNS + ) + + foreach ($site in $testSites) { + if (Test-Connection -ComputerName $site -Count 1 -Quiet -TimeoutSeconds 3 -ErrorAction SilentlyContinue) { + return $true + } + } + return $false + } + catch { + return $false + } +} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 47b3b339..13914e31 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -310,7 +310,35 @@ $sync["Form"].Add_ContentRendered({ Write-Debug "Unable to retrieve information about the primary monitor." } - Invoke-WPFTab "WPFTab1BT" + # Check internet connectivity and disable install tab if offline + $isOnline = Test-WinUtilInternetConnection + + if (-not $isOnline) { + # Disable the install tab + $sync.WPFTab1BT.IsEnabled = $false + $sync.WPFTab1BT.Opacity = 0.5 + $sync.WPFTab1BT.ToolTip = "Internet connection required for installing applications" + + # Disable install-related buttons + $sync.WPFInstall.IsEnabled = $false + $sync.WPFUninstall.IsEnabled = $false + $sync.WPFInstallUpgrade.IsEnabled = $false + $sync.WPFGetInstalled.IsEnabled = $false + + # Show offline indicator + Write-Host "Offline mode detected - Install tab disabled" -ForegroundColor Yellow + + # Optionally switch to a different tab if install tab was going to be default + Invoke-WPFTab "WPFTab2BT" # Switch to Tweaks tab instead + } + else { + # Online - ensure install tab is enabled + $sync.WPFTab1BT.IsEnabled = $true + $sync.WPFTab1BT.Opacity = 1.0 + $sync.WPFTab1BT.ToolTip = $null + Invoke-WPFTab "WPFTab1BT" # Default to install tab + } + $sync["Form"].Focus() # maybe this is not the best place to load and execute config file?