Skip to content

Commit b19bcdd

Browse files
committed
Simplify spinner implementation and cleanup in install script
├── install.ps1 └── install.sh
1 parent 706fb25 commit b19bcdd

1 file changed

Lines changed: 9 additions & 42 deletions

File tree

‎install.ps1‎

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -111,52 +111,22 @@ if ($autoChoice) {
111111
}
112112
}
113113

114-
$global:activeSpinner = $null
115-
116114
function Start-Spinner {
117115
param([string]$Message)
116+
Write-Progress -Activity "CodeWebChat Installation" -Status $Message
118117
Write-Host -NoNewline " $Message"
119-
try { [Console]::CursorVisible = $false } catch {}
120-
121-
$runspace = [runspacefactory]::CreateRunspace()
122-
$runspace.Open()
123-
$ps = [powershell]::Create()
124-
$ps.Runspace = $runspace
125-
$ps.AddScript({
126-
$spinner = @('-', '\', '|', '/')
127-
$i = 0
128-
while ($true) {
129-
try { [Console]::Write("`r$($spinner[$i % 4])") } catch {}
130-
$i++
131-
Start-Sleep -Milliseconds 100
132-
}
133-
}) | Out-Null
134-
$asyncResult = $ps.BeginInvoke()
135-
$spinnerObj = @{ PS = $ps; Runspace = $runspace; Message = $Message }
136-
$global:activeSpinner = $spinnerObj
137-
return $spinnerObj
118+
return $Message
138119
}
139120

140121
function Stop-Spinner {
141-
param($spinnerObj, [bool]$Success = $true)
142-
if ($global:activeSpinner -and $spinnerObj -and $global:activeSpinner.PS -eq $spinnerObj.PS) {
143-
$global:activeSpinner = $null
144-
}
145-
$msg = if ($spinnerObj.Message) { $spinnerObj.Message } else { "" }
146-
if ($spinnerObj) {
147-
try { $spinnerObj.PS.Stop() } catch {}
148-
try { $spinnerObj.PS.Dispose() } catch {}
149-
try { $spinnerObj.Runspace.Close() } catch {}
150-
try { $spinnerObj.Runspace.Dispose() } catch {}
151-
}
152-
try { [Console]::CursorVisible = $true } catch {}
153-
122+
param([string]$Message, [bool]$Success = $true)
123+
Write-Progress -Activity "CodeWebChat Installation" -Completed
154124
if ($Success) {
155125
Write-Host "`r$([char]0x2714) " -ForegroundColor Green -NoNewline
156-
Write-Host $msg
126+
Write-Host $Message
157127
} else {
158128
Write-Host "`r$([char]0x2718) " -ForegroundColor Red -NoNewline
159-
Write-Host $msg
129+
Write-Host $Message
160130
}
161131
}
162132

@@ -252,12 +222,9 @@ if ($choice -eq 'a' -or $choice -eq 'A') {
252222
}
253223

254224
} finally {
255-
if ($global:activeSpinner) {
256-
Stop-Spinner $global:activeSpinner $false
257-
}
258-
try { [Console]::CursorVisible = $true } catch {}
225+
Write-Progress -Activity "CodeWebChat Installation" -Completed
259226
}
260227

261-
Pause
262228
Pop-Location
263-
Start-Process -FilePath "cmd.exe" -ArgumentList "/c", "rmdir", "/s", "/q", "`"$tmpDir`"" -WindowStyle Hidden
229+
Remove-Item -Path $tmpDir -Recurse -Force -ErrorAction SilentlyContinue
230+
Pause

0 commit comments

Comments
 (0)