Skip to content

Commit

Permalink
no lost-focus launch of background agent
Browse files Browse the repository at this point in the history
  • Loading branch information
MaynardMiner committed Oct 2, 2019
1 parent be47eac commit 4a13835
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions build/powershell/startup/winconfig.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -375,17 +375,14 @@ function Global:Start-WindowsConfig {
$Enabled = $(cat ".\config\parameters\autofan.json" | ConvertFrom-Json | ConvertFrom-StringData).ENABLED
if ($Enabled -eq 1) {
log "Starting Autofan" -ForeGroundColor Cyan
$BackgroundTimer = New-Object -TypeName System.Diagnostics.Stopwatch
$command = Start-Process "pwsh" -WorkingDirectory "$($(vars).dir)\build\powershell\scripts" -ArgumentList "-executionpolicy bypass -NoExit -windowstyle minimized -command `"&{`$host.ui.RawUI.WindowTitle = `'AutoFan`'; &.\autofan.ps1 -WorkingDir `'$($(vars).dir)`'}`"" -WindowStyle Minimized -PassThru -Verb Runas
$command.ID | Set-Content ".\build\pid\autofan.txt"
$BackgroundTimer.Restart()
do {
Start-Sleep -S 1
log "Getting Process ID for AutoFan"
$ProcessId = if (Test-Path ".\build\pid\autofan.txt") { Get-Content ".\build\pid\autofan.txt" }
if ($ProcessID -ne $null) { $Process = Get-Process $ProcessId -ErrorAction SilentlyContinue }
}until($ProcessId -ne $null -or ($BackgroundTimer.Elapsed.TotalSeconds) -ge 10)
$BackgroundTimer.Stop()
$start = [launchcode]::New()
$FilePath = "$PSHome\pwsh.exe"
$CommandLine = '"' + $FilePath + '"'
$arguments = "-executionpolicy bypass -command `".\build\powershell\scripts\autofan.ps1`""
$CommandLine += " " + $arguments
$New_Miner = $start.New_Miner($filepath,$CommandLine,$global:Dir)
$Process = Get-Process -id $New_Miner.dwProcessId -ErrorAction Ignore
$Process.ID | Set-Content ".\build\pid\autofan.txt"
}
}
## Aaaaannnnd...Que that sexy logo. Go Time.
Expand Down

0 comments on commit 4a13835

Please sign in to comment.