mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2026-03-12 17:51:46 +08:00
Fix offline mode (#4153)
* Fix usb error on drive with no existing partitions * fix offline mode * Add offline banner
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
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 -ErrorAction SilentlyContinue) {
|
||||
return $true
|
||||
}
|
||||
}
|
||||
return $false
|
||||
}
|
||||
catch {
|
||||
return $false
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,14 @@ $maxthreads = [int]$env:NUMBER_OF_PROCESSORS
|
||||
$hashVars = New-object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'sync',$sync,$Null
|
||||
$debugVar = New-object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'DebugPreference',$DebugPreference,$Null
|
||||
$uiVar = New-object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'PARAM_NOUI',$PARAM_NOUI,$Null
|
||||
$offlineVar = New-object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'PARAM_OFFLINE',$PARAM_OFFLINE,$Null
|
||||
$InitialSessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
|
||||
|
||||
# Add the variable to the session state
|
||||
$InitialSessionState.Variables.Add($hashVars)
|
||||
$InitialSessionState.Variables.Add($debugVar)
|
||||
$InitialSessionState.Variables.Add($uiVar)
|
||||
$InitialSessionState.Variables.Add($offlineVar)
|
||||
|
||||
# Get every private function and add them to the session state
|
||||
$functions = Get-ChildItem function:\ | Where-Object { $_.Name -imatch 'winutil|WPF' }
|
||||
@@ -350,11 +352,10 @@ $sync["Form"].Add_ContentRendered({
|
||||
Write-Debug "Unable to retrieve information about the primary monitor."
|
||||
}
|
||||
|
||||
# Check internet connectivity and disable install tab if offline
|
||||
#$isOnline = Test-WinUtilInternetConnection
|
||||
$isOnline = $true # Temporarily force online mode until we can resolve false negatives
|
||||
if ($PARAM_OFFLINE) {
|
||||
# Show offline banner
|
||||
$sync.WPFOfflineBanner.Visibility = [System.Windows.Visibility]::Visible
|
||||
|
||||
if (-not $isOnline) {
|
||||
# Disable the install tab
|
||||
$sync.WPFTab1BT.IsEnabled = $false
|
||||
$sync.WPFTab1BT.Opacity = 0.5
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
param (
|
||||
[string]$Config,
|
||||
[switch]$Run,
|
||||
[switch]$Noui
|
||||
[switch]$Noui,
|
||||
[switch]$Offline
|
||||
)
|
||||
|
||||
if ($Config) {
|
||||
@@ -27,6 +28,11 @@ if ($Noui) {
|
||||
$PARAM_NOUI = $true
|
||||
}
|
||||
|
||||
$PARAM_OFFLINE = $false
|
||||
if ($Offline) {
|
||||
$PARAM_OFFLINE = $true
|
||||
}
|
||||
|
||||
|
||||
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
||||
Write-Output "Winutil needs to be run as Administrator. Attempting to relaunch."
|
||||
|
||||
@@ -943,13 +943,19 @@
|
||||
</Window.Resources>
|
||||
<Grid Background="{DynamicResource MainBackgroundColor}" ShowGridLines="False" Name="WPFMainGrid" Width="Auto" Height="Auto" HorizontalAlignment="Stretch">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid Grid.Row="0" Background="{DynamicResource MainBackgroundColor}">
|
||||
<!-- Offline banner -->
|
||||
<Border Name="WPFOfflineBanner" Grid.Row="0" Background="#8B0000" Visibility="Collapsed" Padding="6,4">
|
||||
<TextBlock Text="⚠ Offline Mode - No Internet Connection" Foreground="White" FontWeight="Bold"
|
||||
HorizontalAlignment="Center" FontSize="13" Background="Transparent"/>
|
||||
</Border>
|
||||
<Grid Grid.Row="1" Background="{DynamicResource MainBackgroundColor}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/> <!-- Navigation buttons -->
|
||||
<ColumnDefinition Width="*"/> <!-- Search bar and buttons -->
|
||||
@@ -1192,7 +1198,7 @@
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<TabControl Name="WPFTabNav" Background="Transparent" Width="Auto" Height="Auto" BorderBrush="Transparent" BorderThickness="0" Grid.Row="1" Grid.Column="0" Padding="-1">
|
||||
<TabControl Name="WPFTabNav" Background="Transparent" Width="Auto" Height="Auto" BorderBrush="Transparent" BorderThickness="0" Grid.Row="2" Grid.Column="0" Padding="-1">
|
||||
<TabItem Header="Install" Visibility="Collapsed" Name="WPFTab1">
|
||||
<Grid Background="Transparent" >
|
||||
|
||||
|
||||
Reference in New Issue
Block a user