don't wait for ed to exit before exiting when autoquit

closes #131
This commit is contained in:
Chris
2024-06-29 21:05:03 -06:00
parent 3cef3952e5
commit 41f336f3e7
3 changed files with 48 additions and 19 deletions

View File

@ -17,7 +17,11 @@
or [Heroic]. Once you've logged in with either, you can go back to using the normal Epic launcher if you wish. It will
require re-logging in every few days though, so it may be preferable to just stick with the alternate launchers.
- Added an [icon](resources/min-ed-launcher.svg) for the app. Linux users can check the [readme](README.md#icon-on-linux)
for setup instructions.
for setup instructions.
- The launcher will now exit instead of waiting for Elite to exit if the following conditions are met:
1. `/autoquit` is specified
2. `/restart` is not specified
3. No external apps specified in `settings.json` (`processes`, `shutdownProcesses`)
## [0.10.1] - 2024-05-03

View File

@ -98,18 +98,19 @@ let private checkForLauncherUpdates httpClient cancellationToken currentVersion
)
}
let launchProduct dryRun proton processArgs productName product =
let launchProduct dryRun proton processArgs productName waitForExit product =
let args = processArgs()
Log.info $"Launching %s{productName}"
match Product.run dryRun proton args product with
| Product.RunResult.Ok p ->
use p = p
p.BeginErrorReadLine()
p.BeginOutputReadLine()
p.WaitForExit()
p.Close()
Log.info $"Shutdown %s{productName}"
if waitForExit then
use p = p
p.WaitForExit()
p.Close()
Log.info $"Shutdown %s{productName}"
| Product.DryRun p ->
Console.WriteLine("\tDry run")
Console.WriteLine($"\t{p.FileName} {p.Arguments}")
@ -337,22 +338,36 @@ let rec private launchLoop initialLaunch settings playableProducts (session: EdS
Log.info $"Delaying game launch for %.2f{settings.GameStartDelay.TotalSeconds} seconds"
do! Task.Delay settings.GameStartDelay
launchProduct settings.DryRun settings.CompatTool pArgs selectedProduct.Name p
let waitForEdExit = not settings.AutoQuit || settings.Restart.IsSome || not settings.Processes.IsEmpty || not settings.ShutdownProcesses.IsEmpty
let timeout = settings.Restart |> Option.defaultValue 3000L
while settings.Restart.IsSome && not (Console.cancelRestart timeout) do
Process.stopProcesses settings.ShutdownTimeout relaunchProcesses
logStart relaunchStartInfos
relaunchProcesses <- Process.launchProcesses relaunchStartInfos
do! renewEpicTokenIfNeeded settings.Platform session.PlatformToken
launchProduct settings.DryRun settings.CompatTool pArgs selectedProduct.Name p
launchProduct settings.DryRun settings.CompatTool pArgs selectedProduct.Name waitForEdExit p
if not settings.AutoQuit then
return! launchLoop false settings playableProducts session (Some persistentProcesses) (Some relaunchProcesses) cancellationToken processArgs
if not waitForEdExit then
// Wait for ED Process to start before exiting
let maxTries = 30
let mutable tries = 0
while tries < maxTries do
if not (Product.isRunning p) then
do! Task.Delay(TimeSpan.FromSeconds(1))
tries <- tries + 1
else
tries <- maxTries
return [], didLoop
else
return persistentProcesses @ relaunchProcesses, didLoop
let timeout = settings.Restart |> Option.defaultValue 3000L
while settings.Restart.IsSome && not (Console.cancelRestart timeout) do
Process.stopProcesses settings.ShutdownTimeout relaunchProcesses
logStart relaunchStartInfos
relaunchProcesses <- Process.launchProcesses relaunchStartInfos
do! renewEpicTokenIfNeeded settings.Platform session.PlatformToken
launchProduct settings.DryRun settings.CompatTool pArgs selectedProduct.Name true p
if not settings.AutoQuit then
return! launchLoop false settings playableProducts session (Some persistentProcesses) (Some relaunchProcesses) cancellationToken processArgs
else
return persistentProcesses @ relaunchProcesses, didLoop
}
let run settings launcherVersion cancellationToken = taskResult {

View File

@ -247,6 +247,16 @@ let validateForRun launcherDir watchForCrashes (product: ProductDetails) =
Mode = product.VInfo.Mode
ServerArgs = product.ServerArgs }
let isRunning (product:RunnableProduct) =
let exeName = Path.GetFileNameWithoutExtension(product.Executable.Name)
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
Process.GetProcessesByName(exeName).Length > 0
else
// Process.ProcessName seems to be truncated on linux. Not sure if it's always the case or only sometimes
// so check both truncated name and full name
Process.GetProcessesByName(exeName[..14]).Length > 0 || Process.GetProcessesByName(exeName).Length > 0
let createProcessInfo proton args product =
let fileName, arguments =
match proton with