diff --git a/StackMonkey.ps1 b/StackMonkey.ps1 index 82aefe8..de2768d 100644 --- a/StackMonkey.ps1 +++ b/StackMonkey.ps1 @@ -1861,33 +1861,31 @@ function Install-DattoRMM { # Resolve Edge path explicitly (works in both 32/64-bit installs) $edgeCandidates = @( - "$env:ProgramFiles\Microsoft\Edge\Application\msedge.exe", - "${env:ProgramFiles(x86)}\Microsoft\Edge\Application\msedge.exe" + "${env:ProgramFiles(x86)}\Microsoft\Edge\Application\msedge.exe", + "$env:ProgramFiles\Microsoft\Edge\Application\msedge.exe ) $edgePath = ($edgeCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1) - if (-not $edgePath) { $edgePath = 'msedge.exe' } - - # Fire Edge in app mode shortly after, so the server is ready. - $timer = New-Object System.Timers.Timer - $timer.Interval = 400 - $timer.AutoReset = $false - Register-ObjectEvent -InputObject $timer -EventName Elapsed -Action { + if (-not $edgePath) { + $cmd = Get-Command -Name 'msedge.exe' -ErrorAction SilentlyContinue + if ($cmd) { $edgePath = $cmd.Path } + } + + # Launch Edge (app mode) in a background job so Start-Server can block + Start-Job -Name 'OpenScriptMonkeyUI' -ScriptBlock { + param($u, $edge) + Start-Sleep -Milliseconds 400 try { - if (Get-Command -Name $using:edgePath -ErrorAction SilentlyContinue) { - Start-Process -FilePath $using:edgePath -ArgumentList @('--new-window', "--app=$using:url") + if ($edge -and (Test-Path $edge)) { + Start-Process -FilePath $edge -ArgumentList @('--new-window',"--app=$u") } else { - Start-Process -FilePath $using:url + Start-Process -FilePath $u # fallback to default browser } - } catch { - # no-op - } - } | Out-Null - $timer.Start() + } catch { } + } -ArgumentList $url, $edgePath | Out-Null # Now start the blocking listener loop Start-Server return - } }