Move restart option to argument from config file

implements #1
This commit is contained in:
Chris
2021-05-15 17:50:16 -06:00
parent 895968c81b
commit b280180d30
7 changed files with 38 additions and 21 deletions

View File

@ -1,5 +1,13 @@
# Changelog
## [Unreleased]
### Breaking Changes
- Restart option has moved to the `/restart delay` argument and is no longer specified in the config file.
This allows for creating separate shortcuts, one for normal gameplay and one for restarting.
Instead of specifying `restart: { enabled: true, shutdownTimeout: 3 }`, modify your launch options to include `/restart 3`.
## [0.4.0] - 2021-05-11
### New Features

View File

@ -140,6 +140,7 @@ The following arguments are in addition to the above:
| Argument | Effect |
|------------------------|-----------------------------------------------------------|
| /frontier profile-name | Use this argument to login with a Frontier Store account. Keep the profile name to letters, numbers, dashes and underscores only |
| /restart delay | Restart the game after it has closed with _delay_ being the number of seconds given to cancel the restart (i.e `/restart 3`) |
### Settings
The settings file controls additional settings for the launcher that go beyond what the default
@ -156,7 +157,6 @@ Linux: `$XDG_CONFIG_DIR/min-ed-launcher/settings.json` (`~/.config` if `$XDG_CON
| watchForCrashes | Determines if the game should be launched by `WatchDog64.exe` or not |
| gameLocation | Path to game's install folder. Specify this if the launcher can't figure it out by itself |
| language | Sets the game's language. Supported values are _en_ and the names of the language folders in Elite's install directory |
| restart | Restart the game after it has closed |
| autoUpdate | Automatically update games that are out of date |
| maxConcurrentDownloads | Maximum number of simultaneous downloads when downloading updates |
| forceUpdate | Be default, Steam and Epic updates are handled by their respective platform. In cases like the Odyssey alpha, FDev doesn't provide updates through Steam or Epic. This allows the launcher to force updates to be done via FDev servers by providing a comma delimited list of SKUs |
@ -171,10 +171,6 @@ double backslash (`\\`) instead of a single backslash (`\`).
"watchForCrashes": false,
"gameLocation": null,
"language": "en",
"restart": {
"enabled": false,
"shutdownTimeout": 3
},
"autoUpdate": true,
"maxConcurrentDownloads": 4,
"forceUpdate": "PUBLIC_TEST_SERVER_OD",

View File

@ -85,8 +85,7 @@ let rec launchProduct proton processArgs restart productName product =
match Product.run proton args product with
| Product.RunResult.Ok p ->
let shouldRestart = restart |> fst
let timeout = restart |> snd
let timeout = restart |> Option.defaultValue 3000L
let cancelRestart() =
let interval = 250
let stopwatch = Stopwatch()
@ -111,7 +110,7 @@ let rec launchProduct proton processArgs restart productName product =
p.WaitForExit()
Log.info $"Shutdown %s{productName}"
if shouldRestart && not (cancelRestart()) then
if restart.IsSome && not (cancelRestart()) then
launchProduct proton processArgs restart productName product
| Product.RunResult.AlreadyRunning -> Log.info $"%s{productName} is already running"
| Product.RunResult.Error e -> Log.error $"Couldn't start selected product: %s{e.ToString()}"

View File

@ -20,7 +20,7 @@ let defaults =
CbLauncherDir = "."
PreferredLanguage = None
ApiUri = Uri("http://localhost:8080")
Restart = false, 0L
Restart = None
AutoUpdate = true
MaxConcurrentDownloads = 4
ForceUpdate = Set.empty
@ -108,6 +108,13 @@ let parseArgs defaults (findCbLaunchDir: Platform -> Result<string,string>) (arg
| Epic d -> apply arg d
| _ -> apply arg EpicDetails.Empty
let (|PosDouble|_|) (str: string option) =
str
|> Option.bind (fun str ->
match Double.TryParse(str) with
| true, v when v >= 0. -> Some v
| _ -> None)
let settings =
args
|> Array.mapi (fun index value -> index, value)
@ -123,6 +130,7 @@ let parseArgs defaults (findCbLaunchDir: Platform -> Result<string,string>) (arg
| "-auth_type", Some t -> { s with Platform = epicArg (Type t) }
| "-epicapp", Some id -> { s with Platform = epicArg (AppId id) }
| "/oculus", Some nonce -> { s with Platform = Oculus nonce; ForceLocal = true }
| "/restart", PosDouble delay -> { s with Restart = delay * 1000. |> int64 |> Some }
| "/vr", _ -> { s with DisplayMode = Vr; AutoRun = true }
| "/autorun", _ -> { s with AutoRun = true }
| "/autoquit", _ -> { s with AutoQuit = true }
@ -145,16 +153,11 @@ type ProcessConfig =
{ FileName: string
Arguments: string option }
[<CLIMutable>]
type RestartConfig =
{ Enabled: bool
ShutdownTimeout: int64 }
[<CLIMutable>]
type Config =
{ ApiUri: string
WatchForCrashes: bool
GameLocation: string option
Language: string option
Restart: RestartConfig
[<DefaultValue("true")>]
AutoUpdate: bool
[<DefaultValue("4")>]
@ -193,7 +196,6 @@ let getSettings args appDir fileConfig = task {
| None -> Error "Failed to find Elite Dangerous install directory"
| Some dir -> Ok dir
let apiUri = Uri(fileConfig.ApiUri)
let restart = fileConfig.Restart.Enabled, fileConfig.Restart.ShutdownTimeout * 1000L
let processes =
fileConfig.Processes
|> List.map (fun p ->
@ -222,5 +224,4 @@ let getSettings args appDir fileConfig = task {
MaxConcurrentDownloads = fileConfig.MaxConcurrentDownloads
PreferredLanguage = fileConfig.Language
Processes = processes
Restart = restart
WatchForCrashes = fileConfig.WatchForCrashes }) }

View File

@ -41,7 +41,7 @@ type LauncherSettings =
CbLauncherDir: string
PreferredLanguage: string option
ApiUri: Uri
Restart: (bool * int64)
Restart: int64 option
AutoUpdate: bool
MaxConcurrentDownloads: int
ForceUpdate: string Set

View File

@ -2,10 +2,6 @@
"apiUri": "https://api.zaonce.net",
"watchForCrashes": false,
"language": null,
"restart": {
"enabled": false,
"shutdownTimeout": 3
},
"autoUpdate": true,
"maxConcurrentDownloads": 4,
"forceUpdate": "",

View File

@ -86,6 +86,23 @@ let tests =
let! settings = parse [| "/forcelocal" |]
Expect.equal settings.ForceLocal true ""
}
testTask "Matches /restart delay" {
let! settings = parse [| "/restart"; "2" |]
Expect.equal settings.Restart (Some 2000L) ""
}
testTask "Ignores /restart with missing delay" {
let! settings = parse [| "/restart" |]
Expect.equal settings.Restart None ""
}
testTask "Ignores /restart when delay isn't a number" {
let! settings = parse [| "/restart"; "a" |]
Expect.equal settings.Restart None ""
}
testTask "Ignores /restart when delay is negative" {
let! settings = parse [| "/restart"; "-1" |]
Expect.equal settings.Restart None ""
}
testTask "Matches /ed" {
let! settings = parse [| "/ed" |]
Expect.equal (settings.ProductWhitelist.Contains "ed") true ""