Merge pull request #44 from objz/feat/settings-popups
feat(settings): add launcher and instance editors
This commit is contained in:
87 files changed
+10493
-515
No files matched your search
@@ -3,3 +3,6 @@
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: "21"
|
||||
- name: install Linux build dependencies
|
||||
if: runner.os == 'Linux'
|
||||
run: sudo apt-get update && sudo apt-get install --yes libxcb1-dev
|
||||
@@ -103,6 +103,9 @@ jobs:
|
||||
with:
|
||||
"distribution": "temurin"
|
||||
"java-version": "21"
|
||||
- name: install Linux build dependencies
|
||||
if: runner.os == 'Linux'
|
||||
run: sudo apt-get update && sudo apt-get install --yes libxcb1-dev
|
||||
- name: Install dist
|
||||
run: ${{ matrix.install_dist.run }}
|
||||
# Get the dist-manifest
|
||||
|
||||
@@ -68,6 +68,9 @@ jobs:
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
key: ${{ matrix.os }}
|
||||
- name: install Linux build dependencies
|
||||
if: runner.os == 'Linux'
|
||||
run: sudo apt-get update && sudo apt-get install --yes libxcb1-dev
|
||||
- run: cargo build --locked
|
||||
- run: cargo test --locked --all-targets
|
||||
|
||||
@@ -86,4 +89,6 @@ jobs:
|
||||
distribution: temurin
|
||||
java-version: "21"
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- name: install Linux build dependencies
|
||||
run: sudo apt-get update && sudo apt-get install --yes libxcb1-dev
|
||||
- run: cargo test --locked --all-targets -- --ignored
|
||||
Generated
+465
-1
@@ -297,6 +297,15 @@ dependencies = [
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block2"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5"
|
||||
dependencies = [
|
||||
"objc2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bon"
|
||||
version = "3.9.1"
|
||||
@@ -789,6 +798,12 @@ dependencies = [
|
||||
"cmov",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cursor-icon"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f27ae1dd37df86211c42e150270f82743308803d90a6f6e6651cd730d5e1732f"
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.21.3"
|
||||
@@ -1019,6 +1034,37 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dispatch2"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e0e367e4e7da84520dedcac1901e4da967309406d1e51017ae1abfb97adbd38"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"objc2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "display-info"
|
||||
version = "0.5.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e0aca670967c2528799e316f9f97913efcc034867614d55681dd41a1c2f7830"
|
||||
dependencies = [
|
||||
"fxhash",
|
||||
"log",
|
||||
"objc2",
|
||||
"objc2-app-kit",
|
||||
"objc2-core-foundation",
|
||||
"objc2-core-graphics",
|
||||
"objc2-foundation",
|
||||
"scopeguard",
|
||||
"smithay-client-toolkit",
|
||||
"thiserror 2.0.18",
|
||||
"widestring",
|
||||
"windows 0.62.2",
|
||||
"xcb",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "displaydoc"
|
||||
version = "0.2.5"
|
||||
@@ -1048,6 +1094,12 @@ dependencies = [
|
||||
"litrs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "downcast-rs"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.15.0"
|
||||
@@ -1392,6 +1444,15 @@ dependencies = [
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fxhash"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gdb-command"
|
||||
version = "0.7.8"
|
||||
@@ -2623,6 +2684,174 @@ dependencies = [
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3a12a8ed07aefc768292f076dc3ac8c48f3781c8f2d5851dd3d98950e8c5a89f"
|
||||
dependencies = [
|
||||
"objc2-encode",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-app-kit"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d49e936b501e5c5bf01fda3a9452ff86dc3ea98ad5f283e1455153142d97518c"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"block2",
|
||||
"libc",
|
||||
"objc2",
|
||||
"objc2-cloud-kit",
|
||||
"objc2-core-data",
|
||||
"objc2-core-foundation",
|
||||
"objc2-core-graphics",
|
||||
"objc2-core-image",
|
||||
"objc2-core-text",
|
||||
"objc2-core-video",
|
||||
"objc2-foundation",
|
||||
"objc2-quartz-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-cloud-kit"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73ad74d880bb43877038da939b7427bba67e9dd42004a18b809ba7d87cee241c"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"objc2",
|
||||
"objc2-foundation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-core-data"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b402a653efbb5e82ce4df10683b6b28027616a2715e90009947d50b8dd298fa"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"objc2",
|
||||
"objc2-foundation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-core-foundation"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"block2",
|
||||
"dispatch2",
|
||||
"libc",
|
||||
"objc2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-core-graphics"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e022c9d066895efa1345f8e33e584b9f958da2fd4cd116792e15e07e4720a807"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"block2",
|
||||
"dispatch2",
|
||||
"libc",
|
||||
"objc2",
|
||||
"objc2-core-foundation",
|
||||
"objc2-io-surface",
|
||||
"objc2-metal",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-core-image"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5d563b38d2b97209f8e861173de434bd0214cf020e3423a52624cd1d989f006"
|
||||
dependencies = [
|
||||
"objc2",
|
||||
"objc2-foundation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-core-text"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0cde0dfb48d25d2b4862161a4d5fcc0e3c24367869ad306b0c9ec0073bfed92d"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"objc2",
|
||||
"objc2-core-foundation",
|
||||
"objc2-core-graphics",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-core-video"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d425caf1df73233f29fd8a5c3e5edbc30d2d4307870f802d18f00d83dc5141a6"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"objc2",
|
||||
"objc2-core-foundation",
|
||||
"objc2-core-graphics",
|
||||
"objc2-io-surface",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-encode"
|
||||
version = "4.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33"
|
||||
|
||||
[[package]]
|
||||
name = "objc2-foundation"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"block2",
|
||||
"libc",
|
||||
"objc2",
|
||||
"objc2-core-foundation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-io-surface"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "180788110936d59bab6bd83b6060ffdfffb3b922ba1396b312ae795e1de9d81d"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"objc2",
|
||||
"objc2-core-foundation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-metal"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a0125f776a10d00af4152d74616409f0d4a2053a6f57fa5b7d6aa2854ac04794"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"objc2",
|
||||
"objc2-foundation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-quartz-core"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96c1358452b371bf9f104e21ec536d37a650eb10f7ee379fff67d2e08d537f1f"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"objc2",
|
||||
"objc2-foundation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "object"
|
||||
version = "0.37.3"
|
||||
@@ -3150,6 +3379,15 @@ version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
|
||||
|
||||
[[package]]
|
||||
name = "quick-xml"
|
||||
version = "0.41.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e660451e55124f798a69a5af3f49ccfbefbd41910eefd25caf2393e1f3473ec1"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quinn"
|
||||
version = "0.11.9"
|
||||
@@ -3366,7 +3604,7 @@ dependencies = [
|
||||
"rustix 0.38.44",
|
||||
"self_cell",
|
||||
"thiserror 1.0.69",
|
||||
"windows",
|
||||
"windows 0.58.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3653,6 +3891,7 @@ dependencies = [
|
||||
"crossterm 0.29.0",
|
||||
"dirs",
|
||||
"dirs-next",
|
||||
"display-info",
|
||||
"fast-strip-ansi",
|
||||
"fastnbt",
|
||||
"flate2",
|
||||
@@ -3685,6 +3924,7 @@ dependencies = [
|
||||
"throbber-widgets-tui",
|
||||
"tokio",
|
||||
"toml",
|
||||
"toml_edit",
|
||||
"tracing",
|
||||
"tracing-appender",
|
||||
"tracing-subscriber",
|
||||
@@ -4170,6 +4410,31 @@ version = "1.15.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
|
||||
|
||||
[[package]]
|
||||
name = "smithay-client-toolkit"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0512da38f5e2b31201a93524adb8d3136276fa4fe4aafab4e1f727a82b534cc0"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"cursor-icon",
|
||||
"libc",
|
||||
"log",
|
||||
"memmap2",
|
||||
"rustix 1.1.4",
|
||||
"thiserror 2.0.18",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-csd-frame",
|
||||
"wayland-cursor",
|
||||
"wayland-protocols",
|
||||
"wayland-protocols-experimental",
|
||||
"wayland-protocols-misc",
|
||||
"wayland-protocols-wlr",
|
||||
"wayland-scanner",
|
||||
"xkeysym",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
version = "0.6.3"
|
||||
@@ -4683,6 +4948,7 @@ dependencies = [
|
||||
"indexmap",
|
||||
"toml_datetime",
|
||||
"toml_parser",
|
||||
"toml_writer",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
@@ -5294,6 +5560,124 @@ dependencies = [
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-backend"
|
||||
version = "0.3.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38a91b4eaddff87b1cd1074985e3713da4af2c49742d1b356b2c01670a67a078"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"downcast-rs",
|
||||
"rustix 1.1.4",
|
||||
"smallvec",
|
||||
"wayland-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-client"
|
||||
version = "0.31.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3c36a0f861ad76d0901f2800b46321410d9f73f2ea88aac0650d86c32688073"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"rustix 1.1.4",
|
||||
"wayland-backend",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-csd-frame"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "625c5029dbd43d25e6aa9615e88b829a5cad13b2819c4ae129fdbb7c31ab4c7e"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"cursor-icon",
|
||||
"wayland-backend",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-cursor"
|
||||
version = "0.31.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a52d18780be9b1314328a3de5f930b73d2200112e3849ca6cb11822793fb34d"
|
||||
dependencies = [
|
||||
"rustix 1.1.4",
|
||||
"wayland-client",
|
||||
"xcursor",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols"
|
||||
version = "0.32.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23d0c813de3daa2ed6520af85a3bd49b0e722a3078506899aa9686fea58dc4b6"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-experimental"
|
||||
version = "20250721.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40a1f863128dcaaec790d7b4b396cc9b9a7a079e878e18c47e6c2d2c5a8dcbb1"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-misc"
|
||||
version = "0.3.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e9567599ef23e09b8dad6e429e5738d4509dfc46b3b21f32841a304d16b29c8"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-wlr"
|
||||
version = "0.3.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb04e52f7836d7c7976c78ca0250d61e33873c34156a2a1fc9474828ec268234"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-scanner"
|
||||
version = "0.31.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "338e30461b3a2b67d70eb30a6d89f8e0c93a833e07d2ae89085cd070c4a00ac0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quick-xml",
|
||||
"quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-sys"
|
||||
version = "0.31.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8eab23fefc9e41f8e841df4a9c707e8a8c4ed26e944ef69297184de2785e3be"
|
||||
dependencies = [
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.95"
|
||||
@@ -5434,6 +5818,12 @@ dependencies = [
|
||||
"safe_arch",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "widestring"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72069c3113ab32ab29e5584db3c6ec55d416895e60715417b5b883a357c3e471"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
@@ -5475,6 +5865,27 @@ dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.62.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580"
|
||||
dependencies = [
|
||||
"windows-collections",
|
||||
"windows-core 0.62.2",
|
||||
"windows-future",
|
||||
"windows-numerics",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-collections"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610"
|
||||
dependencies = [
|
||||
"windows-core 0.62.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.58.0"
|
||||
@@ -5501,6 +5912,17 @@ dependencies = [
|
||||
"windows-strings 0.5.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-future"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb"
|
||||
dependencies = [
|
||||
"windows-core 0.62.2",
|
||||
"windows-link",
|
||||
"windows-threading",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-implement"
|
||||
version = "0.58.0"
|
||||
@@ -5551,6 +5973,16 @@ version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||
|
||||
[[package]]
|
||||
name = "windows-numerics"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26"
|
||||
dependencies = [
|
||||
"windows-core 0.62.2",
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.2.0"
|
||||
@@ -5657,6 +6089,15 @@ dependencies = [
|
||||
"windows_x86_64_msvc 0.53.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-threading"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.6"
|
||||
@@ -5894,6 +6335,29 @@ dependencies = [
|
||||
"tap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xcb"
|
||||
version = "1.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6c2ad15e0e922856ee89afe862b8992334bbe7953adad56cd1199358cb30566"
|
||||
dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
"libc",
|
||||
"quick-xml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xcursor"
|
||||
version = "0.3.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "163b33ed8786455e2fa5d72f554057ce3f3182425434f756cd39c99839d88e23"
|
||||
|
||||
[[package]]
|
||||
name = "xkeysym"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56"
|
||||
|
||||
[[package]]
|
||||
name = "xmlwriter"
|
||||
version = "0.1.0"
|
||||
|
||||
@@ -29,6 +29,7 @@ clap = "4.5.27"
|
||||
color-eyre = "0.6.3"
|
||||
config = "0.15.6"
|
||||
crossterm = "0.29.0"
|
||||
display-info = "0.5.9"
|
||||
dirs-next = "2.0.0"
|
||||
log = "0.4"
|
||||
ratatui = { version = "0.30.0", features = ["serde", "unstable-rendered-line-info"] }
|
||||
@@ -44,6 +45,7 @@ serde_json = "1.0"
|
||||
sha1 = "0.10"
|
||||
sha2 = "0.10"
|
||||
toml = "1.1.2"
|
||||
toml_edit = "0.25"
|
||||
tachyonfx = "0.25"
|
||||
throbber-widgets-tui = "0.11"
|
||||
thiserror = "2"
|
||||
|
||||
@@ -129,6 +129,39 @@ settings, accounts, instances, and cached game metadata.
|
||||
|
||||
each instance has an `instance.json` for its config and a `.minecraft/` directory with the actual game files.
|
||||
|
||||
Launcher settings can be edited from the TUI or in `config.toml`. Changes to
|
||||
`instances_dir`, `meta_dir`, and `image_protocol` apply after restarting rmcl;
|
||||
other launcher settings apply immediately. Omitting `java_path` enables automatic
|
||||
Java selection. Global JVM arguments and environment variables are applied before
|
||||
per-instance values. Instances can explicitly inherit the launcher window mode
|
||||
and resolution defaults.
|
||||
|
||||
```toml
|
||||
[general]
|
||||
check_modpack_updates = true
|
||||
check_content_updates = true
|
||||
|
||||
[defaults]
|
||||
memory_min = "512M"
|
||||
memory_max = "2G"
|
||||
jvm_args = []
|
||||
environment = {}
|
||||
window_mode = "windowed"
|
||||
resolution = [854, 480]
|
||||
|
||||
[ui]
|
||||
image_protocol = "auto"
|
||||
hidden_shortcut_hints = [] # all, main, instances, content, accounts, settings, popups
|
||||
|
||||
[content]
|
||||
preferred_provider = "modrinth"
|
||||
preferred_provider_only = false
|
||||
ask_on_provider_conflict = true
|
||||
```
|
||||
|
||||
Use `hidden_shortcut_hints = ["main"]` to keep only popup guides,
|
||||
`["all"]` to hide every guide, or list individual areas to hide them selectively.
|
||||
|
||||
### logs
|
||||
|
||||
launcher logs are per-session and contain rmcl's own output. instance launch logs capture game stdout/stderr per launch.
|
||||
|
||||
+22
-11
@@ -1,21 +1,32 @@
|
||||
[general]
|
||||
# check imported modpacks and managed content for updates automatically
|
||||
check_modpack_updates = true
|
||||
check_content_updates = true
|
||||
|
||||
[paths]
|
||||
# where instances are stored
|
||||
instances_dir = "~/.local/share/rmcl/instances"
|
||||
|
||||
# metadata, cache, whatever else ends up there
|
||||
meta_dir = "~/.local/share/rmcl/meta"
|
||||
|
||||
# optional java override (empty = uses JAVA_HOME)
|
||||
java_path = ""
|
||||
# instances_dir and meta_dir use platform defaults when omitted
|
||||
# java_path is omitted to select Java automatically
|
||||
# instances_dir = "/path/to/minecraft/instances"
|
||||
# meta_dir = "/path/to/rmcl/meta"
|
||||
# java_path = "/usr/bin/java"
|
||||
|
||||
[defaults]
|
||||
# default heap settings
|
||||
# inherited by instances that do not override their memory
|
||||
memory_min = "512M"
|
||||
memory_max = "2G"
|
||||
# appended to every instance; instance values take precedence where applicable
|
||||
jvm_args = []
|
||||
environment = {}
|
||||
# inherited by instances that use launcher window defaults
|
||||
window_mode = "windowed"
|
||||
resolution = [854, 480]
|
||||
|
||||
[ui]
|
||||
# image protocol for content icons and screenshots: halfblocks, quadrants, kitty, or iterm2
|
||||
image_protocol = "kitty"
|
||||
# image protocol: auto, halfblocks, quadrants, kitty, or iterm2
|
||||
image_protocol = "auto"
|
||||
# [] shows all guides; ["main"] keeps popup guides; ["all"] hides every guide
|
||||
# areas can also be hidden selectively: instances, content, accounts, settings, popups
|
||||
hidden_shortcut_hints = []
|
||||
# error popup timing (in ms)
|
||||
error_auto_dismiss_ms = 5000
|
||||
error_slide_start_ms = 3500
|
||||
|
||||
+2
-2
@@ -68,7 +68,7 @@ pub(crate) fn find_entry_by_stem<'a>(
|
||||
}
|
||||
|
||||
fn list_entries(instance: &str, scan: Scanner) -> CliResult {
|
||||
let instances_dir = crate::config::SETTINGS.paths.resolve_instances_dir();
|
||||
let instances_dir = crate::config::SETTINGS.read().paths.resolve_instances_dir();
|
||||
require_instance(&instances_dir, instance)?;
|
||||
let rows = scan(&instances_dir, instance)
|
||||
.into_iter()
|
||||
@@ -95,7 +95,7 @@ fn toggle_entry(
|
||||
kind: &str,
|
||||
scan: Scanner,
|
||||
) -> CliResult {
|
||||
let instances_dir = crate::config::SETTINGS.paths.resolve_instances_dir();
|
||||
let instances_dir = crate::config::SETTINGS.read().paths.resolve_instances_dir();
|
||||
require_instance(&instances_dir, instance)?;
|
||||
let entries = scan(&instances_dir, instance);
|
||||
let entry = find_entry_by_stem(&entries, target)
|
||||
|
||||
+2
-2
@@ -16,8 +16,8 @@ pub async fn handle_import(matches: &ArgMatches) -> CliResult {
|
||||
let override_name = matches.get_one::<String>("name");
|
||||
let override_version = matches.get_one::<String>("version");
|
||||
|
||||
let instances_dir = crate::config::SETTINGS.paths.resolve_instances_dir();
|
||||
let meta_dir = crate::config::SETTINGS.paths.resolve_meta_dir();
|
||||
let instances_dir = crate::config::SETTINGS.read().paths.resolve_instances_dir();
|
||||
let meta_dir = crate::config::SETTINGS.read().paths.resolve_meta_dir();
|
||||
let manager = InstanceManager::new(instances_dir, meta_dir);
|
||||
let client = crate::net::HttpClient::new();
|
||||
|
||||
|
||||
+5
-23
@@ -11,7 +11,7 @@ use clap::ArgMatches;
|
||||
use super::utils::{confirm, required_arg};
|
||||
use crate::cli::output::{format_datetime, print_table};
|
||||
use crate::instance::runtime::RunState;
|
||||
use crate::instance::{InstanceManager, ModLoader};
|
||||
use crate::instance::{InstanceManager, ModLoader, models::parse_resolution};
|
||||
|
||||
type CliResult = Result<(), Box<dyn std::error::Error>>;
|
||||
const LOCAL_CONFIG_PROFILE: &str = "instance default";
|
||||
@@ -44,27 +44,9 @@ pub(crate) fn parse_loader(input: &str) -> Result<ModLoader, String> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn parse_resolution(input: &str) -> Result<(u32, u32), String> {
|
||||
let (width, height) = input
|
||||
.split_once('x')
|
||||
.ok_or_else(|| "resolution must be in WxH format".to_string())?;
|
||||
let width = width
|
||||
.parse::<u32>()
|
||||
.map_err(|_| "resolution width must be a positive integer".to_string())?;
|
||||
let height = height
|
||||
.parse::<u32>()
|
||||
.map_err(|_| "resolution height must be a positive integer".to_string())?;
|
||||
|
||||
if width == 0 || height == 0 {
|
||||
return Err("resolution values must be greater than zero".to_string());
|
||||
}
|
||||
|
||||
Ok((width, height))
|
||||
}
|
||||
|
||||
fn manager() -> InstanceManager {
|
||||
let instances_dir = crate::config::SETTINGS.paths.resolve_instances_dir();
|
||||
let meta_dir = crate::config::SETTINGS.paths.resolve_meta_dir();
|
||||
let instances_dir = crate::config::SETTINGS.read().paths.resolve_instances_dir();
|
||||
let meta_dir = crate::config::SETTINGS.read().paths.resolve_meta_dir();
|
||||
InstanceManager::new(instances_dir, meta_dir)
|
||||
}
|
||||
|
||||
@@ -135,8 +117,8 @@ fn rename_instance(matches: &ArgMatches) -> CliResult {
|
||||
async fn launch_instance(matches: &ArgMatches) -> CliResult {
|
||||
let name = required_arg(matches, "name")?;
|
||||
let manager = manager();
|
||||
let instances_dir = crate::config::SETTINGS.paths.resolve_instances_dir();
|
||||
let meta_dir = crate::config::SETTINGS.paths.resolve_meta_dir();
|
||||
let instances_dir = crate::config::SETTINGS.read().paths.resolve_instances_dir();
|
||||
let meta_dir = crate::config::SETTINGS.read().paths.resolve_meta_dir();
|
||||
let config = manager.load_one(name)?;
|
||||
|
||||
crate::instance::launch::launch(&config, &instances_dir, &meta_dir, None)
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ pub async fn handle_log(matches: &ArgMatches) -> CliResult {
|
||||
}
|
||||
|
||||
fn list_logs(instance: &str) -> CliResult {
|
||||
let instances_dir = crate::config::SETTINGS.paths.resolve_instances_dir();
|
||||
let instances_dir = crate::config::SETTINGS.read().paths.resolve_instances_dir();
|
||||
require_instance(&instances_dir, instance)?;
|
||||
let rows = crate::instance::logs::files::scan_log_files(&instances_dir, instance)
|
||||
.into_iter()
|
||||
@@ -41,7 +41,7 @@ async fn show_log(matches: &ArgMatches) -> CliResult {
|
||||
let instance = required_arg(matches, "instance")?;
|
||||
let file = matches.get_one::<String>("file").map(String::as_str);
|
||||
let follow = matches.get_flag("follow");
|
||||
let instances_dir = crate::config::SETTINGS.paths.resolve_instances_dir();
|
||||
let instances_dir = crate::config::SETTINGS.read().paths.resolve_instances_dir();
|
||||
require_instance(&instances_dir, instance)?;
|
||||
let path = resolve_log_path(&instances_dir, instance, file)?;
|
||||
|
||||
|
||||
+5
-3
@@ -27,10 +27,10 @@ pub async fn init() {
|
||||
return;
|
||||
}
|
||||
|
||||
let instances_dir = crate::config::SETTINGS.paths.resolve_instances_dir();
|
||||
let meta_dir = crate::config::SETTINGS.paths.resolve_meta_dir();
|
||||
let instances_dir = crate::config::SETTINGS.read().paths.resolve_instances_dir();
|
||||
let meta_dir = crate::config::SETTINGS.read().paths.resolve_meta_dir();
|
||||
let config = crate::config::get_config_path().join("config.toml");
|
||||
if crate::layout_migration::is_needed(&instances_dir, &meta_dir) {
|
||||
let config = crate::config::get_config_path().join("config.toml");
|
||||
if let Err(error) =
|
||||
crate::layout_migration::run(&instances_dir, &meta_dir, &config, |progress| {
|
||||
eprintln!(
|
||||
@@ -45,6 +45,8 @@ pub async fn init() {
|
||||
} else if let Err(error) = crate::layout_migration::initialize_new_layout(&meta_dir) {
|
||||
eprintln!("error: cannot initialize metadata layout: {error}");
|
||||
std::process::exit(1);
|
||||
} else if let Err(error) = crate::config::upgrade_config_file(&config) {
|
||||
eprintln!("warning: cannot upgrade launcher config: {error}");
|
||||
}
|
||||
if crate::layout_migration::cache_rebuild_pending(&meta_dir) {
|
||||
let manager = crate::instance::InstanceManager::new(&instances_dir, &meta_dir);
|
||||
|
||||
+298
-13
@@ -6,8 +6,9 @@
|
||||
|
||||
use config::{Config as ConfigLoader, ConfigError, File};
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::LazyLock;
|
||||
use std::sync::{LazyLock, RwLock, RwLockReadGuard};
|
||||
|
||||
pub mod settings;
|
||||
pub mod theme;
|
||||
@@ -53,22 +54,306 @@ pub fn load_config(config_path: &std::path::Path) -> Result<Config, ConfigError>
|
||||
ConfigLoader::builder()
|
||||
.add_source(File::from(config_path).required(false))
|
||||
.build()?
|
||||
.try_deserialize()
|
||||
.try_deserialize::<Config>()
|
||||
.map(Config::normalize)
|
||||
}
|
||||
|
||||
pub static SETTINGS: LazyLock<Config> = LazyLock::new(|| {
|
||||
let path = ensure_config_exists();
|
||||
load_config(&path).unwrap_or_else(|e| {
|
||||
tracing::error!("Config load failed, using defaults: {}", e);
|
||||
Config {
|
||||
general: settings::General::default(),
|
||||
paths: settings::Paths::default(),
|
||||
defaults: settings::Defaults::default(),
|
||||
ui: settings::Ui::default(),
|
||||
content: settings::Content::default(),
|
||||
pub(crate) fn upgrade_config_file(path: &std::path::Path) -> io::Result<bool> {
|
||||
let source = match fs::read_to_string(path) {
|
||||
Ok(source) => source,
|
||||
Err(error) if error.kind() == io::ErrorKind::NotFound => {
|
||||
crate::storage::write_atomic(
|
||||
path,
|
||||
include_str!("../../assets/config.toml").as_bytes(),
|
||||
)?;
|
||||
return Ok(true);
|
||||
}
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
let mut document = parse_toml_document(path, &source)?;
|
||||
let template = include_str!("../../assets/config.toml")
|
||||
.parse::<toml_edit::DocumentMut>()
|
||||
.map_err(io::Error::other)?;
|
||||
merge_missing_table(document.as_table_mut(), template.as_table());
|
||||
let upgraded = document.to_string();
|
||||
toml::from_str::<Config>(&upgraded).map_err(|error| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::InvalidData,
|
||||
format!("cannot upgrade {}: {error}", path.display()),
|
||||
)
|
||||
})?;
|
||||
if upgraded == source {
|
||||
return Ok(false);
|
||||
}
|
||||
crate::storage::write_atomic(path, upgraded.as_bytes())?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
pub(crate) fn migrate_legacy_data_paths(path: &std::path::Path) -> io::Result<bool> {
|
||||
let Some(data_dir) = dirs_next::data_dir() else {
|
||||
return Ok(false);
|
||||
};
|
||||
migrate_legacy_data_paths_from(path, &data_dir)
|
||||
}
|
||||
|
||||
fn migrate_legacy_data_paths_from(
|
||||
path: &std::path::Path,
|
||||
data_dir: &std::path::Path,
|
||||
) -> io::Result<bool> {
|
||||
let source = match fs::read_to_string(path) {
|
||||
Ok(source) => source,
|
||||
Err(error) if error.kind() == io::ErrorKind::NotFound => return Ok(false),
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
let mut document = parse_toml_document(path, &source)?;
|
||||
let Some(paths) = document
|
||||
.get_mut("paths")
|
||||
.and_then(toml_edit::Item::as_table_mut)
|
||||
else {
|
||||
return Ok(false);
|
||||
};
|
||||
let old_root = data_dir.join("mcl");
|
||||
let new_root = data_dir.join("rmcl");
|
||||
let mut changed = false;
|
||||
for (key, old_path, replacement) in [
|
||||
(
|
||||
"instances_dir",
|
||||
old_root.join("instances"),
|
||||
new_root.join("instances"),
|
||||
),
|
||||
("meta_dir", old_root.join("meta"), new_root.join("meta")),
|
||||
] {
|
||||
let Some(value) = paths.get_mut(key).and_then(toml_edit::Item::as_value_mut) else {
|
||||
continue;
|
||||
};
|
||||
if value
|
||||
.as_str()
|
||||
.is_some_and(|raw| settings::resolve_path(raw) == old_path)
|
||||
{
|
||||
let decor = value.decor().clone();
|
||||
*value = toml_edit::Value::from(replacement.to_string_lossy().into_owned());
|
||||
*value.decor_mut() = decor;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
crate::storage::write_atomic(path, document.to_string().as_bytes())?;
|
||||
}
|
||||
Ok(changed)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct LauncherSettingsSave {
|
||||
pub restart_required: bool,
|
||||
pub restart_changed: bool,
|
||||
pub provider_changed: bool,
|
||||
pub modpack_updates_enabled: bool,
|
||||
pub content_updates_enabled: bool,
|
||||
}
|
||||
|
||||
pub struct ConfigStore(RwLock<Config>);
|
||||
|
||||
impl ConfigStore {
|
||||
pub fn read(&self) -> RwLockReadGuard<'_, Config> {
|
||||
self.0
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
}
|
||||
|
||||
pub fn save_launcher_settings(&self, edited: Config) -> io::Result<LauncherSettingsSave> {
|
||||
let path = get_config_path().join("config.toml");
|
||||
let current = self.read().clone();
|
||||
let edited = edited.normalize();
|
||||
let persisted = load_config(&path).unwrap_or_else(|_| current.clone());
|
||||
let restart_required = current.paths.instances_dir != edited.paths.instances_dir
|
||||
|| current.paths.meta_dir != edited.paths.meta_dir
|
||||
|| current.ui.image_protocol != edited.ui.image_protocol;
|
||||
let restart_changed = persisted.paths.instances_dir != edited.paths.instances_dir
|
||||
|| persisted.paths.meta_dir != edited.paths.meta_dir
|
||||
|| persisted.ui.image_protocol != edited.ui.image_protocol;
|
||||
let provider_changed = current.content.preferred_provider
|
||||
!= edited.content.preferred_provider
|
||||
|| current.content.preferred_provider_only != edited.content.preferred_provider_only;
|
||||
let modpack_updates_enabled =
|
||||
!current.general.check_modpack_updates && edited.general.check_modpack_updates;
|
||||
let content_updates_enabled =
|
||||
!current.general.check_content_updates && edited.general.check_content_updates;
|
||||
write_config_document(&path, &edited)?;
|
||||
|
||||
let mut runtime = edited;
|
||||
runtime
|
||||
.paths
|
||||
.instances_dir
|
||||
.clone_from(¤t.paths.instances_dir);
|
||||
runtime.paths.meta_dir.clone_from(¤t.paths.meta_dir);
|
||||
runtime.ui.image_protocol = current.ui.image_protocol;
|
||||
*self
|
||||
.0
|
||||
.write()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner) = runtime;
|
||||
crate::feedback::errors::set_max_error_events(self.read().ui.max_error_events);
|
||||
Ok(LauncherSettingsSave {
|
||||
restart_required,
|
||||
restart_changed,
|
||||
provider_changed,
|
||||
modpack_updates_enabled,
|
||||
content_updates_enabled,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn reload(&self) -> Result<LauncherSettingsSave, ConfigError> {
|
||||
let mut config = load_config(&get_config_path().join("config.toml"))?;
|
||||
let outcome = {
|
||||
let current = self.read();
|
||||
let restart_required = current.paths.instances_dir != config.paths.instances_dir
|
||||
|| current.paths.meta_dir != config.paths.meta_dir
|
||||
|| current.ui.image_protocol != config.ui.image_protocol;
|
||||
let provider_changed = current.content.preferred_provider
|
||||
!= config.content.preferred_provider
|
||||
|| current.content.preferred_provider_only
|
||||
!= config.content.preferred_provider_only;
|
||||
let modpack_updates_enabled =
|
||||
!current.general.check_modpack_updates && config.general.check_modpack_updates;
|
||||
let content_updates_enabled =
|
||||
!current.general.check_content_updates && config.general.check_content_updates;
|
||||
// App owns a manager and several watchers rooted at these paths.
|
||||
// Keep them stable for this process; persisted path edits apply on restart.
|
||||
config
|
||||
.paths
|
||||
.instances_dir
|
||||
.clone_from(¤t.paths.instances_dir);
|
||||
config.paths.meta_dir.clone_from(¤t.paths.meta_dir);
|
||||
config.ui.image_protocol = current.ui.image_protocol;
|
||||
LauncherSettingsSave {
|
||||
restart_required,
|
||||
restart_changed: restart_required,
|
||||
provider_changed,
|
||||
modpack_updates_enabled,
|
||||
content_updates_enabled,
|
||||
}
|
||||
};
|
||||
*self
|
||||
.0
|
||||
.write()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner) = config;
|
||||
crate::feedback::errors::set_max_error_events(self.read().ui.max_error_events);
|
||||
Ok(outcome)
|
||||
}
|
||||
}
|
||||
|
||||
pub static SETTINGS: LazyLock<ConfigStore> = LazyLock::new(|| {
|
||||
let config = {
|
||||
let path = ensure_config_exists();
|
||||
load_config(&path).unwrap_or_else(|e| {
|
||||
tracing::error!("Config load failed, using defaults: {}", e);
|
||||
Config::default()
|
||||
})
|
||||
};
|
||||
crate::feedback::errors::set_max_error_events(config.ui.max_error_events);
|
||||
ConfigStore(RwLock::new(config))
|
||||
});
|
||||
|
||||
fn write_config_document(path: &std::path::Path, config: &Config) -> io::Result<()> {
|
||||
write_merged_toml_document(path, config, |document| {
|
||||
if config.paths.java_path.is_none()
|
||||
&& let Some(paths) = document
|
||||
.get_mut("paths")
|
||||
.and_then(|item| item.as_table_mut())
|
||||
{
|
||||
paths.remove("java_path");
|
||||
}
|
||||
let default_paths = settings::Paths::default();
|
||||
if let Some(paths) = document
|
||||
.get_mut("paths")
|
||||
.and_then(|item| item.as_table_mut())
|
||||
{
|
||||
if config.paths.instances_dir == default_paths.instances_dir {
|
||||
paths.remove("instances_dir");
|
||||
}
|
||||
if config.paths.meta_dir == default_paths.meta_dir {
|
||||
paths.remove("meta_dir");
|
||||
}
|
||||
}
|
||||
if config.defaults.resolution.is_none()
|
||||
&& let Some(defaults) = document
|
||||
.get_mut("defaults")
|
||||
.and_then(|item| item.as_table_mut())
|
||||
{
|
||||
defaults.remove("resolution");
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn write_merged_toml_document<T, F>(
|
||||
path: &std::path::Path,
|
||||
value: &T,
|
||||
edit: F,
|
||||
) -> io::Result<()>
|
||||
where
|
||||
T: serde::Serialize,
|
||||
F: FnOnce(&mut toml_edit::DocumentMut),
|
||||
{
|
||||
let source = match fs::read_to_string(path) {
|
||||
Ok(source) => source,
|
||||
Err(error) if error.kind() == io::ErrorKind::NotFound => String::new(),
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
let mut document = parse_toml_document(path, &source)?;
|
||||
let generated = toml::to_string_pretty(value)
|
||||
.map_err(io::Error::other)?
|
||||
.parse::<toml_edit::DocumentMut>()
|
||||
.map_err(io::Error::other)?;
|
||||
merge_table(document.as_table_mut(), generated.as_table());
|
||||
edit(&mut document);
|
||||
crate::storage::write_atomic(path, document.to_string().as_bytes())
|
||||
}
|
||||
|
||||
fn parse_toml_document(path: &std::path::Path, source: &str) -> io::Result<toml_edit::DocumentMut> {
|
||||
source.parse::<toml_edit::DocumentMut>().map_err(|error| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::InvalidData,
|
||||
format!("cannot update {}: {error}", path.display()),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn merge_table(target: &mut toml_edit::Table, source: &toml_edit::Table) {
|
||||
for (key, source_item) in source {
|
||||
if let Some(target_item) = target.get_mut(key) {
|
||||
if let (Some(target_table), Some(source_table)) =
|
||||
(target_item.as_table_mut(), source_item.as_table())
|
||||
{
|
||||
merge_table(target_table, source_table);
|
||||
continue;
|
||||
}
|
||||
if let (Some(target_value), Some(source_value)) =
|
||||
(target_item.as_value_mut(), source_item.as_value())
|
||||
{
|
||||
let decor = target_value.decor().clone();
|
||||
*target_value = source_value.clone();
|
||||
*target_value.decor_mut() = decor;
|
||||
continue;
|
||||
}
|
||||
*target_item = source_item.clone();
|
||||
} else {
|
||||
target.insert(key, source_item.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn merge_missing_table(target: &mut toml_edit::Table, defaults: &toml_edit::Table) {
|
||||
for (key, default_item) in defaults {
|
||||
if let Some(target_item) = target.get_mut(key) {
|
||||
if let (Some(target_table), Some(default_table)) =
|
||||
(target_item.as_table_mut(), default_item.as_table())
|
||||
{
|
||||
merge_missing_table(target_table, default_table);
|
||||
}
|
||||
} else {
|
||||
target.insert(key, default_item.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "tests/loading.rs"]
|
||||
|
||||
+203
-17
@@ -4,29 +4,103 @@
|
||||
// all the config structs that map to sections in config.toml.
|
||||
// everything has sane defaults so a blank file (or no file) still works.
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
fmt,
|
||||
path::PathBuf,
|
||||
};
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Default, Clone, Copy, PartialEq, Eq)]
|
||||
use crate::instance::models::{WindowMode, memory_kib, normalize_memory_value};
|
||||
|
||||
pub const DEFAULT_RESOLUTION: (u32, u32) = (854, 480);
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default, Clone, Copy, PartialEq, Eq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ImageProtocol {
|
||||
#[default]
|
||||
Auto,
|
||||
Halfblocks,
|
||||
Quadrants,
|
||||
#[default]
|
||||
Kitty,
|
||||
Iterm2,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Default)]
|
||||
pub struct General {}
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ShortcutHintScope {
|
||||
All,
|
||||
Main,
|
||||
Instances,
|
||||
Content,
|
||||
Accounts,
|
||||
Settings,
|
||||
Popups,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
impl ShortcutHintScope {
|
||||
pub const AREAS: [Self; 5] = [
|
||||
Self::Instances,
|
||||
Self::Content,
|
||||
Self::Accounts,
|
||||
Self::Settings,
|
||||
Self::Popups,
|
||||
];
|
||||
}
|
||||
|
||||
impl fmt::Display for ImageProtocol {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Auto => formatter.write_str("auto"),
|
||||
Self::Halfblocks => formatter.write_str("halfblocks"),
|
||||
Self::Quadrants => formatter.write_str("quadrants"),
|
||||
Self::Kitty => formatter.write_str("kitty"),
|
||||
Self::Iterm2 => formatter.write_str("iterm2"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct General {
|
||||
#[serde(default = "default_true")]
|
||||
pub check_modpack_updates: bool,
|
||||
#[serde(default = "default_true")]
|
||||
pub check_content_updates: bool,
|
||||
}
|
||||
|
||||
impl Default for General {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
check_modpack_updates: true,
|
||||
check_content_updates: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ContentProvider {
|
||||
#[default]
|
||||
Modrinth,
|
||||
CurseForge,
|
||||
}
|
||||
|
||||
impl fmt::Display for ContentProvider {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Modrinth => formatter.write_str("Modrinth"),
|
||||
Self::CurseForge => formatter.write_str("CurseForge"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Content {
|
||||
#[serde(default = "default_true")]
|
||||
pub ask_on_provider_conflict: bool,
|
||||
#[serde(default = "default_provider")]
|
||||
pub preferred_provider: String,
|
||||
#[serde(default, deserialize_with = "deserialize_content_provider")]
|
||||
pub preferred_provider: ContentProvider,
|
||||
#[serde(default)]
|
||||
pub preferred_provider_only: bool,
|
||||
#[serde(default = "default_unmatched_retry_hours")]
|
||||
@@ -39,8 +113,16 @@ fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_provider() -> String {
|
||||
"modrinth".to_owned()
|
||||
fn deserialize_content_provider<'de, D>(deserializer: D) -> Result<ContentProvider, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let value = String::deserialize(deserializer)?;
|
||||
Ok(if value.eq_ignore_ascii_case("curseforge") {
|
||||
ContentProvider::CurseForge
|
||||
} else {
|
||||
ContentProvider::Modrinth
|
||||
})
|
||||
}
|
||||
|
||||
fn default_unmatched_retry_hours() -> u64 {
|
||||
@@ -55,7 +137,7 @@ impl Default for Content {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
ask_on_provider_conflict: true,
|
||||
preferred_provider: default_provider(),
|
||||
preferred_provider: ContentProvider::default(),
|
||||
preferred_provider_only: false,
|
||||
unmatched_retry_hours: default_unmatched_retry_hours(),
|
||||
max_fingerprint_size_mib: default_max_fingerprint_size_mib(),
|
||||
@@ -80,7 +162,7 @@ impl Content {
|
||||
}
|
||||
|
||||
fn preferred_provider_with_curseforge(&self, curseforge_available: bool) -> &'static str {
|
||||
if self.preferred_provider.eq_ignore_ascii_case("curseforge") && curseforge_available {
|
||||
if self.preferred_provider == ContentProvider::CurseForge && curseforge_available {
|
||||
"curseforge"
|
||||
} else {
|
||||
"modrinth"
|
||||
@@ -119,13 +201,16 @@ impl Content {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Paths {
|
||||
#[serde(default = "default_instances_dir")]
|
||||
#[serde(skip_serializing_if = "is_default_instances_dir")]
|
||||
pub instances_dir: String,
|
||||
#[serde(default = "default_meta_dir")]
|
||||
#[serde(skip_serializing_if = "is_default_meta_dir")]
|
||||
pub meta_dir: String,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub java_path: Option<String>,
|
||||
}
|
||||
|
||||
@@ -138,6 +223,10 @@ fn default_instances_dir() -> String {
|
||||
.into_owned()
|
||||
}
|
||||
|
||||
fn is_default_instances_dir(path: &str) -> bool {
|
||||
path == default_instances_dir()
|
||||
}
|
||||
|
||||
fn default_meta_dir() -> String {
|
||||
dirs_next::data_dir()
|
||||
.unwrap_or_else(|| PathBuf::from("."))
|
||||
@@ -147,6 +236,10 @@ fn default_meta_dir() -> String {
|
||||
.into_owned()
|
||||
}
|
||||
|
||||
fn is_default_meta_dir(path: &str) -> bool {
|
||||
path == default_meta_dir()
|
||||
}
|
||||
|
||||
impl Default for Paths {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
@@ -185,12 +278,21 @@ impl Paths {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Defaults {
|
||||
#[serde(default = "default_memory_min")]
|
||||
pub memory_min: String,
|
||||
#[serde(default = "default_memory_max")]
|
||||
pub memory_max: String,
|
||||
#[serde(default)]
|
||||
pub jvm_args: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub environment: BTreeMap<String, String>,
|
||||
#[serde(default)]
|
||||
pub window_mode: WindowMode,
|
||||
#[serde(default = "default_resolution")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub resolution: Option<(u32, u32)>,
|
||||
}
|
||||
|
||||
fn default_memory_min() -> String {
|
||||
@@ -200,21 +302,31 @@ fn default_memory_max() -> String {
|
||||
"2G".to_owned()
|
||||
}
|
||||
|
||||
fn default_resolution() -> Option<(u32, u32)> {
|
||||
Some(DEFAULT_RESOLUTION)
|
||||
}
|
||||
|
||||
impl Default for Defaults {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
memory_min: default_memory_min(),
|
||||
memory_max: default_memory_max(),
|
||||
jvm_args: Vec::new(),
|
||||
environment: BTreeMap::new(),
|
||||
window_mode: WindowMode::default(),
|
||||
resolution: default_resolution(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
// timing knobs for the error toast animation: show for 5s, start sliding at 3.5s,
|
||||
// fly off screen over 300ms. tweak these if the toasts feel too fast or slow.
|
||||
pub struct Ui {
|
||||
#[serde(default)]
|
||||
pub image_protocol: ImageProtocol,
|
||||
#[serde(default)]
|
||||
pub hidden_shortcut_hints: BTreeSet<ShortcutHintScope>,
|
||||
#[serde(default = "default_error_auto_dismiss_ms")]
|
||||
pub error_auto_dismiss_ms: u64,
|
||||
#[serde(default = "default_error_slide_start_ms")]
|
||||
@@ -242,6 +354,7 @@ impl Default for Ui {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
image_protocol: ImageProtocol::default(),
|
||||
hidden_shortcut_hints: BTreeSet::new(),
|
||||
error_auto_dismiss_ms: default_error_auto_dismiss_ms(),
|
||||
error_slide_start_ms: default_error_slide_start_ms(),
|
||||
error_fly_out_ms: default_error_fly_out_ms(),
|
||||
@@ -250,7 +363,40 @@ impl Default for Ui {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
impl Ui {
|
||||
pub fn show_shortcut_hints(&self, scope: ShortcutHintScope) -> bool {
|
||||
!self.hidden_shortcut_hints.contains(&ShortcutHintScope::All)
|
||||
&& !(scope != ShortcutHintScope::Popups
|
||||
&& self
|
||||
.hidden_shortcut_hints
|
||||
.contains(&ShortcutHintScope::Main))
|
||||
&& !self.hidden_shortcut_hints.contains(&scope)
|
||||
}
|
||||
|
||||
pub fn set_shortcut_hints(&mut self, scope: ShortcutHintScope, visible: bool) {
|
||||
let mut hidden = ShortcutHintScope::AREAS
|
||||
.into_iter()
|
||||
.filter(|area| !self.show_shortcut_hints(*area))
|
||||
.collect::<BTreeSet<_>>();
|
||||
if visible {
|
||||
hidden.remove(&scope);
|
||||
} else {
|
||||
hidden.insert(scope);
|
||||
}
|
||||
self.hidden_shortcut_hints = if hidden.len() == ShortcutHintScope::AREAS.len() {
|
||||
[ShortcutHintScope::All].into_iter().collect()
|
||||
} else if ShortcutHintScope::AREAS[..4]
|
||||
.iter()
|
||||
.all(|area| hidden.contains(area))
|
||||
{
|
||||
[ShortcutHintScope::Main].into_iter().collect()
|
||||
} else {
|
||||
hidden
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
#[serde(default)]
|
||||
pub general: General,
|
||||
@@ -264,6 +410,46 @@ pub struct Config {
|
||||
pub content: Content,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn normalize(mut self) -> Self {
|
||||
if self.paths.instances_dir.trim().is_empty() {
|
||||
self.paths.instances_dir = default_instances_dir();
|
||||
}
|
||||
if self.paths.meta_dir.trim().is_empty() {
|
||||
self.paths.meta_dir = default_meta_dir();
|
||||
}
|
||||
self.paths.java_path = self
|
||||
.paths
|
||||
.java_path
|
||||
.take()
|
||||
.and_then(|path| (!path.trim().is_empty()).then(|| path.trim().to_owned()));
|
||||
self.defaults.memory_min =
|
||||
normalize_memory_value(&self.defaults.memory_min).unwrap_or_else(default_memory_min);
|
||||
self.defaults.memory_max =
|
||||
normalize_memory_value(&self.defaults.memory_max).unwrap_or_else(default_memory_max);
|
||||
if memory_kib(&self.defaults.memory_min) > memory_kib(&self.defaults.memory_max) {
|
||||
self.defaults
|
||||
.memory_max
|
||||
.clone_from(&self.defaults.memory_min);
|
||||
}
|
||||
if self
|
||||
.defaults
|
||||
.resolution
|
||||
.is_none_or(|(width, height)| width == 0 || height == 0)
|
||||
{
|
||||
self.defaults.resolution = default_resolution();
|
||||
}
|
||||
self.ui.error_auto_dismiss_ms = self.ui.error_auto_dismiss_ms.max(1);
|
||||
self.ui.error_slide_start_ms = self
|
||||
.ui
|
||||
.error_slide_start_ms
|
||||
.min(self.ui.error_auto_dismiss_ms);
|
||||
self.ui.error_fly_out_ms = self.ui.error_fly_out_ms.min(self.ui.error_auto_dismiss_ms);
|
||||
self.ui.max_error_events = self.ui.max_error_events.max(1);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "tests/settings.rs"]
|
||||
mod tests;
|
||||
@@ -54,3 +54,161 @@ fn load_config_partial_sections() {
|
||||
assert_eq!(config.paths.instances_dir, "/custom/path");
|
||||
assert!(config.paths.java_path.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bundled_config_uses_platform_paths_and_automatic_java() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let path = tmp.path().join("config.toml");
|
||||
std::fs::write(&path, include_str!("../../../assets/config.toml")).unwrap();
|
||||
let config = load_config(&path).unwrap();
|
||||
assert_eq!(
|
||||
config.paths.instances_dir,
|
||||
settings::Paths::default().instances_dir
|
||||
);
|
||||
assert_eq!(config.paths.meta_dir, settings::Paths::default().meta_dir);
|
||||
assert!(config.paths.java_path.is_none());
|
||||
assert_eq!(config.ui.image_protocol, settings::ImageProtocol::Auto);
|
||||
assert_eq!(
|
||||
config.defaults.resolution,
|
||||
Some(settings::DEFAULT_RESOLUTION)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_normalizes_memory_java_and_notification_bounds() {
|
||||
let config = Config {
|
||||
paths: settings::Paths {
|
||||
instances_dir: String::new(),
|
||||
meta_dir: " ".to_owned(),
|
||||
java_path: Some(" ".to_owned()),
|
||||
},
|
||||
defaults: settings::Defaults {
|
||||
memory_min: "invalid".to_owned(),
|
||||
memory_max: "1G".to_owned(),
|
||||
resolution: Some((0, 1080)),
|
||||
..Default::default()
|
||||
},
|
||||
ui: settings::Ui {
|
||||
error_auto_dismiss_ms: 100,
|
||||
error_slide_start_ms: 200,
|
||||
error_fly_out_ms: 300,
|
||||
max_error_events: 0,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}
|
||||
.normalize();
|
||||
assert_eq!(
|
||||
config.paths.instances_dir,
|
||||
settings::Paths::default().instances_dir
|
||||
);
|
||||
assert_eq!(config.paths.meta_dir, settings::Paths::default().meta_dir);
|
||||
assert!(config.paths.java_path.is_none());
|
||||
assert_eq!(config.defaults.memory_min, "512M");
|
||||
assert_eq!(config.defaults.memory_max, "1G");
|
||||
assert_eq!(
|
||||
config.defaults.resolution,
|
||||
Some(settings::DEFAULT_RESOLUTION)
|
||||
);
|
||||
assert_eq!(config.ui.error_slide_start_ms, 100);
|
||||
assert_eq!(config.ui.error_fly_out_ms, 100);
|
||||
assert_eq!(config.ui.max_error_events, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settings_writer_preserves_comments_and_unknown_keys() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let path = tmp.path().join("config.toml");
|
||||
std::fs::write(
|
||||
&path,
|
||||
"# keep this comment\n[defaults]\n# heap comment\nmemory_max = \"2G\"\n\n[future]\nvalue = 42\n",
|
||||
)
|
||||
.unwrap();
|
||||
let mut config = Config::default();
|
||||
config.defaults.memory_max = "8G".to_owned();
|
||||
write_config_document(&path, &config).unwrap();
|
||||
let saved = std::fs::read_to_string(path).unwrap();
|
||||
assert!(saved.contains("# keep this comment"), "{saved}");
|
||||
assert!(saved.contains("# heap comment"), "{saved}");
|
||||
assert!(saved.contains("memory_max = \"8G\""));
|
||||
assert!(saved.contains("[future]"));
|
||||
assert!(saved.contains("value = 42"));
|
||||
assert!(!saved.contains("instances_dir"));
|
||||
assert!(!saved.contains("meta_dir"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_upgrade_adds_new_defaults_without_replacing_old_values() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let path = tmp.path().join("config.toml");
|
||||
let old = r#"# user comment
|
||||
[paths]
|
||||
instances_dir = "/custom/instances"
|
||||
meta_dir = "/custom/meta"
|
||||
java_path = "/custom/java"
|
||||
|
||||
[defaults]
|
||||
memory_min = "1G"
|
||||
memory_max = "8G"
|
||||
|
||||
[ui]
|
||||
image_protocol = "kitty"
|
||||
|
||||
[future]
|
||||
value = 42
|
||||
"#;
|
||||
std::fs::write(&path, old).unwrap();
|
||||
|
||||
assert!(upgrade_config_file(&path).unwrap());
|
||||
let upgraded = std::fs::read_to_string(&path).unwrap();
|
||||
let config = load_config(&path).unwrap();
|
||||
|
||||
assert!(upgraded.contains("# user comment"), "{upgraded}");
|
||||
assert!(upgraded.contains("[future]"), "{upgraded}");
|
||||
assert!(upgraded.contains("value = 42"), "{upgraded}");
|
||||
assert!(upgraded.contains("jvm_args = []"), "{upgraded}");
|
||||
assert!(
|
||||
upgraded.contains("check_modpack_updates = true"),
|
||||
"{upgraded}"
|
||||
);
|
||||
assert_eq!(config.paths.instances_dir, "/custom/instances");
|
||||
assert_eq!(config.paths.meta_dir, "/custom/meta");
|
||||
assert_eq!(config.paths.java_path.as_deref(), Some("/custom/java"));
|
||||
assert_eq!(config.defaults.memory_min, "1G");
|
||||
assert_eq!(config.defaults.memory_max, "8G");
|
||||
assert_eq!(config.ui.image_protocol, settings::ImageProtocol::Kitty);
|
||||
|
||||
assert!(!upgrade_config_file(&path).unwrap());
|
||||
assert_eq!(std::fs::read_to_string(path).unwrap(), upgraded);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_default_data_paths_follow_the_renamed_data_directory() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let path = tmp.path().join("config.toml");
|
||||
let data = tmp.path().join("data");
|
||||
std::fs::write(
|
||||
&path,
|
||||
format!(
|
||||
"[paths]\ninstances_dir = {:?}\nmeta_dir = {:?}\n",
|
||||
data.join("mcl/instances").to_string_lossy(),
|
||||
data.join("mcl/meta").to_string_lossy()
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert!(migrate_legacy_data_paths_from(&path, &data).unwrap());
|
||||
let migrated = std::fs::read_to_string(&path).unwrap();
|
||||
let config = load_config(&path).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
settings::resolve_path(&config.paths.instances_dir),
|
||||
data.join("rmcl").join("instances"),
|
||||
"{migrated}"
|
||||
);
|
||||
assert_eq!(
|
||||
settings::resolve_path(&config.paths.meta_dir),
|
||||
data.join("rmcl").join("meta"),
|
||||
"{migrated}"
|
||||
);
|
||||
}
|
||||
@@ -66,6 +66,11 @@ fn content_provider_settings_are_normalized() {
|
||||
merged.discovery_provider_label_with_curseforge(true),
|
||||
"providers"
|
||||
);
|
||||
|
||||
let legacy: Content = toml::from_str("preferred_provider = \"CurseForge\"").unwrap();
|
||||
assert_eq!(legacy.preferred_provider, ContentProvider::CurseForge);
|
||||
let unknown: Content = toml::from_str("preferred_provider = \"unknown\"").unwrap();
|
||||
assert_eq!(unknown.preferred_provider, ContentProvider::Modrinth);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -105,3 +110,28 @@ memory_max = "8G"
|
||||
assert_eq!(config.defaults.memory_max, "8G");
|
||||
assert_eq!(config.defaults.memory_min, "512M");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shortcut_hints_support_global_main_and_selective_hiding() {
|
||||
let mut ui: Ui = toml::from_str("hidden_shortcut_hints = []").unwrap();
|
||||
assert!(
|
||||
ShortcutHintScope::AREAS
|
||||
.iter()
|
||||
.all(|scope| ui.show_shortcut_hints(*scope))
|
||||
);
|
||||
|
||||
ui = toml::from_str("hidden_shortcut_hints = [\"main\"]").unwrap();
|
||||
assert!(!ui.show_shortcut_hints(ShortcutHintScope::Instances));
|
||||
assert!(ui.show_shortcut_hints(ShortcutHintScope::Popups));
|
||||
|
||||
ui.set_shortcut_hints(ShortcutHintScope::Content, true);
|
||||
assert!(ui.show_shortcut_hints(ShortcutHintScope::Content));
|
||||
assert!(!ui.show_shortcut_hints(ShortcutHintScope::Accounts));
|
||||
|
||||
ui.hidden_shortcut_hints = [ShortcutHintScope::All].into_iter().collect();
|
||||
assert!(
|
||||
ShortcutHintScope::AREAS
|
||||
.iter()
|
||||
.all(|scope| !ui.show_shortcut_hints(*scope))
|
||||
);
|
||||
}
|
||||
+131
-7
@@ -6,7 +6,7 @@
|
||||
// config/theme/ directory or by absolute path.
|
||||
|
||||
use std::path::Path;
|
||||
use std::sync::LazyLock;
|
||||
use std::sync::{Arc, LazyLock, RwLock};
|
||||
|
||||
use ratatui::style::Color;
|
||||
use ratatui::widgets::BorderType;
|
||||
@@ -34,7 +34,7 @@ impl BorderStyle {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Default)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct ThemeOverrides {
|
||||
pub accent: Option<Color>,
|
||||
pub accent_dim: Option<Color>,
|
||||
@@ -53,7 +53,7 @@ pub struct ThemeOverrides {
|
||||
pub background: Option<Color>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ThemeConfig {
|
||||
#[serde(default)]
|
||||
pub border_style: BorderStyle,
|
||||
@@ -167,12 +167,136 @@ fn load_base_theme(name: &str) -> Box<dyn Theme> {
|
||||
resolve_theme(name)
|
||||
}
|
||||
|
||||
static THEME_CONFIG: LazyLock<ThemeConfig> = LazyLock::new(load_theme_config);
|
||||
pub struct ThemeStore(RwLock<Arc<dyn Theme>>);
|
||||
|
||||
pub static THEME: LazyLock<Box<dyn Theme>> = LazyLock::new(|| resolve_app_theme(&THEME_CONFIG));
|
||||
impl ThemeStore {
|
||||
pub fn as_ref(&self) -> Arc<dyn Theme> {
|
||||
self.0
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.clone()
|
||||
}
|
||||
|
||||
pub static BORDER_STYLE: LazyLock<BorderStyle> =
|
||||
LazyLock::new(|| THEME_CONFIG.border_style.clone());
|
||||
fn set(&self, theme: Box<dyn Theme>) {
|
||||
*self
|
||||
.0
|
||||
.write()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner) = Arc::from(theme);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BorderStyleStore(RwLock<BorderStyle>);
|
||||
|
||||
impl BorderStyleStore {
|
||||
pub fn to_border_type(&self) -> BorderType {
|
||||
self.current().to_border_type()
|
||||
}
|
||||
|
||||
pub fn current(&self) -> BorderStyle {
|
||||
self.0
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.clone()
|
||||
}
|
||||
|
||||
fn set(&self, style: BorderStyle) {
|
||||
*self
|
||||
.0
|
||||
.write()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner) = style;
|
||||
}
|
||||
}
|
||||
|
||||
static THEME_CONFIG: LazyLock<RwLock<ThemeConfig>> =
|
||||
LazyLock::new(|| RwLock::new(load_theme_config()));
|
||||
|
||||
pub static THEME: LazyLock<ThemeStore> = LazyLock::new(|| {
|
||||
let config = THEME_CONFIG
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
ThemeStore(RwLock::new(Arc::from(resolve_app_theme(&config))))
|
||||
});
|
||||
|
||||
pub static BORDER_STYLE: LazyLock<BorderStyleStore> = LazyLock::new(|| {
|
||||
let config = THEME_CONFIG
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
BorderStyleStore(RwLock::new(config.border_style.clone()))
|
||||
});
|
||||
|
||||
pub fn current_theme_config() -> ThemeConfig {
|
||||
THEME_CONFIG
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.clone()
|
||||
}
|
||||
|
||||
pub fn apply_theme(theme: String, border_style: BorderStyle) -> std::io::Result<()> {
|
||||
validate_theme_name(&theme)?;
|
||||
let mut config = current_theme_config();
|
||||
config.theme = theme;
|
||||
config.border_style = border_style.clone();
|
||||
super::write_merged_toml_document(
|
||||
&super::get_config_path().join("theme.toml"),
|
||||
&config,
|
||||
|document| {
|
||||
if config.custom.is_none() {
|
||||
document.as_table_mut().remove("custom");
|
||||
}
|
||||
},
|
||||
)?;
|
||||
THEME.set(resolve_app_theme(&config));
|
||||
BORDER_STYLE.set(border_style);
|
||||
*THEME_CONFIG
|
||||
.write()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner) = config;
|
||||
crate::feedback::request_redraw();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_theme_name(name: &str) -> std::io::Result<()> {
|
||||
if ratatui_themekit::available_theme_ids().contains(&name) {
|
||||
return Ok(());
|
||||
}
|
||||
let path = if Path::new(name).is_absolute() {
|
||||
std::path::PathBuf::from(name)
|
||||
} else {
|
||||
let directory = super::get_config_path().join("theme");
|
||||
let direct = directory.join(name);
|
||||
if direct.exists() {
|
||||
direct
|
||||
} else {
|
||||
directory.join(format!("{name}.toml"))
|
||||
}
|
||||
};
|
||||
let content = std::fs::read_to_string(&path).map_err(|error| {
|
||||
std::io::Error::new(
|
||||
error.kind(),
|
||||
format!("failed to load theme {}: {error}", path.display()),
|
||||
)
|
||||
})?;
|
||||
toml::from_str::<CustomTheme>(&content).map_err(|error| {
|
||||
std::io::Error::new(
|
||||
std::io::ErrorKind::InvalidData,
|
||||
format!("invalid theme {}: {error}", path.display()),
|
||||
)
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn reload_theme() -> std::io::Result<()> {
|
||||
let path = super::get_config_path().join("theme.toml");
|
||||
let content = std::fs::read_to_string(path)?;
|
||||
let config: ThemeConfig = toml::from_str(&content)
|
||||
.map_err(|error| std::io::Error::new(std::io::ErrorKind::InvalidData, error))?;
|
||||
THEME.set(resolve_app_theme(&config));
|
||||
BORDER_STYLE.set(config.border_style.clone());
|
||||
*THEME_CONFIG
|
||||
.write()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner) = config;
|
||||
crate::feedback::request_redraw();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "tests/theme.rs"]
|
||||
|
||||
+23
-3
@@ -9,15 +9,25 @@
|
||||
// used by the render layer to track per-toast animation state.
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Instant;
|
||||
|
||||
use std::sync::LazyLock;
|
||||
use tracing::Level;
|
||||
|
||||
const MAX_ERROR_EVENTS: usize = 50;
|
||||
static NEXT_ERROR_ID: AtomicU64 = AtomicU64::new(1);
|
||||
static MAX_ERROR_EVENTS: AtomicUsize = AtomicUsize::new(50);
|
||||
|
||||
pub(crate) fn set_max_error_events(max_events: usize) {
|
||||
let max_events = max_events.max(1);
|
||||
MAX_ERROR_EVENTS.store(max_events, Ordering::Relaxed);
|
||||
if let Ok(mut events) = ERROR_EVENTS.lock() {
|
||||
while events.len() > max_events {
|
||||
events.pop_front();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ErrorEvent {
|
||||
@@ -38,7 +48,8 @@ pub fn push_error(event: ErrorEvent) {
|
||||
|
||||
events.push_back(event);
|
||||
|
||||
while events.len() > MAX_ERROR_EVENTS {
|
||||
let max_events = MAX_ERROR_EVENTS.load(Ordering::Relaxed);
|
||||
while events.len() > max_events {
|
||||
events.pop_front();
|
||||
}
|
||||
super::request_redraw();
|
||||
@@ -49,6 +60,15 @@ pub fn push_error(event: ErrorEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push_message(level: Level, message: impl Into<String>) {
|
||||
push_error(ErrorEvent {
|
||||
id: 0,
|
||||
level,
|
||||
message: message.into(),
|
||||
pushed_at: Instant::now(),
|
||||
});
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn has_errors() -> bool {
|
||||
match ERROR_EVENTS.lock() {
|
||||
|
||||
@@ -72,13 +72,15 @@ fn overflow_drops_oldest() {
|
||||
let _guard = TEST_LOCK.lock().unwrap();
|
||||
clear_errors_for_test();
|
||||
|
||||
for i in 0..(MAX_ERROR_EVENTS + 10) {
|
||||
let max_error_events = 50;
|
||||
set_max_error_events(max_error_events);
|
||||
for i in 0..(max_error_events + 10) {
|
||||
push_error(make_event(&format!("overflow_{i}")));
|
||||
}
|
||||
|
||||
let all = peek_all_errors();
|
||||
|
||||
assert_eq!(all.len(), MAX_ERROR_EVENTS);
|
||||
assert_eq!(all.len(), max_error_events);
|
||||
|
||||
assert!(!all.iter().any(|e| e.message == "overflow_0"));
|
||||
assert!(!all.iter().any(|e| e.message == "overflow_9"));
|
||||
@@ -86,3 +88,21 @@ fn overflow_drops_oldest() {
|
||||
assert!(all.iter().any(|e| e.message == "overflow_10"));
|
||||
assert!(all.iter().any(|e| e.message == "overflow_59"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lowering_limit_trims_existing_events_immediately() {
|
||||
let _guard = TEST_LOCK.lock().unwrap();
|
||||
clear_errors_for_test();
|
||||
set_max_error_events(5);
|
||||
for i in 0..5 {
|
||||
push_error(make_event(&format!("trim_{i}")));
|
||||
}
|
||||
|
||||
set_max_error_events(2);
|
||||
let all = peek_all_errors();
|
||||
|
||||
assert_eq!(all.len(), 2);
|
||||
assert_eq!(all[0].message, "trim_4");
|
||||
assert_eq!(all[1].message, "trim_3");
|
||||
set_max_error_events(50);
|
||||
}
|
||||
@@ -113,7 +113,7 @@ pub fn switch_profile(
|
||||
meta_dir: &Path,
|
||||
instance_dir: &Path,
|
||||
) -> Result<Option<String>, ConfigSyncError> {
|
||||
if crate::instance::runtime::get(instance_name).is_some() {
|
||||
if crate::instance::runtime::is_active(instance_name) {
|
||||
return Err(ConfigSyncError::InstanceRunning {
|
||||
instance: instance_name.to_string(),
|
||||
});
|
||||
|
||||
@@ -151,8 +151,13 @@ async fn reconcile(job: ReconcileJob, task: &ProgressTask) -> ReconcileResult {
|
||||
let paths = InstancePaths::new(instances_dir.join(&instance_name));
|
||||
let manifest_path = paths.content_manifest();
|
||||
let minecraft_dir = paths.minecraft();
|
||||
let retry_hours = crate::config::SETTINGS.content.unmatched_retry_hours;
|
||||
let max_fingerprint_size_mib = crate::config::SETTINGS.content.max_fingerprint_size_mib;
|
||||
let (retry_hours, max_fingerprint_size_mib) = {
|
||||
let settings = crate::config::SETTINGS.read();
|
||||
(
|
||||
settings.content.unmatched_retry_hours,
|
||||
settings.content.max_fingerprint_size_mib,
|
||||
)
|
||||
};
|
||||
let inventory_progress = task.handle();
|
||||
let inventory_minecraft_dir = minecraft_dir.clone();
|
||||
let inventory = tokio::task::spawn_blocking(move || {
|
||||
@@ -400,6 +405,7 @@ fn reconcile_inventory(
|
||||
}
|
||||
let provider_unchecked = ["modrinth", "curseforge"].into_iter().any(|provider| {
|
||||
crate::config::SETTINGS
|
||||
.read()
|
||||
.content
|
||||
.discovery_provider_enabled(provider)
|
||||
&& provider_was_not_checked(&record, provider)
|
||||
@@ -553,8 +559,16 @@ async fn resolve_queries(
|
||||
},
|
||||
Vec::new(),
|
||||
),
|
||||
_ if !crate::config::SETTINGS.content.ask_on_provider_conflict => {
|
||||
let preferred = crate::config::SETTINGS.content.preferred_provider();
|
||||
_ if !crate::config::SETTINGS
|
||||
.read()
|
||||
.content
|
||||
.ask_on_provider_conflict =>
|
||||
{
|
||||
let preferred = crate::config::SETTINGS
|
||||
.read()
|
||||
.content
|
||||
.preferred_provider()
|
||||
.to_owned();
|
||||
if let Some(project) = candidates
|
||||
.iter()
|
||||
.find(|project| project.provider == preferred)
|
||||
|
||||
+69
-19
@@ -45,7 +45,7 @@ pub fn icon_path() -> Option<PathBuf> {
|
||||
// lazily writes the bundled svg icon to disk the first time a shortcut needs it
|
||||
fn ensure_icon() -> Option<PathBuf> {
|
||||
let path = icon_path()?;
|
||||
if path.exists() {
|
||||
if std::fs::read(&path).ok().as_deref() == Some(ICON_BYTES) {
|
||||
return Some(path);
|
||||
}
|
||||
let parent = path.parent()?;
|
||||
@@ -53,7 +53,7 @@ fn ensure_icon() -> Option<PathBuf> {
|
||||
tracing::warn!("Failed to create icon directory: {}", e);
|
||||
return None;
|
||||
}
|
||||
if let Err(e) = std::fs::write(&path, ICON_BYTES) {
|
||||
if let Err(e) = crate::storage::write_atomic(&path, ICON_BYTES) {
|
||||
tracing::warn!("Failed to write bundled icon: {}", e);
|
||||
return None;
|
||||
}
|
||||
@@ -74,7 +74,9 @@ pub fn create(config: &InstanceConfig) -> std::io::Result<PathBuf> {
|
||||
|
||||
let icon = ensure_icon();
|
||||
let content = build_content(&config.name, icon.as_deref());
|
||||
std::fs::write(&path, content)?;
|
||||
if std::fs::read_to_string(&path).ok().as_deref() != Some(content.as_str()) {
|
||||
crate::storage::write_atomic(&path, content.as_bytes())?;
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
@@ -96,22 +98,28 @@ pub fn remove(name: &str) -> std::io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn toggle(config: &InstanceConfig) -> std::io::Result<bool> {
|
||||
if exists(&config.name) {
|
||||
remove(&config.name)?;
|
||||
Ok(false)
|
||||
pub fn set_enabled(config: &InstanceConfig, enabled: bool) -> std::io::Result<()> {
|
||||
if enabled {
|
||||
create(config).map(|_| ())
|
||||
} else {
|
||||
create(config)?;
|
||||
Ok(true)
|
||||
remove(&config.name)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn toggle(config: &InstanceConfig) -> std::io::Result<bool> {
|
||||
let enabled = !exists(&config.name);
|
||||
set_enabled(config, enabled)?;
|
||||
Ok(enabled)
|
||||
}
|
||||
|
||||
pub fn rename(old_name: &str, new_config: &InstanceConfig) -> std::io::Result<()> {
|
||||
if !exists(old_name) {
|
||||
let Some(old_path) = desktop_path(old_name).filter(|path| path.exists()) else {
|
||||
return Ok(());
|
||||
}
|
||||
remove(old_name)?;
|
||||
};
|
||||
create(new_config)?;
|
||||
if desktop_path(&new_config.name).as_ref() != Some(&old_path) {
|
||||
std::fs::remove_file(old_path)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -148,7 +156,10 @@ fn build_linux_desktop(name: &str, icon: Option<&Path>) -> String {
|
||||
out.push_str("Type=Application\n");
|
||||
out.push_str(&format!("Name=Minecraft - {name}\n"));
|
||||
out.push_str(&format!("Comment=Launch {name} Minecraft instance\n"));
|
||||
out.push_str(&format!("Exec=rmcl instance launch \"{name}\"\n"));
|
||||
out.push_str(&format!(
|
||||
"Exec=rmcl instance launch {}\n",
|
||||
quote_desktop_exec_arg(name)
|
||||
));
|
||||
if let Some(icon) = icon {
|
||||
out.push_str(&format!("Icon={}\n", icon.display()));
|
||||
}
|
||||
@@ -159,14 +170,12 @@ fn build_linux_desktop(name: &str, icon: Option<&Path>) -> String {
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn build_windows_shortcut(name: &str) -> String {
|
||||
let escaped_name = name.replace('"', "\"\"");
|
||||
let command = format!("rmcl instance launch {}", quote_windows_arg(name));
|
||||
let escaped_command = command.replace('"', "\"\"");
|
||||
|
||||
let mut out = String::new();
|
||||
out.push_str("Set shell = CreateObject(\"WScript.Shell\")\r\n");
|
||||
out.push_str(&format!(
|
||||
"shell.Run \"rmcl instance launch \"\"{}\"\"\", 0, False\r\n",
|
||||
escaped_name
|
||||
));
|
||||
out.push_str(&format!("shell.Run \"{escaped_command}\", 0, False\r\n"));
|
||||
out
|
||||
}
|
||||
|
||||
@@ -175,10 +184,51 @@ fn build_macos_command(name: &str) -> String {
|
||||
let mut out = String::new();
|
||||
out.push_str("#!/bin/bash\n");
|
||||
out.push_str(&format!("# Launch Minecraft instance: {name}\n"));
|
||||
out.push_str(&format!("rmcl instance launch \"{name}\"\n"));
|
||||
out.push_str(&format!("rmcl instance launch {}\n", quote_shell_arg(name)));
|
||||
out
|
||||
}
|
||||
|
||||
fn quote_desktop_exec_arg(value: &str) -> String {
|
||||
let mut escaped = String::with_capacity(value.len() + 2);
|
||||
escaped.push('"');
|
||||
for character in value.chars() {
|
||||
if matches!(character, '"' | '`' | '$' | '\\') {
|
||||
escaped.push('\\');
|
||||
}
|
||||
escaped.push(character);
|
||||
}
|
||||
escaped.push('"');
|
||||
escaped
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "macos", test))]
|
||||
fn quote_shell_arg(value: &str) -> String {
|
||||
format!("'{}'", value.replace('\'', "'\\''"))
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "windows", test))]
|
||||
fn quote_windows_arg(value: &str) -> String {
|
||||
let mut quoted = String::with_capacity(value.len() + 2);
|
||||
quoted.push('"');
|
||||
let mut backslashes = 0;
|
||||
for character in value.chars() {
|
||||
if character == '\\' {
|
||||
backslashes += 1;
|
||||
} else if character == '"' {
|
||||
quoted.extend(std::iter::repeat_n('\\', backslashes * 2 + 1));
|
||||
quoted.push('"');
|
||||
backslashes = 0;
|
||||
} else {
|
||||
quoted.extend(std::iter::repeat_n('\\', backslashes));
|
||||
quoted.push(character);
|
||||
backslashes = 0;
|
||||
}
|
||||
}
|
||||
quoted.extend(std::iter::repeat_n('\\', backslashes * 2));
|
||||
quoted.push('"');
|
||||
quoted
|
||||
}
|
||||
|
||||
// replaces anything that isn't alphanumeric, dash, or underscore with _
|
||||
fn sanitize(name: &str) -> String {
|
||||
name.chars()
|
||||
|
||||
@@ -55,9 +55,7 @@ pub async fn prepare(
|
||||
instance: &InstanceConfig,
|
||||
target: VersionInfo,
|
||||
) -> Result<RefreshPlan, String> {
|
||||
if crate::instance::runtime::get(&instance.name)
|
||||
.is_some_and(|state| !matches!(state, crate::instance::runtime::RunState::Crashed(_)))
|
||||
{
|
||||
if crate::instance::runtime::is_active(&instance.name) {
|
||||
return Err("Stop the instance before changing its modpack".to_owned());
|
||||
}
|
||||
let source = instance
|
||||
|
||||
@@ -3,6 +3,20 @@
|
||||
|
||||
// java runtime discovery shared by launching, loader installation, and settings.
|
||||
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
path::{Path, PathBuf},
|
||||
process::Command,
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct JavaInstallation {
|
||||
pub path: PathBuf,
|
||||
pub version: Option<String>,
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn detect_java_path() -> String {
|
||||
if let Ok(java_home) = std::env::var("JAVA_HOME") {
|
||||
@@ -32,3 +46,259 @@ pub fn detect_java_path() -> String {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Finds Java executables in the environment and the conventional installation
|
||||
/// directories for the current platform. The search is deliberately bounded so
|
||||
/// opening the selector never walks an entire drive.
|
||||
#[must_use]
|
||||
pub fn discover_installations() -> Vec<JavaInstallation> {
|
||||
let mut candidates = Vec::new();
|
||||
for variable in ["JAVA_HOME", "JDK_HOME"] {
|
||||
if let Ok(java_home) = std::env::var(variable) {
|
||||
add_java_home(Path::new(&java_home), &mut candidates);
|
||||
}
|
||||
}
|
||||
if let Ok(path) = which::which("java") {
|
||||
candidates.push(path);
|
||||
}
|
||||
if let Some(path) = std::env::var_os("PATH") {
|
||||
for directory in std::env::split_paths(&path) {
|
||||
let executable = if cfg!(target_os = "windows") {
|
||||
"java.exe"
|
||||
} else {
|
||||
"java"
|
||||
};
|
||||
candidates.push(directory.join(executable));
|
||||
}
|
||||
}
|
||||
|
||||
for root in java_roots() {
|
||||
collect_java_executables(&root, 3, &mut candidates);
|
||||
}
|
||||
|
||||
let mut seen = HashSet::new();
|
||||
let mut installations = candidates
|
||||
.into_iter()
|
||||
.filter(|path| path.is_file())
|
||||
.filter_map(|path| {
|
||||
let identity = std::fs::canonicalize(&path).unwrap_or_else(|_| path.clone());
|
||||
seen.insert(identity)
|
||||
.then(|| inspect_installation(&path))
|
||||
.flatten()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
installations.sort_by(|a, b| {
|
||||
java_major(b.version.as_deref())
|
||||
.cmp(&java_major(a.version.as_deref()))
|
||||
.then_with(|| a.path.cmp(&b.path))
|
||||
});
|
||||
installations
|
||||
}
|
||||
|
||||
/// Reads the version reported by one Java executable.
|
||||
#[must_use]
|
||||
pub fn inspect_installation(path: &Path) -> Option<JavaInstallation> {
|
||||
path.is_file().then(|| JavaInstallation {
|
||||
version: java_version(path),
|
||||
path: path.to_path_buf(),
|
||||
})
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn load_installation_cache(path: &Path) -> Option<Vec<JavaInstallation>> {
|
||||
let mut installations =
|
||||
serde_json::from_slice::<Vec<JavaInstallation>>(&std::fs::read(path).ok()?).ok()?;
|
||||
installations.retain(|installation| installation.path.is_file());
|
||||
(!installations.is_empty()).then_some(installations)
|
||||
}
|
||||
|
||||
pub fn save_installation_cache(
|
||||
path: &Path,
|
||||
installations: &[JavaInstallation],
|
||||
) -> std::io::Result<()> {
|
||||
let bytes = serde_json::to_vec_pretty(installations).map_err(std::io::Error::other)?;
|
||||
crate::storage::write_atomic(path, &bytes)
|
||||
}
|
||||
|
||||
fn java_roots() -> Vec<PathBuf> {
|
||||
let mut roots = Vec::new();
|
||||
if cfg!(target_os = "windows") {
|
||||
for variable in ["ProgramFiles", "ProgramFiles(x86)", "LOCALAPPDATA"] {
|
||||
if let Some(root) = std::env::var_os(variable) {
|
||||
let root = PathBuf::from(root);
|
||||
roots.extend([
|
||||
root.join("Java"),
|
||||
root.join("Eclipse Adoptium"),
|
||||
root.join("Programs/Eclipse Adoptium"),
|
||||
root.join("Programs/Java"),
|
||||
root.join("Microsoft"),
|
||||
root.join("BellSoft"),
|
||||
root.join("Zulu"),
|
||||
root.join("Amazon Corretto"),
|
||||
]);
|
||||
}
|
||||
}
|
||||
} else if cfg!(target_os = "macos") {
|
||||
roots.push(PathBuf::from("/Library/Java/JavaVirtualMachines"));
|
||||
for prefix in ["/opt/homebrew/opt", "/usr/local/opt"] {
|
||||
for formula in [
|
||||
"openjdk",
|
||||
"openjdk@8",
|
||||
"openjdk@11",
|
||||
"openjdk@17",
|
||||
"openjdk@21",
|
||||
] {
|
||||
roots.push(PathBuf::from(prefix).join(formula));
|
||||
}
|
||||
}
|
||||
if let Some(home) = dirs_next::home_dir() {
|
||||
roots.push(home.join("Library/Java/JavaVirtualMachines"));
|
||||
roots.push(home.join(".sdkman/candidates/java"));
|
||||
roots.push(home.join(".asdf/installs/java"));
|
||||
roots.push(home.join(".local/share/mise/installs/java"));
|
||||
}
|
||||
} else {
|
||||
roots.extend([
|
||||
PathBuf::from("/usr/lib/jvm"),
|
||||
PathBuf::from("/usr/java"),
|
||||
PathBuf::from("/opt/java"),
|
||||
PathBuf::from("/opt/jdk"),
|
||||
]);
|
||||
if let Some(home) = dirs_next::home_dir() {
|
||||
roots.push(home.join(".sdkman/candidates/java"));
|
||||
roots.push(home.join(".jdks"));
|
||||
roots.push(home.join(".asdf/installs/java"));
|
||||
roots.push(home.join(".local/share/mise/installs/java"));
|
||||
}
|
||||
}
|
||||
roots
|
||||
}
|
||||
|
||||
fn collect_java_executables(directory: &Path, depth: usize, candidates: &mut Vec<PathBuf>) {
|
||||
if depth == 0 || !directory.is_dir() {
|
||||
return;
|
||||
}
|
||||
add_java_home(directory, candidates);
|
||||
if let Ok(entries) = std::fs::read_dir(directory) {
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
collect_java_executables(&path, depth - 1, candidates);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn add_java_home(home: &Path, candidates: &mut Vec<PathBuf>) {
|
||||
let executable = if cfg!(target_os = "windows") {
|
||||
"java.exe"
|
||||
} else {
|
||||
"java"
|
||||
};
|
||||
for path in [
|
||||
home.join("bin").join(executable),
|
||||
home.join("Contents/Home/bin").join(executable),
|
||||
] {
|
||||
if path.is_file() {
|
||||
candidates.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn java_version(path: &Path) -> Option<String> {
|
||||
let output = Command::new(path).arg("-version").output().ok()?;
|
||||
if !output.status.success() {
|
||||
return None;
|
||||
}
|
||||
let text = format!(
|
||||
"{}{}",
|
||||
String::from_utf8_lossy(&output.stderr),
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
);
|
||||
parse_java_version(&text)
|
||||
}
|
||||
|
||||
fn parse_java_version(output: &str) -> Option<String> {
|
||||
output.lines().find_map(|line| {
|
||||
line.split_once('"')
|
||||
.and_then(|(_, rest)| rest.split_once('"'))
|
||||
.map(|(version, _)| version.to_owned())
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn java_major(version: Option<&str>) -> u32 {
|
||||
let Some(version) = version else {
|
||||
return 0;
|
||||
};
|
||||
let parts = version
|
||||
.split(|character: char| !character.is_ascii_digit())
|
||||
.filter(|part| !part.is_empty())
|
||||
.filter_map(|part| part.parse::<u32>().ok())
|
||||
.collect::<Vec<_>>();
|
||||
match parts.as_slice() {
|
||||
[1, legacy_major, ..] => *legacy_major,
|
||||
[major, ..] => *major,
|
||||
[] => 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn parse_java_major_version(output: &str) -> Option<u32> {
|
||||
if let Some(version) = parse_java_version(output) {
|
||||
return Some(java_major(Some(&version))).filter(|major| *major > 0);
|
||||
}
|
||||
|
||||
let start = output.find(|character: char| character.is_ascii_digit())?;
|
||||
let parts = output[start..]
|
||||
.split(|character: char| !character.is_ascii_digit())
|
||||
.filter(|part| !part.is_empty())
|
||||
.filter_map(|part| part.parse::<u32>().ok())
|
||||
.collect::<Vec<_>>();
|
||||
match parts.as_slice() {
|
||||
[1, legacy_major, ..] => Some(*legacy_major),
|
||||
[major, ..] => Some(*major),
|
||||
[] => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn parses_modern_and_legacy_java_versions() {
|
||||
assert_eq!(
|
||||
parse_java_version("openjdk version \"21.0.4\" 2024-07-16"),
|
||||
Some("21.0.4".to_owned())
|
||||
);
|
||||
assert_eq!(
|
||||
parse_java_version("java version \"1.8.0_412\""),
|
||||
Some("1.8.0_412".to_owned())
|
||||
);
|
||||
assert_eq!(java_major(Some("21.0.4")), 21);
|
||||
assert_eq!(java_major(Some("1.8.0_412")), 8);
|
||||
assert_eq!(java_major(Some("21-ea")), 21);
|
||||
assert_eq!(
|
||||
parse_java_major_version("openjdk version \"21-ea\" 2026-03-17"),
|
||||
Some(21)
|
||||
);
|
||||
assert_eq!(parse_java_major_version("openjdk 17"), Some(17));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn installation_cache_round_trips_existing_paths() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let executable = temp.path().join("java");
|
||||
std::fs::write(&executable, b"java").unwrap();
|
||||
let cache = temp.path().join("cache/java/installations.json");
|
||||
let installations = vec![JavaInstallation {
|
||||
path: executable.clone(),
|
||||
version: Some("25.0.1".to_owned()),
|
||||
}];
|
||||
|
||||
save_installation_cache(&cache, &installations).unwrap();
|
||||
assert_eq!(load_installation_cache(&cache), Some(installations));
|
||||
|
||||
std::fs::remove_file(executable).unwrap();
|
||||
assert_eq!(load_installation_cache(&cache), None);
|
||||
}
|
||||
}
|
||||
+229
-51
@@ -13,7 +13,7 @@ use std::path::{Path, PathBuf};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::auth::AccountType;
|
||||
use crate::instance::models::{InstanceConfig, ModLoader};
|
||||
use crate::instance::models::{InstanceConfig, LaunchCommand, ModLoader, WindowMode};
|
||||
use crate::launch_profile::model::{Argument, LaunchProfile};
|
||||
use crate::launch_profile::rules::{self, FeatureSet, RuleAction, RuleContext};
|
||||
use crate::launch_profile::templates::TemplateContext;
|
||||
@@ -45,6 +45,8 @@ pub enum LaunchError {
|
||||
},
|
||||
#[error("{0}")]
|
||||
Auth(String),
|
||||
#[error("{phase} command failed: {reason}")]
|
||||
Command { phase: &'static str, reason: String },
|
||||
#[error("Config sync error: {0}")]
|
||||
ConfigSync(#[from] crate::instance::config_sync::ConfigSyncError),
|
||||
}
|
||||
@@ -59,26 +61,23 @@ fn build_game_args(
|
||||
Ok((rendered.jvm, rendered.game))
|
||||
}
|
||||
|
||||
fn parse_java_major_version(text: &str) -> Option<u32> {
|
||||
let quoted = text
|
||||
.split_once('"')
|
||||
.and_then(|(_, rest)| rest.split_once('"').map(|(version, _)| version));
|
||||
fn apply_custom_resolution(game_args: &mut Vec<String>, resolution: Option<(u32, u32)>) {
|
||||
let Some((width, height)) = resolution else {
|
||||
return;
|
||||
};
|
||||
if !game_args.iter().any(|arg| arg == "--width") {
|
||||
game_args.extend(["--width".to_owned(), width.to_string()]);
|
||||
}
|
||||
if !game_args.iter().any(|arg| arg == "--height") {
|
||||
game_args.extend(["--height".to_owned(), height.to_string()]);
|
||||
}
|
||||
}
|
||||
|
||||
let token = quoted.or_else(|| {
|
||||
let start = text.find(|c: char| c.is_ascii_digit())?;
|
||||
Some(&text[start..])
|
||||
})?;
|
||||
|
||||
let parts: Vec<u32> = token
|
||||
.split(|c: char| !c.is_ascii_digit())
|
||||
.filter(|part| !part.is_empty())
|
||||
.filter_map(|part| part.parse::<u32>().ok())
|
||||
.collect();
|
||||
|
||||
match parts.as_slice() {
|
||||
[1, legacy_major, ..] => Some(*legacy_major),
|
||||
[major, ..] => Some(*major),
|
||||
[] => None,
|
||||
fn apply_window_mode(game_args: &mut Vec<String>, window_mode: WindowMode) {
|
||||
if window_mode == WindowMode::Windowed {
|
||||
game_args.retain(|argument| argument != "--fullscreen");
|
||||
} else if !game_args.iter().any(|arg| arg == "--fullscreen") {
|
||||
game_args.push("--fullscreen".to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,16 +86,29 @@ async fn check_java_version(java: &str, required: Option<u32>) -> Result<(), Lau
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let output = tokio::process::Command::new(java)
|
||||
.arg("-version")
|
||||
.output()
|
||||
let mut command = tokio::process::Command::new(java);
|
||||
command.arg("-version").kill_on_drop(true);
|
||||
let output = tokio::time::timeout(std::time::Duration::from_secs(10), command.output())
|
||||
.await
|
||||
.map_err(|_| LaunchError::JavaCheckFailed {
|
||||
java: java.to_owned(),
|
||||
required,
|
||||
reason: "version check timed out".to_owned(),
|
||||
})?
|
||||
.map_err(|e| LaunchError::JavaCheckFailed {
|
||||
java: java.to_owned(),
|
||||
required,
|
||||
reason: e.to_string(),
|
||||
})?;
|
||||
|
||||
if !output.status.success() {
|
||||
return Err(LaunchError::JavaCheckFailed {
|
||||
java: java.to_owned(),
|
||||
required,
|
||||
reason: format!("`java -version` exited with {}", output.status),
|
||||
});
|
||||
}
|
||||
|
||||
let version_text = format!(
|
||||
"{}{}",
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
@@ -104,10 +116,12 @@ async fn check_java_version(java: &str, required: Option<u32>) -> Result<(), Lau
|
||||
);
|
||||
|
||||
let detected =
|
||||
parse_java_major_version(&version_text).ok_or_else(|| LaunchError::JavaCheckFailed {
|
||||
java: java.to_owned(),
|
||||
required,
|
||||
reason: format!("could not parse `java -version` output: {version_text:?}"),
|
||||
crate::instance::java::parse_java_major_version(&version_text).ok_or_else(|| {
|
||||
LaunchError::JavaCheckFailed {
|
||||
java: java.to_owned(),
|
||||
required,
|
||||
reason: format!("could not parse `java -version` output: {version_text:?}"),
|
||||
}
|
||||
})?;
|
||||
|
||||
if detected < required {
|
||||
@@ -171,10 +185,15 @@ async fn migrate_legacy_meta_if_needed(
|
||||
}
|
||||
};
|
||||
|
||||
tokio::fs::write(meta_path, &raw).await?;
|
||||
|
||||
let refreshed: LaunchProfile = serde_json::from_slice(&raw)
|
||||
.map_err(|e| LaunchError::Parse(format!("Failed to parse refreshed meta: {e}")))?;
|
||||
if refreshed.arguments.is_none() && refreshed.minecraft_arguments.is_none() {
|
||||
tracing::warn!(
|
||||
"Refetched metadata for {game_version} still has no launch arguments; keeping the cached profile"
|
||||
);
|
||||
return Ok(None);
|
||||
}
|
||||
crate::storage::write_atomic(meta_path, &raw)?;
|
||||
Ok(Some(refreshed))
|
||||
}
|
||||
|
||||
@@ -274,11 +293,10 @@ async fn migrate_legacy_loader_profile_if_needed(
|
||||
);
|
||||
|
||||
let raw = tokio::fs::read(&installer_json_path).await?;
|
||||
tokio::fs::write(profile_path, &raw).await?;
|
||||
|
||||
let refreshed: LaunchProfile = serde_json::from_slice(&raw).map_err(|e| {
|
||||
LaunchError::Parse(format!("Failed to parse refreshed loader profile: {e}"))
|
||||
})?;
|
||||
crate::storage::write_atomic(profile_path, &raw)?;
|
||||
Ok(Some(refreshed))
|
||||
}
|
||||
|
||||
@@ -306,6 +324,7 @@ pub struct LaunchInvocation {
|
||||
pub main_class: String,
|
||||
pub extra_args: Vec<String>,
|
||||
pub game_args: Vec<String>,
|
||||
pub environment: std::collections::BTreeMap<String, String>,
|
||||
pub working_dir: PathBuf,
|
||||
}
|
||||
|
||||
@@ -363,6 +382,13 @@ pub async fn build_launch_invocation(
|
||||
) -> Result<LaunchInvocation, LaunchError> {
|
||||
let instance_dir = instances_dir.join(&config.name);
|
||||
let minecraft_dir = instance_dir.join(crate::storage::MINECRAFT_DIR_NAME);
|
||||
let (window_mode, resolution) = {
|
||||
let defaults = &crate::config::SETTINGS.read().defaults;
|
||||
(
|
||||
config.effective_window_mode(defaults.window_mode),
|
||||
config.effective_resolution(defaults.resolution),
|
||||
)
|
||||
};
|
||||
|
||||
let metadata_paths = crate::storage::MetadataPaths::new(meta_dir);
|
||||
let meta_path = metadata_paths
|
||||
@@ -384,6 +410,7 @@ pub async fn build_launch_invocation(
|
||||
|
||||
let current_features = FeatureSet {
|
||||
is_quick_play_singleplayer: quick_play_world.map(|_| true),
|
||||
has_custom_resolution: resolution.map(|_| true),
|
||||
..Default::default()
|
||||
};
|
||||
let host_os_version = system::mojang_os_version();
|
||||
@@ -403,13 +430,8 @@ pub async fn build_launch_invocation(
|
||||
let lib_dir = metadata_paths.libraries();
|
||||
|
||||
let lv = config.loader_version.as_deref().unwrap_or("unknown");
|
||||
let profile_filename = match config.loader {
|
||||
ModLoader::Vanilla => None,
|
||||
ModLoader::Fabric => Some(format!("fabric-{}-{}.json", config.game_version, lv)),
|
||||
ModLoader::Quilt => Some(format!("quilt-{}-{}.json", config.game_version, lv)),
|
||||
ModLoader::Forge => Some(format!("forge-{}-{}.json", config.game_version, lv)),
|
||||
ModLoader::NeoForge => Some(format!("neoforge-{}.json", lv)),
|
||||
};
|
||||
let profile_filename =
|
||||
crate::instance::loader::profile_filename(config.loader, &config.game_version, lv);
|
||||
|
||||
// load the loader profile (if any), migrate from the old stripped format
|
||||
// if needed, and resolve `inheritsFrom` against the vanilla parent (which
|
||||
@@ -539,6 +561,7 @@ pub async fn build_launch_invocation(
|
||||
.clone()
|
||||
.or_else(|| {
|
||||
crate::config::SETTINGS
|
||||
.read()
|
||||
.paths
|
||||
.effective_java_path()
|
||||
.map(str::to_owned)
|
||||
@@ -560,6 +583,8 @@ pub async fn build_launch_invocation(
|
||||
.join(&config.game_version)
|
||||
.join("natives");
|
||||
let version_type = merged_profile.type_.as_deref().unwrap_or("release");
|
||||
let resolution_width = resolution.map(|(width, _)| width.to_string());
|
||||
let resolution_height = resolution.map(|(_, height)| height.to_string());
|
||||
let template_ctx = TemplateContext {
|
||||
library_directory,
|
||||
classpath_separator: sep,
|
||||
@@ -580,18 +605,43 @@ pub async fn build_launch_invocation(
|
||||
launcher_version: env!("CARGO_PKG_VERSION"),
|
||||
clientid: "0",
|
||||
quick_play_singleplayer: quick_play_world,
|
||||
resolution_width: resolution_width.as_deref(),
|
||||
resolution_height: resolution_height.as_deref(),
|
||||
};
|
||||
|
||||
let (upstream_jvm_args, game_args) =
|
||||
let (upstream_jvm_args, mut game_args) =
|
||||
build_game_args(&merged_profile, &rule_ctx, &template_ctx)?;
|
||||
// Modern Mojang profiles include feature-gated resolution arguments.
|
||||
// Older and third-party profiles may not, so add them when absent.
|
||||
apply_custom_resolution(&mut game_args, resolution);
|
||||
apply_window_mode(&mut game_args, window_mode);
|
||||
|
||||
let mut jvm_args: Vec<String> = vec![
|
||||
format!("-Xms{}", config.memory_min.as_deref().unwrap_or("512M")),
|
||||
format!("-Xmx{}", config.memory_max.as_deref().unwrap_or("2G")),
|
||||
];
|
||||
let (memory_min, memory_max, global_jvm_args, global_environment) = {
|
||||
let settings = crate::config::SETTINGS.read();
|
||||
(
|
||||
config
|
||||
.memory_min
|
||||
.clone()
|
||||
.unwrap_or_else(|| settings.defaults.memory_min.clone()),
|
||||
config
|
||||
.memory_max
|
||||
.clone()
|
||||
.unwrap_or_else(|| settings.defaults.memory_max.clone()),
|
||||
settings.defaults.jvm_args.clone(),
|
||||
settings.defaults.environment.clone(),
|
||||
)
|
||||
};
|
||||
let mut jvm_args: Vec<String> = vec![format!("-Xms{memory_min}"), format!("-Xmx{memory_max}")];
|
||||
jvm_args.extend(patch_jvm_args);
|
||||
jvm_args.extend(upstream_jvm_args);
|
||||
jvm_args.extend(global_jvm_args);
|
||||
jvm_args.extend(config.jvm_args.clone());
|
||||
if let Some(glfw_path) = config.glfw_path.as_deref() {
|
||||
jvm_args.push(format!("-Dorg.lwjgl.glfw.libname={glfw_path}"));
|
||||
}
|
||||
|
||||
let mut environment = global_environment;
|
||||
environment.extend(config.environment.clone());
|
||||
|
||||
Ok(LaunchInvocation {
|
||||
java,
|
||||
@@ -601,10 +651,94 @@ pub async fn build_launch_invocation(
|
||||
main_class,
|
||||
extra_args,
|
||||
game_args,
|
||||
environment,
|
||||
working_dir: minecraft_dir,
|
||||
})
|
||||
}
|
||||
|
||||
fn command_process(command: &str) -> tokio::process::Command {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let mut process = tokio::process::Command::new("cmd");
|
||||
process.args(["/C", command]);
|
||||
process
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
let mut process = tokio::process::Command::new("/bin/sh");
|
||||
process.args(["-c", command]);
|
||||
process
|
||||
}
|
||||
}
|
||||
|
||||
fn select_launch_account<'a>(
|
||||
accounts: &'a [crate::auth::Account],
|
||||
preferred: Option<&str>,
|
||||
) -> Option<&'a crate::auth::Account> {
|
||||
preferred
|
||||
.and_then(|uuid| accounts.iter().find(|account| account.uuid == uuid))
|
||||
.or_else(|| accounts.iter().find(|account| account.active))
|
||||
}
|
||||
|
||||
async fn run_launch_command(
|
||||
phase: &'static str,
|
||||
command: &LaunchCommand,
|
||||
config: &InstanceConfig,
|
||||
invocation: &LaunchInvocation,
|
||||
instance_dir: &Path,
|
||||
) -> Result<(), LaunchError> {
|
||||
if !command.enabled || command.command.trim().is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
tracing::info!("[{}] Running {} command", config.name, phase.to_lowercase());
|
||||
let mut process = command_process(&command.command);
|
||||
process
|
||||
.current_dir(&invocation.working_dir)
|
||||
.envs(&invocation.environment)
|
||||
.env("INST_NAME", &config.name)
|
||||
.env("INST_ID", &config.name)
|
||||
.env("INST_DIR", instance_dir)
|
||||
.env("INST_MC_DIR", &invocation.working_dir)
|
||||
.env("INST_JAVA", &invocation.java)
|
||||
.env("INST_JAVA_ARGS", invocation.jvm_args.join(" "));
|
||||
let output = process
|
||||
.output()
|
||||
.await
|
||||
.map_err(|error| LaunchError::Command {
|
||||
phase,
|
||||
reason: error.to_string(),
|
||||
})?;
|
||||
for line in String::from_utf8_lossy(&output.stdout).lines() {
|
||||
tracing::info!("[{}] [{}] {}", config.name, phase, line);
|
||||
}
|
||||
for line in String::from_utf8_lossy(&output.stderr).lines() {
|
||||
tracing::warn!("[{}] [{}] {}", config.name, phase, line);
|
||||
}
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(LaunchError::Command {
|
||||
phase,
|
||||
reason: output.status.to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn finish_config_sync(
|
||||
active: bool,
|
||||
profile: Option<&str>,
|
||||
meta_dir: &Path,
|
||||
minecraft_dir: &Path,
|
||||
instance: &str,
|
||||
) {
|
||||
if active
|
||||
&& let Err(error) = crate::instance::config_sync::finish(profile, meta_dir, minecraft_dir)
|
||||
{
|
||||
tracing::warn!("Failed to sync config for '{}': {}", instance, error);
|
||||
}
|
||||
}
|
||||
|
||||
// resolves auth credentials, then builds the launch invocation and spawns
|
||||
// the java process. only thin wrapper logic lives here: token refresh,
|
||||
// process spawn, child supervision. all the heavy lifting (profile loading,
|
||||
@@ -619,7 +753,9 @@ pub async fn launch(
|
||||
|
||||
// resolve auth credentials, refreshing the microsoft token if needed.
|
||||
let mut account_store = crate::auth::AccountStore::load();
|
||||
let Some(acc) = account_store.active_account().cloned() else {
|
||||
let account =
|
||||
select_launch_account(&account_store.accounts, config.preferred_account.as_deref());
|
||||
let Some(acc) = account.cloned() else {
|
||||
return Err(LaunchError::Auth("No account selected".to_owned()));
|
||||
};
|
||||
|
||||
@@ -673,6 +809,7 @@ pub async fn launch(
|
||||
|
||||
let invocation =
|
||||
build_launch_invocation(config, instances_dir, meta_dir, &auth, quick_play_world).await?;
|
||||
let instance_dir = instances_dir.join(&config.name);
|
||||
tracing::debug!(
|
||||
"[{}] Prepared launch invocation: working_dir={} classpath_entries={} jvm_args={} extra_args={} game_args={} main_class={}",
|
||||
name,
|
||||
@@ -689,6 +826,24 @@ pub async fn launch(
|
||||
meta_dir,
|
||||
&invocation.working_dir,
|
||||
)?;
|
||||
if let Err(error) = run_launch_command(
|
||||
"Pre-launch",
|
||||
&config.pre_launch_command,
|
||||
config,
|
||||
&invocation,
|
||||
&instance_dir,
|
||||
)
|
||||
.await
|
||||
{
|
||||
finish_config_sync(
|
||||
config_sync_active,
|
||||
config_sync_profile.as_deref(),
|
||||
meta_dir,
|
||||
&invocation.working_dir,
|
||||
&name,
|
||||
);
|
||||
return Err(error);
|
||||
}
|
||||
|
||||
let (kill_tx, kill_rx) = tokio::sync::oneshot::channel::<()>();
|
||||
crate::instance::runtime::register_kill(&name, kill_tx);
|
||||
@@ -721,6 +876,7 @@ pub async fn launch(
|
||||
cmd.args(&invocation.extra_args);
|
||||
cmd.args(&invocation.game_args);
|
||||
cmd.current_dir(&invocation.working_dir);
|
||||
cmd.envs(&invocation.environment);
|
||||
cmd.stdout(std::process::Stdio::piped());
|
||||
cmd.stderr(std::process::Stdio::piped());
|
||||
|
||||
@@ -729,6 +885,13 @@ pub async fn launch(
|
||||
Err(e) => {
|
||||
crate::instance::runtime::cleanup_kill_sender(&name);
|
||||
crate::instance::runtime::remove(&name);
|
||||
finish_config_sync(
|
||||
config_sync_active,
|
||||
config_sync_profile.as_deref(),
|
||||
meta_dir,
|
||||
&invocation.working_dir,
|
||||
&name,
|
||||
);
|
||||
tracing::error!("[{}] Failed to spawn Minecraft process: {}", name, e);
|
||||
return Err(LaunchError::Io(e));
|
||||
}
|
||||
@@ -751,6 +914,10 @@ pub async fn launch(
|
||||
let instances_dir_owned = instances_dir.to_path_buf();
|
||||
let meta_dir_owned = meta_dir.to_path_buf();
|
||||
let minecraft_dir_owned = invocation.working_dir.clone();
|
||||
let instance_dir_owned = instances_dir.join(&config.name);
|
||||
let post_exit_command = config.post_exit_command.clone();
|
||||
let config_for_post_exit = config.clone();
|
||||
let invocation_for_post_exit = invocation.clone();
|
||||
|
||||
// spawn a background task to babysit the child process: capture stdout/stderr
|
||||
// into both the TUI log viewer and a timestamped log file on disk
|
||||
@@ -852,15 +1019,26 @@ pub async fn launch(
|
||||
let _ = parser_task.await;
|
||||
tracing::info!("[{}] Exited with code {:?}", name_for_task, code);
|
||||
|
||||
if config_sync_active
|
||||
&& let Err(e) = crate::instance::config_sync::finish(
|
||||
config_sync_profile.as_deref(),
|
||||
&meta_dir_owned,
|
||||
&minecraft_dir_owned,
|
||||
)
|
||||
if let Err(error) = run_launch_command(
|
||||
"Post-exit",
|
||||
&post_exit_command,
|
||||
&config_for_post_exit,
|
||||
&invocation_for_post_exit,
|
||||
&instance_dir_owned,
|
||||
)
|
||||
.await
|
||||
{
|
||||
tracing::warn!("Failed to sync config for '{}': {}", name_for_task, e);
|
||||
tracing::warn!("[{}] {}", name_for_task, error);
|
||||
crate::feedback::errors::push_message(tracing::Level::WARN, error.to_string());
|
||||
}
|
||||
|
||||
finish_config_sync(
|
||||
config_sync_active,
|
||||
config_sync_profile.as_deref(),
|
||||
&meta_dir_owned,
|
||||
&minecraft_dir_owned,
|
||||
&name_for_task,
|
||||
);
|
||||
if code == Some(0) || killed_by_user {
|
||||
crate::instance::runtime::remove(&name_for_task);
|
||||
tracing::debug!(
|
||||
|
||||
@@ -48,6 +48,26 @@ impl ModLoaderInstaller for ForgeInstaller {
|
||||
loader_version: &str,
|
||||
instance_dir: &Path,
|
||||
meta_dir: &Path,
|
||||
) -> Result<(), InstallError> {
|
||||
self.install_with_java(
|
||||
client,
|
||||
game_version,
|
||||
loader_version,
|
||||
instance_dir,
|
||||
meta_dir,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn install_with_java(
|
||||
&self,
|
||||
client: &HttpClient,
|
||||
game_version: &str,
|
||||
loader_version: &str,
|
||||
instance_dir: &Path,
|
||||
meta_dir: &Path,
|
||||
java_path: Option<&str>,
|
||||
) -> Result<(), InstallError> {
|
||||
let installer_jar = instance_dir
|
||||
.join(crate::storage::MINECRAFT_DIR_NAME)
|
||||
@@ -76,11 +96,14 @@ impl ModLoaderInstaller for ForgeInstaller {
|
||||
}
|
||||
} else {
|
||||
// modern forge: run the java installer
|
||||
let java_path = crate::config::SETTINGS
|
||||
.paths
|
||||
.effective_java_path()
|
||||
.map(str::to_owned)
|
||||
.unwrap_or_else(crate::instance::java::detect_java_path);
|
||||
let java_path = java_path.map(str::to_owned).unwrap_or_else(|| {
|
||||
crate::config::SETTINGS
|
||||
.read()
|
||||
.paths
|
||||
.effective_java_path()
|
||||
.map(str::to_owned)
|
||||
.unwrap_or_else(crate::instance::java::detect_java_path)
|
||||
});
|
||||
tracing::debug!("Running Forge installer with Java {}", java_path);
|
||||
if let Err(e) = run_forge_installer(&installer_jar, instance_dir, &java_path).await {
|
||||
let _ = tokio::fs::remove_file(&installer_jar).await;
|
||||
|
||||
@@ -67,6 +67,20 @@ pub trait ModLoaderInstaller: Send + Sync {
|
||||
instance_dir: &Path,
|
||||
meta_dir: &Path,
|
||||
) -> Result<(), InstallError>;
|
||||
|
||||
async fn install_with_java(
|
||||
&self,
|
||||
client: &HttpClient,
|
||||
game_version: &str,
|
||||
loader_version: &str,
|
||||
instance_dir: &Path,
|
||||
meta_dir: &Path,
|
||||
java_path: Option<&str>,
|
||||
) -> Result<(), InstallError> {
|
||||
let _ = java_path;
|
||||
self.install(client, game_version, loader_version, instance_dir, meta_dir)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
// writes raw profile JSON bytes to meta_dir/loader-profiles/<filename>.
|
||||
@@ -80,7 +94,21 @@ pub(crate) fn save_profile_bytes(
|
||||
) -> std::io::Result<()> {
|
||||
let profiles_dir = crate::storage::MetadataPaths::new(meta_dir).loader_profiles();
|
||||
std::fs::create_dir_all(&profiles_dir)?;
|
||||
std::fs::write(profiles_dir.join(filename), bytes)
|
||||
crate::storage::write_atomic(&profiles_dir.join(filename), bytes)
|
||||
}
|
||||
|
||||
pub(crate) fn profile_filename(
|
||||
loader: ModLoader,
|
||||
game_version: &str,
|
||||
loader_version: &str,
|
||||
) -> Option<String> {
|
||||
match loader {
|
||||
ModLoader::Vanilla => None,
|
||||
ModLoader::Fabric => Some(format!("fabric-{game_version}-{loader_version}.json")),
|
||||
ModLoader::Quilt => Some(format!("quilt-{game_version}-{loader_version}.json")),
|
||||
ModLoader::Forge => Some(format!("forge-{game_version}-{loader_version}.json")),
|
||||
ModLoader::NeoForge => Some(format!("neoforge-{loader_version}.json")),
|
||||
}
|
||||
}
|
||||
|
||||
// used by forge/neoforge. their java installer drops a version json into
|
||||
@@ -118,11 +146,29 @@ pub(crate) fn save_installer_profile(
|
||||
ver_json_path.display()
|
||||
);
|
||||
let raw = std::fs::read(&ver_json_path)?;
|
||||
let profile: crate::launch_profile::model::LaunchProfile = serde_json::from_slice(&raw)
|
||||
.map_err(|error| {
|
||||
InstallerError::Profile(format!(
|
||||
"Invalid installer profile {}: {error}",
|
||||
ver_json_path.display()
|
||||
))
|
||||
})?;
|
||||
if profile.id.trim().is_empty()
|
||||
|| profile
|
||||
.main_class
|
||||
.as_deref()
|
||||
.is_none_or(|main_class| main_class.trim().is_empty())
|
||||
{
|
||||
return Err(InstallerError::Profile(format!(
|
||||
"Installer profile {} is missing id or mainClass",
|
||||
ver_json_path.display()
|
||||
)));
|
||||
}
|
||||
|
||||
let profiles_dir = crate::storage::MetadataPaths::new(meta_dir).loader_profiles();
|
||||
std::fs::create_dir_all(&profiles_dir)?;
|
||||
let profile_path = profiles_dir.join(profile_filename);
|
||||
std::fs::write(&profile_path, &raw)?;
|
||||
crate::storage::write_atomic(&profile_path, &raw)?;
|
||||
tracing::debug!(
|
||||
"Saved installer profile to {} ({} bytes)",
|
||||
profile_path.display(),
|
||||
|
||||
@@ -41,12 +41,32 @@ impl ModLoaderInstaller for NeoForgeInstaller {
|
||||
}
|
||||
|
||||
async fn install(
|
||||
&self,
|
||||
client: &HttpClient,
|
||||
game_version: &str,
|
||||
loader_version: &str,
|
||||
instance_dir: &Path,
|
||||
meta_dir: &Path,
|
||||
) -> Result<(), InstallError> {
|
||||
self.install_with_java(
|
||||
client,
|
||||
game_version,
|
||||
loader_version,
|
||||
instance_dir,
|
||||
meta_dir,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn install_with_java(
|
||||
&self,
|
||||
client: &HttpClient,
|
||||
_game_version: &str,
|
||||
loader_version: &str,
|
||||
instance_dir: &Path,
|
||||
meta_dir: &Path,
|
||||
java_path: Option<&str>,
|
||||
) -> Result<(), InstallError> {
|
||||
let installer_jar = instance_dir
|
||||
.join(crate::storage::MINECRAFT_DIR_NAME)
|
||||
@@ -56,11 +76,14 @@ impl ModLoaderInstaller for NeoForgeInstaller {
|
||||
|
||||
neoforge_api::download_neoforge_installer(client, loader_version, &installer_jar).await?;
|
||||
|
||||
let java_path = crate::config::SETTINGS
|
||||
.paths
|
||||
.effective_java_path()
|
||||
.map(str::to_owned)
|
||||
.unwrap_or_else(crate::instance::java::detect_java_path);
|
||||
let java_path = java_path.map(str::to_owned).unwrap_or_else(|| {
|
||||
crate::config::SETTINGS
|
||||
.read()
|
||||
.paths
|
||||
.effective_java_path()
|
||||
.map(str::to_owned)
|
||||
.unwrap_or_else(crate::instance::java::detect_java_path)
|
||||
});
|
||||
tracing::debug!("Running NeoForge installer with Java {}", java_path);
|
||||
if let Err(e) = run_neoforge_installer(&installer_jar, instance_dir, &java_path).await {
|
||||
let _ = tokio::fs::remove_file(&installer_jar).await;
|
||||
|
||||
+115
-74
@@ -206,24 +206,8 @@ impl InstanceManager {
|
||||
.versions()
|
||||
.join(game_version)
|
||||
.join("meta.json");
|
||||
if let Some(parent) = meta_json_path.parent()
|
||||
&& let Err(e) = std::fs::create_dir_all(parent)
|
||||
{
|
||||
tracing::warn!(
|
||||
"Failed to ensure meta dir {} exists: {}",
|
||||
parent.display(),
|
||||
e
|
||||
);
|
||||
}
|
||||
if let Err(e) = std::fs::write(&meta_json_path, &raw_meta_bytes) {
|
||||
tracing::warn!(
|
||||
"Failed to save version meta {}: {}",
|
||||
meta_json_path.display(),
|
||||
e
|
||||
);
|
||||
} else {
|
||||
tracing::debug!("Saved version meta to {}", meta_json_path.display());
|
||||
}
|
||||
crate::storage::write_atomic(&meta_json_path, &raw_meta_bytes)?;
|
||||
tracing::debug!("Saved version meta to {}", meta_json_path.display());
|
||||
|
||||
crate::net::mojang::download_libraries(&self.client, &version_meta, &self.meta_dir).await?;
|
||||
|
||||
@@ -262,6 +246,7 @@ impl InstanceManager {
|
||||
}
|
||||
})?;
|
||||
|
||||
let defaults = crate::config::SETTINGS.read().defaults.clone();
|
||||
let config = InstanceConfig {
|
||||
name: name.to_string(),
|
||||
game_version: game_version.to_string(),
|
||||
@@ -273,7 +258,15 @@ impl InstanceManager {
|
||||
memory_max: None,
|
||||
memory_min: None,
|
||||
jvm_args: vec![],
|
||||
resolution: None,
|
||||
environment: Default::default(),
|
||||
window_mode: defaults.window_mode,
|
||||
inherit_window_mode: true,
|
||||
resolution: defaults.resolution,
|
||||
inherit_resolution: true,
|
||||
preferred_account: None,
|
||||
pre_launch_command: Default::default(),
|
||||
post_exit_command: Default::default(),
|
||||
glfw_path: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
};
|
||||
@@ -306,15 +299,40 @@ impl InstanceManager {
|
||||
.versions()
|
||||
.join(&config.game_version)
|
||||
.join("meta.json");
|
||||
let (version_meta, raw_meta) = if meta_path.exists() {
|
||||
let raw = std::fs::read(&meta_path)?;
|
||||
let parsed = serde_json::from_slice(&raw).map_err(|error| {
|
||||
InstanceError::InvalidName(format!(
|
||||
"Cached metadata for Minecraft {} is invalid: {error}",
|
||||
config.game_version
|
||||
))
|
||||
})?;
|
||||
(parsed, raw)
|
||||
let cached_meta = match std::fs::read(&meta_path) {
|
||||
Ok(raw) => match serde_json::from_slice(&raw) {
|
||||
Ok(parsed)
|
||||
if serde_json::from_slice::<serde_json::Value>(&raw)
|
||||
.ok()
|
||||
.is_some_and(|value| {
|
||||
value.as_object().is_some_and(|object| {
|
||||
object.contains_key("arguments")
|
||||
|| object.contains_key("minecraftArguments")
|
||||
})
|
||||
}) =>
|
||||
{
|
||||
Some((parsed, raw))
|
||||
}
|
||||
Ok(_) => {
|
||||
tracing::warn!(
|
||||
"Cached metadata for Minecraft {} is incomplete; downloading it again",
|
||||
config.game_version
|
||||
);
|
||||
None
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::warn!(
|
||||
"Cached metadata for Minecraft {} is invalid; downloading it again: {error}",
|
||||
config.game_version
|
||||
);
|
||||
None
|
||||
}
|
||||
},
|
||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => None,
|
||||
Err(error) => return Err(error.into()),
|
||||
};
|
||||
let (version_meta, raw_meta, fetched_meta) = if let Some((parsed, raw)) = cached_meta {
|
||||
(parsed, raw, false)
|
||||
} else {
|
||||
let manifest = crate::net::mojang::fetch_version_manifest(&self.client).await?;
|
||||
let version_entry = manifest
|
||||
@@ -327,14 +345,17 @@ impl InstanceManager {
|
||||
config.game_version
|
||||
))
|
||||
})?;
|
||||
crate::net::mojang::fetch_version_meta_with_raw(&self.client, version_entry).await?
|
||||
let (parsed, raw) =
|
||||
crate::net::mojang::fetch_version_meta_with_raw(&self.client, version_entry)
|
||||
.await?;
|
||||
(parsed, raw, true)
|
||||
};
|
||||
crate::net::mojang::download_client_jar(&self.client, &version_meta, &self.meta_dir)
|
||||
.await?;
|
||||
if let Some(parent) = meta_path.parent() {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
}
|
||||
if !meta_path.exists() {
|
||||
if fetched_meta {
|
||||
crate::storage::write_atomic(&meta_path, &raw_meta)?;
|
||||
}
|
||||
crate::net::mojang::download_libraries(&self.client, &version_meta, &self.meta_dir).await?;
|
||||
@@ -347,34 +368,43 @@ impl InstanceManager {
|
||||
config.name, config.loader
|
||||
))
|
||||
})?;
|
||||
let profile_name = match config.loader {
|
||||
ModLoader::Fabric => {
|
||||
format!("fabric-{}-{loader_version}.json", config.game_version)
|
||||
}
|
||||
ModLoader::Quilt => {
|
||||
format!("quilt-{}-{loader_version}.json", config.game_version)
|
||||
}
|
||||
ModLoader::Forge => {
|
||||
format!("forge-{}-{loader_version}.json", config.game_version)
|
||||
}
|
||||
ModLoader::NeoForge => format!("neoforge-{loader_version}.json"),
|
||||
ModLoader::Vanilla => unreachable!(),
|
||||
};
|
||||
if !metadata_paths.loader_profiles().join(profile_name).exists() {
|
||||
task.set_sub_action(format!("{} {}", config.loader, loader_version));
|
||||
crate::instance::loader::get_installer(config.loader)
|
||||
.install(
|
||||
&self.client,
|
||||
&config.game_version,
|
||||
loader_version,
|
||||
&self.instances_dir.join(&config.name),
|
||||
&self.meta_dir,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| match error {
|
||||
InstallError::Download(error) => InstanceError::Download(error),
|
||||
InstallError::Installer(error) => InstanceError::InstallerError(error),
|
||||
})?;
|
||||
task.set_sub_action(format!("{} {}", config.loader, loader_version));
|
||||
crate::instance::loader::get_installer(config.loader)
|
||||
.install_with_java(
|
||||
&self.client,
|
||||
&config.game_version,
|
||||
loader_version,
|
||||
&self.instances_dir.join(&config.name),
|
||||
&self.meta_dir,
|
||||
config.java_path.as_deref(),
|
||||
)
|
||||
.await
|
||||
.map_err(|error| match error {
|
||||
InstallError::Download(error) => InstanceError::Download(error),
|
||||
InstallError::Installer(error) => InstanceError::InstallerError(error),
|
||||
})?;
|
||||
let profile_filename = crate::instance::loader::profile_filename(
|
||||
config.loader,
|
||||
&config.game_version,
|
||||
loader_version,
|
||||
)
|
||||
.expect("non-vanilla loaders have profile filenames");
|
||||
let profile_path = metadata_paths.loader_profiles().join(profile_filename);
|
||||
let profile: crate::launch_profile::model::LaunchProfile =
|
||||
serde_json::from_slice(&std::fs::read(&profile_path)?)?;
|
||||
if profile.id.trim().is_empty()
|
||||
|| profile
|
||||
.main_class
|
||||
.as_deref()
|
||||
.is_none_or(|main_class| main_class.trim().is_empty())
|
||||
{
|
||||
return Err(InstanceError::InstallerError(InstallerError::Profile(
|
||||
format!(
|
||||
"Installed {} profile {} is missing id or mainClass",
|
||||
config.loader,
|
||||
profile_path.display()
|
||||
),
|
||||
)));
|
||||
}
|
||||
}
|
||||
task.finish();
|
||||
@@ -382,6 +412,7 @@ impl InstanceManager {
|
||||
}
|
||||
|
||||
pub fn delete(&self, name: &str) -> Result<(), InstanceError> {
|
||||
validate_name(name)?;
|
||||
let instance_dir = self.instances_dir.join(name);
|
||||
if !instance_dir.exists() {
|
||||
tracing::warn!(
|
||||
@@ -407,6 +438,7 @@ impl InstanceManager {
|
||||
}
|
||||
|
||||
pub fn rename(&self, old_name: &str, new_name: &str) -> Result<(), InstanceError> {
|
||||
validate_name(old_name)?;
|
||||
let new_name = new_name.trim();
|
||||
if new_name.is_empty() {
|
||||
tracing::warn!("Cannot rename instance '{}': new name is empty", old_name);
|
||||
@@ -441,6 +473,9 @@ impl InstanceManager {
|
||||
);
|
||||
return Err(InstanceError::AlreadyExists(new_name.to_string()));
|
||||
}
|
||||
let mut config = self.load_one(old_name)?;
|
||||
config.name = new_name.to_owned();
|
||||
let json = serde_json::to_vec_pretty(&config)?;
|
||||
tracing::info!("Renaming instance '{}' to '{}'", old_name, new_name);
|
||||
if let Err(e) = std::fs::rename(&old_dir, &new_dir) {
|
||||
tracing::error!(
|
||||
@@ -453,21 +488,19 @@ impl InstanceManager {
|
||||
}
|
||||
|
||||
let config_path = new_dir.join("instance.json");
|
||||
if let Ok(data) = std::fs::read_to_string(&config_path)
|
||||
&& let Ok(mut config) = serde_json::from_str::<InstanceConfig>(&data)
|
||||
{
|
||||
config.name = new_name.to_string();
|
||||
if let Ok(json) = serde_json::to_string_pretty(&config) {
|
||||
let _ = std::fs::write(&config_path, json);
|
||||
if let Err(error) = crate::storage::write_atomic(&config_path, &json) {
|
||||
if let Err(rollback_error) = std::fs::rename(&new_dir, &old_dir) {
|
||||
tracing::error!(
|
||||
"Failed to roll back instance rename from {} to {}: {}",
|
||||
new_dir.display(),
|
||||
old_dir.display(),
|
||||
rollback_error
|
||||
);
|
||||
}
|
||||
if let Err(e) = crate::instance::desktop::rename(old_name, &config) {
|
||||
tracing::warn!("Failed to rename desktop shortcut: {}", e);
|
||||
}
|
||||
} else {
|
||||
tracing::warn!(
|
||||
"Renamed instance directory but could not update config at {}",
|
||||
config_path.display()
|
||||
);
|
||||
return Err(error.into());
|
||||
}
|
||||
if let Err(e) = crate::instance::desktop::rename(old_name, &config) {
|
||||
tracing::warn!("Failed to rename desktop shortcut: {}", e);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -559,10 +592,14 @@ impl InstanceManager {
|
||||
}
|
||||
|
||||
pub fn save(&self, instance: &InstanceConfig) -> Result<(), InstanceError> {
|
||||
validate_name(&instance.name)?;
|
||||
let instance_dir = self.instances_dir.join(&instance.name);
|
||||
if !instance_dir.is_dir() {
|
||||
return Err(InstanceError::NotFound(instance.name.clone()));
|
||||
}
|
||||
let config_path = instance_dir.join("instance.json");
|
||||
let json = serde_json::to_string_pretty(instance)?;
|
||||
std::fs::write(&config_path, &json)?;
|
||||
crate::storage::write_atomic(&config_path, json.as_bytes())?;
|
||||
tracing::debug!(
|
||||
"Saved instance '{}' config to {}",
|
||||
instance.name,
|
||||
@@ -587,7 +624,11 @@ fn validate_name(name: &str) -> Result<(), InstanceError> {
|
||||
name
|
||||
)));
|
||||
}
|
||||
if name.contains('/') || name.contains('\\') || name.starts_with('.') {
|
||||
if name.contains('/')
|
||||
|| name.contains('\\')
|
||||
|| name.starts_with('.')
|
||||
|| name.chars().any(char::is_control)
|
||||
{
|
||||
return Err(InstanceError::InvalidName(format!(
|
||||
"Name contains invalid characters: {:?}",
|
||||
name
|
||||
|
||||
+1
-1
@@ -27,4 +27,4 @@ pub use content::{
|
||||
pub use launch::LaunchError;
|
||||
pub use loader::{GameVersion, ModLoaderInstaller, VanillaInstaller, get_installer};
|
||||
pub use manager::{InstanceError, InstanceManager};
|
||||
pub use models::{InstanceConfig, ModLoader, normalize_memory_value};
|
||||
pub use models::{InstanceConfig, ModLoader, WindowMode, normalize_memory_value};
|
||||
+135
-3
@@ -7,7 +7,7 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use std::fmt;
|
||||
use std::{collections::BTreeMap, fmt};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
@@ -31,6 +31,43 @@ impl fmt::Display for ModLoader {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum WindowMode {
|
||||
#[default]
|
||||
Windowed,
|
||||
Fullscreen,
|
||||
}
|
||||
|
||||
impl WindowMode {
|
||||
fn is_windowed(&self) -> bool {
|
||||
*self == Self::Windowed
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for WindowMode {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Windowed => write!(f, "windowed"),
|
||||
Self::Fullscreen => write!(f, "fullscreen"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct LaunchCommand {
|
||||
#[serde(default)]
|
||||
pub enabled: bool,
|
||||
#[serde(default)]
|
||||
pub command: String,
|
||||
}
|
||||
|
||||
impl LaunchCommand {
|
||||
fn is_default(&self) -> bool {
|
||||
!self.enabled && self.command.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct InstanceConfig {
|
||||
pub name: String,
|
||||
@@ -40,7 +77,7 @@ pub struct InstanceConfig {
|
||||
pub created: DateTime<Utc>,
|
||||
#[serde(default)]
|
||||
pub last_played: Option<DateTime<Utc>>,
|
||||
#[serde(default)]
|
||||
#[serde(default, deserialize_with = "deserialize_optional_non_empty_string")]
|
||||
pub java_path: Option<String>,
|
||||
#[serde(default, deserialize_with = "deserialize_optional_memory")]
|
||||
pub memory_max: Option<String>,
|
||||
@@ -48,14 +85,97 @@ pub struct InstanceConfig {
|
||||
pub memory_min: Option<String>,
|
||||
#[serde(default)]
|
||||
pub jvm_args: Vec<String>,
|
||||
#[serde(default)]
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub environment: BTreeMap<String, String>,
|
||||
#[serde(default, skip_serializing_if = "WindowMode::is_windowed")]
|
||||
pub window_mode: WindowMode,
|
||||
#[serde(default, skip_serializing_if = "is_false")]
|
||||
pub inherit_window_mode: bool,
|
||||
#[serde(default, deserialize_with = "deserialize_optional_resolution")]
|
||||
pub resolution: Option<(u32, u32)>,
|
||||
#[serde(default, skip_serializing_if = "is_false")]
|
||||
pub inherit_resolution: bool,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "deserialize_optional_non_empty_string",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
pub preferred_account: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "LaunchCommand::is_default")]
|
||||
pub pre_launch_command: LaunchCommand,
|
||||
#[serde(default, skip_serializing_if = "LaunchCommand::is_default")]
|
||||
pub post_exit_command: LaunchCommand,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "deserialize_optional_non_empty_string",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
pub glfw_path: Option<String>,
|
||||
#[serde(default)]
|
||||
pub config_sync_profile: Option<String>,
|
||||
#[serde(default)]
|
||||
pub modpack_source: Option<crate::instance::ProviderProject>,
|
||||
}
|
||||
|
||||
impl InstanceConfig {
|
||||
pub fn effective_window_mode(&self, global: WindowMode) -> WindowMode {
|
||||
if self.inherit_window_mode {
|
||||
global
|
||||
} else {
|
||||
self.window_mode
|
||||
}
|
||||
}
|
||||
|
||||
pub fn effective_resolution(&self, global: Option<(u32, u32)>) -> Option<(u32, u32)> {
|
||||
if self.inherit_resolution {
|
||||
global
|
||||
} else {
|
||||
self.resolution
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn is_false(value: &bool) -> bool {
|
||||
!value
|
||||
}
|
||||
|
||||
fn deserialize_optional_resolution<'de, D>(deserializer: D) -> Result<Option<(u32, u32)>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
Ok(Option::<(u32, u32)>::deserialize(deserializer)?
|
||||
.filter(|(width, height)| *width > 0 && *height > 0))
|
||||
}
|
||||
|
||||
fn deserialize_optional_non_empty_string<'de, D>(
|
||||
deserializer: D,
|
||||
) -> Result<Option<String>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
Ok(Option::<String>::deserialize(deserializer)?
|
||||
.and_then(|value| (!value.trim().is_empty()).then(|| value.trim().to_owned())))
|
||||
}
|
||||
|
||||
pub fn parse_resolution(input: &str) -> Result<(u32, u32), String> {
|
||||
let (width, height) = input
|
||||
.trim()
|
||||
.split_once(['x', 'X'])
|
||||
.ok_or_else(|| "resolution must be in WxH format".to_string())?;
|
||||
let width = width
|
||||
.parse::<u32>()
|
||||
.map_err(|_| "resolution width must be a positive integer".to_string())?;
|
||||
let height = height
|
||||
.parse::<u32>()
|
||||
.map_err(|_| "resolution height must be a positive integer".to_string())?;
|
||||
|
||||
if width == 0 || height == 0 {
|
||||
return Err("resolution values must be greater than zero".to_string());
|
||||
}
|
||||
|
||||
Ok((width, height))
|
||||
}
|
||||
|
||||
pub fn normalize_memory_value(raw: &str) -> Option<String> {
|
||||
let trimmed = raw.trim();
|
||||
if trimmed.is_empty() {
|
||||
@@ -84,6 +204,18 @@ pub fn normalize_memory_value(raw: &str) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn memory_kib(value: &str) -> Option<u64> {
|
||||
let normalized = normalize_memory_value(value)?;
|
||||
let (number, suffix) = normalized.split_at(normalized.len().saturating_sub(1));
|
||||
let number = number.parse::<u64>().ok()?;
|
||||
match suffix {
|
||||
"K" => Some(number),
|
||||
"M" => number.checked_mul(1024),
|
||||
"G" => number.checked_mul(1024 * 1024),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn deserialize_optional_memory<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
|
||||
@@ -52,6 +52,14 @@ pub fn get(name: &str) -> Option<RunState> {
|
||||
RUNNING.lock().ok().and_then(|map| map.get(name).cloned())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_active(name: &str) -> bool {
|
||||
matches!(
|
||||
get(name),
|
||||
Some(RunState::Authenticating | RunState::Starting | RunState::Running)
|
||||
)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn all() -> Vec<(String, RunState)> {
|
||||
RUNNING
|
||||
|
||||
@@ -244,7 +244,15 @@ fn instance() -> InstanceConfig {
|
||||
memory_max: None,
|
||||
memory_min: None,
|
||||
jvm_args: Vec::new(),
|
||||
environment: Default::default(),
|
||||
window_mode: Default::default(),
|
||||
inherit_window_mode: false,
|
||||
resolution: None,
|
||||
inherit_resolution: false,
|
||||
preferred_account: None,
|
||||
pre_launch_command: Default::default(),
|
||||
post_exit_command: Default::default(),
|
||||
glfw_path: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
}
|
||||
|
||||
@@ -49,7 +49,15 @@ fn job(name: &str) -> ReconcileJob {
|
||||
memory_max: None,
|
||||
memory_min: None,
|
||||
jvm_args: Vec::new(),
|
||||
environment: Default::default(),
|
||||
window_mode: Default::default(),
|
||||
inherit_window_mode: false,
|
||||
resolution: None,
|
||||
inherit_resolution: false,
|
||||
preferred_account: None,
|
||||
pre_launch_command: Default::default(),
|
||||
post_exit_command: Default::default(),
|
||||
glfw_path: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
},
|
||||
|
||||
@@ -31,3 +31,16 @@ fn build_content_linux_with_icon() {
|
||||
let content = build_content("TestPack", Some(&icon));
|
||||
assert!(content.contains("Icon=/tmp/icon.png"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shortcut_arguments_escape_platform_metacharacters() {
|
||||
assert_eq!(
|
||||
quote_desktop_exec_arg("Pack \"$HOME`\\"),
|
||||
"\"Pack \\\"\\$HOME\\`\\\\\""
|
||||
);
|
||||
assert_eq!(quote_shell_arg("Pack 'quoted'"), "'Pack '\\''quoted'\\'''");
|
||||
assert_eq!(
|
||||
quote_windows_arg("Pack \\\"quoted"),
|
||||
"\"Pack \\\\\\\"quoted\""
|
||||
);
|
||||
}
|
||||
@@ -12,7 +12,10 @@ fn parse_java_major_version_handles_common_outputs(
|
||||
#[case] output: &str,
|
||||
#[case] expected: Option<u32>,
|
||||
) {
|
||||
assert_eq!(parse_java_major_version(output), expected);
|
||||
assert_eq!(
|
||||
crate::instance::java::parse_java_major_version(output),
|
||||
expected
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -57,6 +60,8 @@ fn build_game_args_renders_upstream_arguments() {
|
||||
launcher_version: "test",
|
||||
clientid: "0",
|
||||
quick_play_singleplayer: None,
|
||||
resolution_width: None,
|
||||
resolution_height: None,
|
||||
version_type: "release",
|
||||
};
|
||||
let features = FeatureSet::default();
|
||||
@@ -89,6 +94,145 @@ fn build_game_args_renders_upstream_arguments() {
|
||||
assert_eq!(game_args, vec!["--username", "Player"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_resolution_is_added_once() {
|
||||
let mut args = vec!["--username".to_owned(), "Player".to_owned()];
|
||||
apply_custom_resolution(&mut args, Some((1920, 1080)));
|
||||
assert_eq!(
|
||||
args,
|
||||
[
|
||||
"--username",
|
||||
"Player",
|
||||
"--width",
|
||||
"1920",
|
||||
"--height",
|
||||
"1080"
|
||||
]
|
||||
);
|
||||
|
||||
apply_custom_resolution(&mut args, Some((1280, 720)));
|
||||
assert_eq!(args.iter().filter(|arg| *arg == "--width").count(), 1);
|
||||
assert_eq!(args.iter().filter(|arg| *arg == "--height").count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fullscreen_is_added_once() {
|
||||
let mut args = vec!["--username".to_owned(), "Player".to_owned()];
|
||||
apply_window_mode(&mut args, WindowMode::Fullscreen);
|
||||
apply_window_mode(&mut args, WindowMode::Fullscreen);
|
||||
assert_eq!(
|
||||
args.iter()
|
||||
.filter(|argument| *argument == "--fullscreen")
|
||||
.count(),
|
||||
1
|
||||
);
|
||||
|
||||
let mut windowed = vec![
|
||||
"--username".to_owned(),
|
||||
"Player".to_owned(),
|
||||
"--fullscreen".to_owned(),
|
||||
];
|
||||
apply_window_mode(&mut windowed, WindowMode::Windowed);
|
||||
assert_eq!(windowed, ["--username", "Player"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preferred_account_falls_back_to_the_active_account() {
|
||||
let accounts = vec![
|
||||
crate::auth::Account {
|
||||
uuid: "active".to_owned(),
|
||||
username: "Active".to_owned(),
|
||||
account_type: AccountType::Microsoft,
|
||||
active: true,
|
||||
refresh_token: None,
|
||||
cached_mc_token: None,
|
||||
cached_mc_token_expires_at: None,
|
||||
},
|
||||
crate::auth::Account {
|
||||
uuid: "preferred".to_owned(),
|
||||
username: "Preferred".to_owned(),
|
||||
account_type: AccountType::Offline,
|
||||
active: false,
|
||||
refresh_token: None,
|
||||
cached_mc_token: None,
|
||||
cached_mc_token_expires_at: None,
|
||||
},
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
select_launch_account(&accounts, Some("preferred")).map(|account| account.uuid.as_str()),
|
||||
Some("preferred")
|
||||
);
|
||||
assert_eq!(
|
||||
select_launch_account(&accounts, Some("removed")).map(|account| account.uuid.as_str()),
|
||||
Some("active")
|
||||
);
|
||||
assert_eq!(
|
||||
select_launch_account(&accounts, None).map(|account| account.uuid.as_str()),
|
||||
Some("active")
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
async fn launch_commands_receive_instance_environment() {
|
||||
use chrono::Utc;
|
||||
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let minecraft = temp.path().join("minecraft");
|
||||
std::fs::create_dir_all(&minecraft).unwrap();
|
||||
let mut config = InstanceConfig {
|
||||
name: "Hook Test".to_owned(),
|
||||
game_version: "1.21.1".to_owned(),
|
||||
loader: ModLoader::Vanilla,
|
||||
loader_version: None,
|
||||
created: Utc::now(),
|
||||
last_played: None,
|
||||
java_path: None,
|
||||
memory_max: None,
|
||||
memory_min: None,
|
||||
jvm_args: Vec::new(),
|
||||
environment: Default::default(),
|
||||
window_mode: Default::default(),
|
||||
inherit_window_mode: false,
|
||||
resolution: None,
|
||||
inherit_resolution: false,
|
||||
preferred_account: None,
|
||||
pre_launch_command: Default::default(),
|
||||
post_exit_command: Default::default(),
|
||||
glfw_path: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
};
|
||||
config
|
||||
.environment
|
||||
.insert("CUSTOM_VALUE".to_owned(), "available".to_owned());
|
||||
let invocation = LaunchInvocation {
|
||||
java: "/usr/bin/java".to_owned(),
|
||||
jvm_args: vec!["-Xmx2G".to_owned()],
|
||||
classpath: Vec::new(),
|
||||
classpath_string: String::new(),
|
||||
main_class: String::new(),
|
||||
extra_args: Vec::new(),
|
||||
game_args: Vec::new(),
|
||||
environment: config.environment.clone(),
|
||||
working_dir: minecraft.clone(),
|
||||
};
|
||||
let command = LaunchCommand {
|
||||
enabled: true,
|
||||
command: "printf '%s|%s' \"$CUSTOM_VALUE\" \"$INST_NAME\" > hook-result".to_owned(),
|
||||
};
|
||||
|
||||
run_launch_command("Pre-launch", &command, &config, &invocation, temp.path())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(minecraft.join("hook-result")).unwrap(),
|
||||
"available|Hook Test"
|
||||
);
|
||||
}
|
||||
|
||||
// exercises the early-return branch of migrate_legacy_meta_if_needed.
|
||||
// a profile with either arguments or minecraftArguments is not legacy
|
||||
// and must produce Ok(None) without touching the network. covers both
|
||||
@@ -180,7 +324,15 @@ async fn migrate_legacy_loader_profile_skips_modern_with_inherits_from() {
|
||||
memory_max: None,
|
||||
memory_min: None,
|
||||
jvm_args: Vec::new(),
|
||||
environment: Default::default(),
|
||||
window_mode: Default::default(),
|
||||
inherit_window_mode: false,
|
||||
resolution: None,
|
||||
inherit_resolution: false,
|
||||
preferred_account: None,
|
||||
pre_launch_command: Default::default(),
|
||||
post_exit_command: Default::default(),
|
||||
glfw_path: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
};
|
||||
@@ -229,7 +381,15 @@ async fn migrate_legacy_loader_profile_skips_fabric() {
|
||||
memory_max: None,
|
||||
memory_min: None,
|
||||
jvm_args: Vec::new(),
|
||||
environment: Default::default(),
|
||||
window_mode: Default::default(),
|
||||
inherit_window_mode: false,
|
||||
resolution: None,
|
||||
inherit_resolution: false,
|
||||
preferred_account: None,
|
||||
pre_launch_command: Default::default(),
|
||||
post_exit_command: Default::default(),
|
||||
glfw_path: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
};
|
||||
|
||||
@@ -66,6 +66,51 @@ fn save_installer_profile_copies_raw_bytes_verbatim() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_installer_profile_rejects_invalid_json_without_overwriting_cache() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let instance_dir = tmp.path().join("instance");
|
||||
let meta_dir = tmp.path().join("meta");
|
||||
let version_name = "1.20.1-forge-broken";
|
||||
let version_dir = instance_dir
|
||||
.join(crate::storage::MINECRAFT_DIR_NAME)
|
||||
.join("versions")
|
||||
.join(version_name);
|
||||
std::fs::create_dir_all(&version_dir).unwrap();
|
||||
std::fs::write(
|
||||
version_dir.join(format!("{version_name}.json")),
|
||||
b"not json",
|
||||
)
|
||||
.unwrap();
|
||||
let cached = crate::storage::MetadataPaths::new(&meta_dir)
|
||||
.loader_profiles()
|
||||
.join("forge-broken.json");
|
||||
std::fs::create_dir_all(cached.parent().unwrap()).unwrap();
|
||||
std::fs::write(&cached, b"previous").unwrap();
|
||||
|
||||
assert!(
|
||||
save_installer_profile(&instance_dir, &meta_dir, version_name, "forge-broken.json")
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(std::fs::read(cached).unwrap(), b"previous");
|
||||
}
|
||||
|
||||
#[rstest::rstest]
|
||||
#[case(ModLoader::Vanilla, None)]
|
||||
#[case(ModLoader::Fabric, Some("fabric-1.21.1-1.0.json"))]
|
||||
#[case(ModLoader::Quilt, Some("quilt-1.21.1-1.0.json"))]
|
||||
#[case(ModLoader::Forge, Some("forge-1.21.1-1.0.json"))]
|
||||
#[case(ModLoader::NeoForge, Some("neoforge-1.0.json"))]
|
||||
fn profile_filenames_match_launch_cache_names(
|
||||
#[case] loader: ModLoader,
|
||||
#[case] expected: Option<&str>,
|
||||
) {
|
||||
assert_eq!(
|
||||
profile_filename(loader, "1.21.1", "1.0").as_deref(),
|
||||
expected
|
||||
);
|
||||
}
|
||||
|
||||
// shape-pinning test: a synthetic versionInfo from a 1.7.10 forge
|
||||
// install_profile.json must deserialise as a LaunchProfile so the
|
||||
// launch flow's render_args + resolve pipeline can consume it. no
|
||||
|
||||
@@ -27,7 +27,15 @@ fn dummy_config(name: &str) -> InstanceConfig {
|
||||
memory_max: None,
|
||||
memory_min: None,
|
||||
jvm_args: vec![],
|
||||
environment: Default::default(),
|
||||
window_mode: Default::default(),
|
||||
inherit_window_mode: false,
|
||||
resolution: None,
|
||||
inherit_resolution: false,
|
||||
preferred_account: None,
|
||||
pre_launch_command: Default::default(),
|
||||
post_exit_command: Default::default(),
|
||||
glfw_path: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
}
|
||||
@@ -44,6 +52,7 @@ fn validate_name_rejects_empty_traversal_and_hidden() {
|
||||
assert!(validate_name("").is_err());
|
||||
assert!(validate_name("path/traversal").is_err());
|
||||
assert!(validate_name(".hidden").is_err());
|
||||
assert!(validate_name("line\nbreak").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -53,6 +62,23 @@ fn delete_missing_instance_returns_not_found() {
|
||||
assert!(matches!(result, Err(InstanceError::NotFound(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_rejects_path_traversal() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let instances = tmp.path().join("instances");
|
||||
let meta = tmp.path().join("meta");
|
||||
std::fs::create_dir_all(&instances).unwrap();
|
||||
std::fs::create_dir_all(&meta).unwrap();
|
||||
let manager = InstanceManager::new(instances, meta);
|
||||
let outside = tmp.path().join("outside-instance");
|
||||
std::fs::create_dir_all(&outside).unwrap();
|
||||
|
||||
let result = manager.delete("../outside-instance");
|
||||
|
||||
assert!(matches!(result, Err(InstanceError::InvalidName(_))));
|
||||
assert!(outside.exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_then_load_all_round_trips_config() {
|
||||
let (manager, tmp) = test_manager();
|
||||
@@ -161,6 +187,20 @@ fn rename_target_exists_errors() {
|
||||
assert!(matches!(err, InstanceError::AlreadyExists(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_with_invalid_source_is_rejected() {
|
||||
let (manager, _tmp) = test_manager();
|
||||
let err = manager.rename("../outside", "safe-name").unwrap_err();
|
||||
assert!(matches!(err, InstanceError::InvalidName(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_rejects_invalid_instance_name() {
|
||||
let (manager, _tmp) = test_manager();
|
||||
let err = manager.save(&dummy_config("../outside")).unwrap_err();
|
||||
assert!(matches!(err, InstanceError::InvalidName(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn touch_last_played_updates_field() {
|
||||
let (manager, tmp) = test_manager();
|
||||
|
||||
@@ -16,7 +16,15 @@ fn instance_config_roundtrips_through_json() {
|
||||
memory_max: Some("4G".to_string()),
|
||||
memory_min: Some("512M".to_string()),
|
||||
jvm_args: vec![],
|
||||
environment: Default::default(),
|
||||
window_mode: Default::default(),
|
||||
inherit_window_mode: false,
|
||||
resolution: Some((1920, 1080)),
|
||||
inherit_resolution: false,
|
||||
preferred_account: None,
|
||||
pre_launch_command: Default::default(),
|
||||
post_exit_command: Default::default(),
|
||||
glfw_path: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: Some(crate::instance::ProviderProject {
|
||||
provider: "modrinth".to_owned(),
|
||||
@@ -47,6 +55,57 @@ fn instance_config_accepts_numeric_memory() {
|
||||
let parsed: InstanceConfig = serde_json::from_str(json).expect("deserialize");
|
||||
assert_eq!(parsed.memory_max.as_deref(), Some("8G"));
|
||||
assert_eq!(parsed.memory_min.as_deref(), Some("512M"));
|
||||
assert!(parsed.environment.is_empty());
|
||||
assert_eq!(parsed.window_mode, WindowMode::Windowed);
|
||||
assert!(!parsed.inherit_window_mode);
|
||||
assert!(!parsed.inherit_resolution);
|
||||
assert_eq!(parsed.preferred_account, None);
|
||||
assert_eq!(parsed.pre_launch_command, LaunchCommand::default());
|
||||
assert_eq!(parsed.post_exit_command, LaunchCommand::default());
|
||||
assert_eq!(parsed.glfw_path, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn window_defaults_are_inherited_only_when_explicitly_enabled() {
|
||||
let mut config = InstanceConfig {
|
||||
name: "test".to_owned(),
|
||||
game_version: "1.21.1".to_owned(),
|
||||
loader: ModLoader::Vanilla,
|
||||
loader_version: None,
|
||||
created: Utc::now(),
|
||||
last_played: None,
|
||||
java_path: None,
|
||||
memory_max: None,
|
||||
memory_min: None,
|
||||
jvm_args: Vec::new(),
|
||||
environment: Default::default(),
|
||||
window_mode: WindowMode::Windowed,
|
||||
inherit_window_mode: false,
|
||||
resolution: None,
|
||||
inherit_resolution: false,
|
||||
preferred_account: None,
|
||||
pre_launch_command: Default::default(),
|
||||
post_exit_command: Default::default(),
|
||||
glfw_path: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
};
|
||||
assert_eq!(
|
||||
config.effective_window_mode(WindowMode::Fullscreen),
|
||||
WindowMode::Windowed
|
||||
);
|
||||
assert_eq!(config.effective_resolution(Some((1920, 1080))), None);
|
||||
|
||||
config.inherit_window_mode = true;
|
||||
config.inherit_resolution = true;
|
||||
assert_eq!(
|
||||
config.effective_window_mode(WindowMode::Fullscreen),
|
||||
WindowMode::Fullscreen
|
||||
);
|
||||
assert_eq!(
|
||||
config.effective_resolution(Some((1920, 1080))),
|
||||
Some((1920, 1080))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -76,6 +135,48 @@ fn instance_config_ignores_invalid_memory_values() {
|
||||
assert_eq!(parsed.memory_min, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn instance_config_normalizes_optional_paths_and_resolution() {
|
||||
let json = r#"
|
||||
{
|
||||
"name": "test",
|
||||
"game_version": "1.21.1",
|
||||
"loader": "vanilla",
|
||||
"loader_version": null,
|
||||
"created": "2026-04-20T18:04:25.567993893Z",
|
||||
"java_path": " ",
|
||||
"glfw_path": " /usr/lib/libglfw.so ",
|
||||
"preferred_account": "",
|
||||
"resolution": [0, 1080]
|
||||
}
|
||||
"#;
|
||||
|
||||
let parsed: InstanceConfig = serde_json::from_str(json).expect("deserialize");
|
||||
|
||||
assert!(parsed.java_path.is_none());
|
||||
assert_eq!(parsed.glfw_path.as_deref(), Some("/usr/lib/libglfw.so"));
|
||||
assert!(parsed.preferred_account.is_none());
|
||||
assert!(parsed.resolution.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn instance_config_rejects_zero_resolution_height() {
|
||||
let json = r#"
|
||||
{
|
||||
"name": "test",
|
||||
"game_version": "1.21.1",
|
||||
"loader": "vanilla",
|
||||
"loader_version": null,
|
||||
"created": "2026-04-20T18:04:25.567993893Z",
|
||||
"resolution": [1920, 0]
|
||||
}
|
||||
"#;
|
||||
|
||||
let parsed: InstanceConfig = serde_json::from_str(json).expect("deserialize");
|
||||
|
||||
assert!(parsed.resolution.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize_memory_value_rejects_invalid_values() {
|
||||
assert_eq!(normalize_memory_value("0"), None);
|
||||
@@ -84,3 +185,16 @@ fn normalize_memory_value_rejects_invalid_values() {
|
||||
assert_eq!(normalize_memory_value("8GB"), None);
|
||||
assert_eq!(normalize_memory_value("banana"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_resolution_accepts_common_separators() {
|
||||
assert_eq!(parse_resolution("1920x1080"), Ok((1920, 1080)));
|
||||
assert_eq!(parse_resolution(" 1280X720 "), Ok((1280, 720)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_resolution_rejects_invalid_values() {
|
||||
assert!(parse_resolution("1920").is_err());
|
||||
assert!(parse_resolution("0x1080").is_err());
|
||||
assert!(parse_resolution("wide x tall").is_err());
|
||||
}
|
||||
@@ -41,6 +41,14 @@ fn crashed_state_stores_exit_code() {
|
||||
assert_eq!(get("run_test_crash"), Some(RunState::Crashed(Some(1))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn crashed_instances_are_not_active() {
|
||||
set_state("run_test_inactive_crash", RunState::Crashed(Some(1)));
|
||||
assert!(!is_active("run_test_inactive_crash"));
|
||||
set_state("run_test_active_start", RunState::Starting);
|
||||
assert!(is_active("run_test_active_start"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn push_and_drain_last_played() {
|
||||
let time = Utc::now();
|
||||
|
||||
@@ -33,6 +33,8 @@ pub struct TemplateContext<'a> {
|
||||
pub launcher_version: &'a str,
|
||||
pub clientid: &'a str,
|
||||
pub quick_play_singleplayer: Option<&'a str>,
|
||||
pub resolution_width: Option<&'a str>,
|
||||
pub resolution_height: Option<&'a str>,
|
||||
}
|
||||
|
||||
pub fn substitute(input: &str, ctx: &TemplateContext) -> String {
|
||||
@@ -88,6 +90,8 @@ fn lookup(name: &str, ctx: &TemplateContext) -> Option<String> {
|
||||
"launcher_version" => ctx.launcher_version.to_string(),
|
||||
"clientid" => ctx.clientid.to_string(),
|
||||
"quickPlaySingleplayer" => ctx.quick_play_singleplayer?.to_owned(),
|
||||
"resolution_width" => ctx.resolution_width?.to_owned(),
|
||||
"resolution_height" => ctx.resolution_height?.to_owned(),
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -50,6 +50,8 @@ impl Fixture {
|
||||
launcher_version: "0.3.0",
|
||||
clientid: "0",
|
||||
quick_play_singleplayer: None,
|
||||
resolution_width: None,
|
||||
resolution_height: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,8 @@ impl Fixture {
|
||||
launcher_version: "0.3.0",
|
||||
clientid: "0",
|
||||
quick_play_singleplayer: None,
|
||||
resolution_width: None,
|
||||
resolution_height: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,3 +117,15 @@ fn quick_play_world_is_substituted_when_present() {
|
||||
"New World"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_resolution_is_substituted_when_present() {
|
||||
let fx = Fixture::unix();
|
||||
let mut context = fx.ctx();
|
||||
context.resolution_width = Some("1920");
|
||||
context.resolution_height = Some("1080");
|
||||
assert_eq!(
|
||||
substitute("${resolution_width}x${resolution_height}", &context),
|
||||
"1920x1080"
|
||||
);
|
||||
}
|
||||
+18
-1
@@ -138,9 +138,11 @@ pub fn run(
|
||||
if marker_version(&metadata.layout_marker()) == Some(LAYOUT_VERSION)
|
||||
&& metadata.cache_rebuild_pending().exists()
|
||||
{
|
||||
crate::config::upgrade_config_file(config_file)?;
|
||||
return Ok(latest_layout_backup(&metadata).unwrap_or_else(|| metadata.backups()));
|
||||
}
|
||||
if !is_needed(instances_dir, meta_dir) {
|
||||
crate::config::upgrade_config_file(config_file)?;
|
||||
initialize_new_layout(meta_dir)?;
|
||||
return Ok(metadata.backups());
|
||||
}
|
||||
@@ -149,7 +151,7 @@ pub fn run(
|
||||
|
||||
let mut journal = load_or_create_journal(instances_dir, &metadata)?;
|
||||
let instances = instance_directories(instances_dir)?;
|
||||
let total = instances.len() as u64 + 7;
|
||||
let total = instances.len() as u64 + 8;
|
||||
let mut current = journal.completed.len() as u64;
|
||||
|
||||
if !is_complete(&journal, "backup") {
|
||||
@@ -176,6 +178,21 @@ pub fn run(
|
||||
current += 1;
|
||||
}
|
||||
|
||||
if !is_complete(&journal, "config") {
|
||||
report(
|
||||
MigrationProgress::new(
|
||||
"Upgrading launcher config",
|
||||
config_file.display().to_string(),
|
||||
current,
|
||||
total,
|
||||
)
|
||||
.with_backup(&journal.backup_dir),
|
||||
);
|
||||
crate::config::upgrade_config_file(config_file)?;
|
||||
complete(&mut journal, &metadata, "config")?;
|
||||
current += 1;
|
||||
}
|
||||
|
||||
validate_migration_conflicts(&instances, meta_dir)?;
|
||||
|
||||
for instance in &instances {
|
||||
|
||||
@@ -27,6 +27,13 @@ pub fn run_legacy_rename() {
|
||||
if let (Some(desk), Some(data)) = (dirs::desktop_dir(), dirs_next::data_dir()) {
|
||||
rewrite_native_desktop_shortcuts(&desk, &data.join(NEW_NAME).join("instances"));
|
||||
}
|
||||
if let (Some(config_dir), Some(data_dir)) = (dirs_next::config_dir(), dirs_next::data_dir())
|
||||
&& !data_dir.join(OLD_NAME).exists()
|
||||
&& let Err(error) =
|
||||
crate::config::migrate_legacy_data_paths(&config_dir.join(NEW_NAME).join("config.toml"))
|
||||
{
|
||||
eprintln!("rmcl migration: failed to update legacy config paths: {error}");
|
||||
}
|
||||
}
|
||||
|
||||
fn rename_top_level(old: &Path, new: &Path) {
|
||||
|
||||
@@ -104,6 +104,10 @@ impl MetadataPaths {
|
||||
self.cache().join("loaders").join("profiles")
|
||||
}
|
||||
|
||||
pub fn java_installations(&self) -> PathBuf {
|
||||
self.cache().join("java").join("installations.json")
|
||||
}
|
||||
|
||||
pub fn provider_cache(&self, provider: &str) -> PathBuf {
|
||||
self.cache().join("providers").join(provider)
|
||||
}
|
||||
@@ -137,6 +141,18 @@ impl MetadataPaths {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clear_disposable_caches(meta_dir: &Path) -> io::Result<()> {
|
||||
let paths = MetadataPaths::new(meta_dir);
|
||||
for path in [paths.cache().join("providers"), paths.cache().join("java")] {
|
||||
match std::fs::remove_dir_all(&path) {
|
||||
Ok(()) => {}
|
||||
Err(error) if error.kind() == io::ErrorKind::NotFound => {}
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn write_atomic(path: &Path, bytes: &[u8]) -> io::Result<()> {
|
||||
let parent = path
|
||||
.parent()
|
||||
|
||||
@@ -38,6 +38,13 @@ fn migration_backs_up_and_renames_instance_directories() {
|
||||
b"options"
|
||||
);
|
||||
assert!(backup.join("instances/Example/.minecraft").exists());
|
||||
assert_eq!(
|
||||
fs::read_to_string(backup.join("config/config.toml")).unwrap(),
|
||||
"[paths]"
|
||||
);
|
||||
let upgraded_config = fs::read_to_string(&config).unwrap();
|
||||
assert!(upgraded_config.contains("check_modpack_updates = true"));
|
||||
assert!(upgraded_config.contains("resolution = [854, 480]"));
|
||||
assert!(backup.join("profiles/legacy/main/options.txt").exists());
|
||||
assert!(
|
||||
backup
|
||||
|
||||
@@ -32,12 +32,34 @@ fn metadata_paths_separate_state_and_cache() {
|
||||
paths.versions(),
|
||||
PathBuf::from("/meta/cache/minecraft/versions")
|
||||
);
|
||||
assert_eq!(
|
||||
paths.java_installations(),
|
||||
PathBuf::from("/meta/cache/java/installations.json")
|
||||
);
|
||||
assert_eq!(
|
||||
paths.migration_journal(),
|
||||
PathBuf::from("/meta/state/migration.json")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disposable_cache_cleanup_preserves_runtime_metadata() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let paths = MetadataPaths::new(temp.path());
|
||||
std::fs::create_dir_all(paths.provider_icons("modrinth")).unwrap();
|
||||
std::fs::create_dir_all(paths.java_installations().parent().unwrap()).unwrap();
|
||||
std::fs::create_dir_all(paths.temporary()).unwrap();
|
||||
std::fs::create_dir_all(paths.versions()).unwrap();
|
||||
std::fs::write(paths.java_installations(), "[]").unwrap();
|
||||
|
||||
clear_disposable_caches(temp.path()).unwrap();
|
||||
|
||||
assert!(!paths.cache().join("providers").exists());
|
||||
assert!(!paths.cache().join("java").exists());
|
||||
assert!(paths.temporary().exists());
|
||||
assert!(paths.versions().exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn atomic_write_replaces_existing_file() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
|
||||
+23
-4
@@ -19,6 +19,11 @@ use crate::instance::{InstanceConfig, InstanceManager};
|
||||
// so the main loop can pick them up without blocking
|
||||
pub(super) static PENDING_INSTANCES: LazyLock<Arc<Mutex<Vec<InstanceConfig>>>> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(Vec::new())));
|
||||
pub(super) static COMPLETED_INSTANCE_SETTINGS_UPDATES: LazyLock<Arc<Mutex<Vec<InstanceConfig>>>> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(Vec::new())));
|
||||
pub(super) static FAILED_INSTANCE_SETTINGS_UPDATES: LazyLock<Arc<Mutex<Vec<String>>>> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(Vec::new())));
|
||||
pub(super) const RUNTIME_UPDATE_PENDING_MESSAGE: &str = "Wait for the runtime update to finish";
|
||||
|
||||
pub struct App {
|
||||
pub(super) exit: bool,
|
||||
@@ -42,7 +47,11 @@ pub struct App {
|
||||
pub(super) logs_state: widgets::logs_viewer::LogsState,
|
||||
pub(super) account_state: widgets::account::AccountState,
|
||||
pub(super) settings_state: widgets::settings::SettingsState,
|
||||
pub(super) instance_settings: Option<widgets::popups::instance_settings::State>,
|
||||
pub(super) pending_instance_settings_updates: HashSet<String>,
|
||||
pub(super) global_settings: Option<widgets::popups::global_settings::State>,
|
||||
pub(super) picker: ratatui_image::picker::Picker,
|
||||
pub(super) detected_image_protocol: ratatui_image::picker::ProtocolType,
|
||||
pub(super) instance_manager: InstanceManager,
|
||||
pub(super) log_overlay_scroll: usize,
|
||||
pub(super) log_overlay_max_scroll: usize,
|
||||
@@ -89,6 +98,8 @@ pub enum FocusedArea {
|
||||
ImportPopup,
|
||||
ErrorPopup,
|
||||
ConfirmDelete,
|
||||
InstanceSettings,
|
||||
GlobalSettings,
|
||||
}
|
||||
|
||||
impl App {
|
||||
@@ -114,15 +125,19 @@ impl App {
|
||||
supported
|
||||
}
|
||||
|
||||
pub fn new(picker: ratatui_image::picker::Picker) -> Self {
|
||||
let instances_dir = crate::config::SETTINGS.paths.resolve_instances_dir();
|
||||
let meta_dir = crate::config::SETTINGS.paths.resolve_meta_dir();
|
||||
pub fn new(
|
||||
picker: ratatui_image::picker::Picker,
|
||||
detected_image_protocol: ratatui_image::picker::ProtocolType,
|
||||
) -> Self {
|
||||
let instances_dir = crate::config::SETTINGS.read().paths.resolve_instances_dir();
|
||||
let meta_dir = crate::config::SETTINGS.read().paths.resolve_meta_dir();
|
||||
|
||||
let _ = std::fs::create_dir_all(&instances_dir);
|
||||
let _ = std::fs::create_dir_all(&meta_dir);
|
||||
crate::instance::import::refresh::recover_interrupted(&instances_dir);
|
||||
|
||||
let manager = InstanceManager::new(instances_dir, meta_dir);
|
||||
let settings_state = widgets::settings::SettingsState::new(manager.meta_dir.clone());
|
||||
let instances = manager.load_all();
|
||||
instances::spawn_modpack_update_checks(&instances);
|
||||
let instances_state = instances::State::with_instances(instances);
|
||||
@@ -169,7 +184,10 @@ impl App {
|
||||
world_quick_play_support: None,
|
||||
logs_state: widgets::logs_viewer::LogsState::default(),
|
||||
account_state: widgets::account::AccountState::default(),
|
||||
settings_state: widgets::settings::SettingsState::new(manager.meta_dir.clone()),
|
||||
settings_state,
|
||||
instance_settings: None,
|
||||
pending_instance_settings_updates: HashSet::new(),
|
||||
global_settings: None,
|
||||
screenshots_state: {
|
||||
let mut s = widgets::screenshots_grid::ScreenshotsState::default();
|
||||
let font_size = picker.font_size();
|
||||
@@ -177,6 +195,7 @@ impl App {
|
||||
s
|
||||
},
|
||||
picker,
|
||||
detected_image_protocol,
|
||||
instance_manager: manager,
|
||||
log_overlay_scroll: 0,
|
||||
log_overlay_max_scroll: 0,
|
||||
|
||||
+242
-13
@@ -10,7 +10,10 @@ use ratatui::{
|
||||
use std::time::Duration;
|
||||
|
||||
use super::Tui;
|
||||
use super::app::{App, FocusedArea, PENDING_INSTANCES};
|
||||
use super::app::{
|
||||
App, COMPLETED_INSTANCE_SETTINGS_UPDATES, FAILED_INSTANCE_SETTINGS_UPDATES, FocusedArea,
|
||||
PENDING_INSTANCES, RUNTIME_UPDATE_PENDING_MESSAGE,
|
||||
};
|
||||
use super::widgets::{self, popups::import_modpack, popups::new_instance};
|
||||
use crate::feedback::errors as error_buffer;
|
||||
use crate::feedback::progress;
|
||||
@@ -43,6 +46,8 @@ impl App {
|
||||
// every content type has its own pending queue because they each
|
||||
// get scanned/loaded on separate tokio tasks
|
||||
self.drain_pending_instances();
|
||||
self.drain_completed_instance_settings_updates();
|
||||
self.drain_failed_instance_settings_updates();
|
||||
self.instances_state.drain_modpack_updates();
|
||||
self.drain_pending_last_played();
|
||||
if let Some(state) = self.modpack_versions_state.as_mut() {
|
||||
@@ -209,6 +214,8 @@ impl App {
|
||||
+ usize::from(self.instances_state.show_import_popup)
|
||||
+ usize::from(self.focused == super::app::FocusedArea::OverviewExpanded)
|
||||
+ usize::from(self.focused == super::app::FocusedArea::ConfirmDelete)
|
||||
+ usize::from(self.focused == super::app::FocusedArea::InstanceSettings)
|
||||
+ usize::from(self.focused == super::app::FocusedArea::GlobalSettings)
|
||||
+ usize::from(self.provider_conflict.is_some())
|
||||
+ usize::from(
|
||||
self.content_update_popup
|
||||
@@ -415,7 +422,7 @@ impl App {
|
||||
cached.map(|snapshot| (result.instance_name.clone(), snapshot));
|
||||
self.content_manifest = Some((result.instance_name.clone(), result.manifest.clone()));
|
||||
self.apply_content_update_snapshot();
|
||||
if stale {
|
||||
if stale && crate::config::SETTINGS.read().general.check_content_updates {
|
||||
crate::instance::content::updates::spawn(
|
||||
selected,
|
||||
result.manifest,
|
||||
@@ -505,7 +512,10 @@ impl App {
|
||||
}
|
||||
|
||||
fn ensure_provider_conflict_popup(&mut self) {
|
||||
if !crate::config::SETTINGS.content.ask_on_provider_conflict
|
||||
if !crate::config::SETTINGS
|
||||
.read()
|
||||
.content
|
||||
.ask_on_provider_conflict
|
||||
|| self.focused != super::app::FocusedArea::Content
|
||||
|| self.provider_conflict.is_some()
|
||||
{
|
||||
@@ -569,7 +579,7 @@ impl App {
|
||||
|
||||
fn spawn_create(&self, params: new_instance::WizardParams) {
|
||||
let instances_dir = self.instance_manager.instances_dir.clone();
|
||||
let meta_dir = crate::config::SETTINGS.paths.resolve_meta_dir();
|
||||
let meta_dir = crate::config::SETTINGS.read().paths.resolve_meta_dir();
|
||||
let pending_instances = PENDING_INSTANCES.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
@@ -605,9 +615,63 @@ impl App {
|
||||
});
|
||||
}
|
||||
|
||||
pub(super) fn spawn_instance_settings_update(
|
||||
&self,
|
||||
previous: crate::instance::InstanceConfig,
|
||||
mut updated: crate::instance::InstanceConfig,
|
||||
desktop: bool,
|
||||
) {
|
||||
let instances_dir = self.instance_manager.instances_dir.clone();
|
||||
let meta_dir = self.instance_manager.meta_dir.clone();
|
||||
let completed_updates = COMPLETED_INSTANCE_SETTINGS_UPDATES.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
progress::set_action(format!("Updating instance '{}'...", updated.name));
|
||||
progress::set_sub_action(format!("{} {}", updated.game_version, updated.loader));
|
||||
let manager = InstanceManager::new(&instances_dir, &meta_dir);
|
||||
updated = match apply_instance_settings_update(&manager, &previous, updated).await {
|
||||
Ok(updated) => updated,
|
||||
Err(error) => {
|
||||
progress::clear();
|
||||
if let Ok(mut failed) = FAILED_INSTANCE_SETTINGS_UPDATES.lock() {
|
||||
failed.push(previous.name.clone());
|
||||
}
|
||||
error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
level: tracing::Level::ERROR,
|
||||
message: format!("Failed to update instance '{}': {error}", previous.name),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let shortcut_result = crate::instance::desktop::set_enabled(&updated, desktop);
|
||||
if let Err(error) = shortcut_result {
|
||||
error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
level: tracing::Level::ERROR,
|
||||
message: format!("Instance saved, but shortcut update failed: {error}"),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
}
|
||||
if let Ok(mut pending) = completed_updates.lock() {
|
||||
pending.push(updated);
|
||||
}
|
||||
progress::clear();
|
||||
error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
level: tracing::Level::INFO,
|
||||
message: format!("Updated instance '{}'", previous.name),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
crate::feedback::request_redraw();
|
||||
});
|
||||
}
|
||||
|
||||
fn spawn_import(&self, result: import_modpack::ImportResult) {
|
||||
let instances_dir = self.instance_manager.instances_dir.clone();
|
||||
let meta_dir = crate::config::SETTINGS.paths.resolve_meta_dir();
|
||||
let meta_dir = crate::config::SETTINGS.read().paths.resolve_meta_dir();
|
||||
let pending_instances = PENDING_INSTANCES.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
@@ -689,8 +753,53 @@ impl App {
|
||||
}
|
||||
|
||||
fn reload_edited_config(&mut self, path: &std::path::Path) {
|
||||
if path.file_name().and_then(|n| n.to_str()) != Some("instance.json") {
|
||||
return;
|
||||
match path.file_name().and_then(|name| name.to_str()) {
|
||||
Some("config.toml") => {
|
||||
match crate::config::SETTINGS.reload() {
|
||||
Ok(outcome) => {
|
||||
if outcome.provider_changed {
|
||||
self.reset_discovery_states();
|
||||
}
|
||||
if outcome.modpack_updates_enabled {
|
||||
widgets::instances::spawn_modpack_update_checks(
|
||||
&self.instances_state.instances,
|
||||
);
|
||||
}
|
||||
if outcome.content_updates_enabled {
|
||||
self.spawn_selected_content_update_check();
|
||||
}
|
||||
if outcome.restart_required {
|
||||
error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
level: tracing::Level::INFO,
|
||||
message: "Path and image protocol changes apply after restart"
|
||||
.to_owned(),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
}
|
||||
}
|
||||
Err(error) => error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
level: tracing::Level::ERROR,
|
||||
message: format!("Failed to reload config.toml: {error}"),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
}),
|
||||
}
|
||||
return;
|
||||
}
|
||||
Some("theme.toml") => {
|
||||
if let Err(error) = crate::config::theme::reload_theme() {
|
||||
error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
level: tracing::Level::ERROR,
|
||||
message: format!("Failed to reload theme.toml: {error}"),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
Some("instance.json") => {}
|
||||
_ => return,
|
||||
}
|
||||
|
||||
let Some(name) = path
|
||||
@@ -725,6 +834,14 @@ impl App {
|
||||
use crate::instance::launch;
|
||||
use crate::instance::runtime;
|
||||
|
||||
if self
|
||||
.pending_instance_settings_updates
|
||||
.contains(&instance.name)
|
||||
{
|
||||
error_buffer::push_message(tracing::Level::WARN, RUNTIME_UPDATE_PENDING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
let instance = match self.instance_manager.load_one(&instance.name) {
|
||||
Ok(config) => config,
|
||||
Err(e) => {
|
||||
@@ -776,7 +893,7 @@ impl App {
|
||||
match error_buffer::peek_error() {
|
||||
Some(event)
|
||||
if event.pushed_at.elapsed().as_millis()
|
||||
>= SETTINGS.ui.error_auto_dismiss_ms as u128 =>
|
||||
>= SETTINGS.read().ui.error_auto_dismiss_ms as u128 =>
|
||||
{
|
||||
let _ = error_buffer::pop_error();
|
||||
}
|
||||
@@ -786,11 +903,73 @@ impl App {
|
||||
}
|
||||
|
||||
fn drain_pending_instances(&mut self) {
|
||||
if let Ok(mut pending) = PENDING_INSTANCES.lock() {
|
||||
for config in pending.drain(..) {
|
||||
self.forget_instance_content(&config.name);
|
||||
widgets::instances::spawn_modpack_update_check(&config);
|
||||
self.instances_state.add_instance(config);
|
||||
let pending = PENDING_INSTANCES
|
||||
.lock()
|
||||
.map(|mut pending| pending.drain(..).collect::<Vec<_>>())
|
||||
.unwrap_or_default();
|
||||
for config in pending {
|
||||
self.apply_pending_instance(config, false);
|
||||
}
|
||||
}
|
||||
|
||||
fn drain_completed_instance_settings_updates(&mut self) {
|
||||
let completed = COMPLETED_INSTANCE_SETTINGS_UPDATES
|
||||
.lock()
|
||||
.map(|mut pending| pending.drain(..).collect::<Vec<_>>())
|
||||
.unwrap_or_default();
|
||||
for config in completed {
|
||||
self.apply_pending_instance(config, true);
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_pending_instance(
|
||||
&mut self,
|
||||
config: crate::instance::InstanceConfig,
|
||||
settings_update: bool,
|
||||
) {
|
||||
let config = self
|
||||
.instance_manager
|
||||
.load_one(&config.name)
|
||||
.unwrap_or(config);
|
||||
if settings_update {
|
||||
self.pending_instance_settings_updates.remove(&config.name);
|
||||
if let Some(state) = self.instance_settings.as_mut()
|
||||
&& state.runtime_update_pending_for(&config.name)
|
||||
{
|
||||
let desktop = crate::instance::desktop::exists(&config.name);
|
||||
state.mark_saved(&config, desktop);
|
||||
}
|
||||
}
|
||||
self.forget_instance_content(&config.name);
|
||||
widgets::instances::spawn_modpack_update_check(&config);
|
||||
if self
|
||||
.instances_state
|
||||
.instances
|
||||
.iter()
|
||||
.any(|instance| instance.name == config.name)
|
||||
{
|
||||
let name = config.name.clone();
|
||||
self.instances_state.replace_instance(&name, config);
|
||||
} else {
|
||||
self.instances_state.add_instance(config);
|
||||
}
|
||||
}
|
||||
|
||||
fn drain_failed_instance_settings_updates(&mut self) {
|
||||
let failed = FAILED_INSTANCE_SETTINGS_UPDATES
|
||||
.lock()
|
||||
.map(|mut failed| failed.drain(..).collect::<Vec<_>>())
|
||||
.unwrap_or_default();
|
||||
for name in failed {
|
||||
self.pending_instance_settings_updates.remove(&name);
|
||||
let remaining = self.instance_settings.as_mut().and_then(|state| {
|
||||
state
|
||||
.runtime_update_pending_for(&name)
|
||||
.then(|| state.cancel_runtime_change())
|
||||
.flatten()
|
||||
});
|
||||
if let Some((updated, desktop)) = remaining {
|
||||
self.apply_instance_settings(*updated, desktop);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -840,6 +1019,56 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
async fn apply_instance_settings_update(
|
||||
manager: &InstanceManager,
|
||||
previous: &crate::instance::InstanceConfig,
|
||||
mut updated: crate::instance::InstanceConfig,
|
||||
) -> color_eyre::Result<crate::instance::InstanceConfig> {
|
||||
manager.repair_runtime_cache(&updated).await?;
|
||||
|
||||
if crate::instance::runtime::is_active(&previous.name) {
|
||||
color_eyre::eyre::bail!("instance started while its runtime was being updated");
|
||||
}
|
||||
|
||||
let current = manager.load_one(&previous.name)?;
|
||||
updated = merge_instance_settings(previous, &updated, current);
|
||||
manager.save(&updated)?;
|
||||
|
||||
Ok(updated)
|
||||
}
|
||||
|
||||
pub(super) fn merge_instance_settings(
|
||||
previous: &crate::instance::InstanceConfig,
|
||||
updated: &crate::instance::InstanceConfig,
|
||||
mut current: crate::instance::InstanceConfig,
|
||||
) -> crate::instance::InstanceConfig {
|
||||
macro_rules! apply_changed {
|
||||
($field:ident) => {
|
||||
if previous.$field != updated.$field {
|
||||
current.$field.clone_from(&updated.$field);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
apply_changed!(game_version);
|
||||
apply_changed!(loader);
|
||||
apply_changed!(loader_version);
|
||||
apply_changed!(java_path);
|
||||
apply_changed!(memory_max);
|
||||
apply_changed!(memory_min);
|
||||
apply_changed!(jvm_args);
|
||||
apply_changed!(environment);
|
||||
apply_changed!(window_mode);
|
||||
apply_changed!(inherit_window_mode);
|
||||
apply_changed!(resolution);
|
||||
apply_changed!(inherit_resolution);
|
||||
apply_changed!(preferred_account);
|
||||
apply_changed!(pre_launch_command);
|
||||
apply_changed!(post_exit_command);
|
||||
apply_changed!(glfw_path);
|
||||
current
|
||||
}
|
||||
|
||||
fn mark_terminal_images(buffer: &mut Buffer, alternate: bool) {
|
||||
// toggling an invisible suffix lets the normal cell diff redraw exposed
|
||||
// images before later popup cells, without clearing or repainting the screen
|
||||
|
||||
+488
-43
@@ -205,7 +205,34 @@ impl App {
|
||||
}
|
||||
Some(confirm_popup::ConfirmTarget::Account { index, .. }) => {
|
||||
let count = self.account_state.store.accounts.len();
|
||||
let removed_uuid = self
|
||||
.account_state
|
||||
.store
|
||||
.accounts
|
||||
.get(index)
|
||||
.map(|account| account.uuid.clone());
|
||||
self.account_state.store.remove(index);
|
||||
if let Some(removed_uuid) = removed_uuid {
|
||||
for instance in &mut self.instances_state.instances {
|
||||
if instance.preferred_account.as_deref()
|
||||
== Some(removed_uuid.as_str())
|
||||
{
|
||||
let mut updated = instance.clone();
|
||||
updated.preferred_account = None;
|
||||
if let Err(error) = self.instance_manager.save(&updated) {
|
||||
error_buffer::push_message(
|
||||
tracing::Level::ERROR,
|
||||
format!(
|
||||
"Failed to reset preferred account for '{}': {error}",
|
||||
instance.name
|
||||
),
|
||||
);
|
||||
} else {
|
||||
*instance = updated;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if count > 1 {
|
||||
self.account_state.list_state.selected = Some(index.min(
|
||||
self.account_state.store.accounts.len().saturating_sub(1),
|
||||
@@ -223,6 +250,8 @@ impl App {
|
||||
message: e.to_string(),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
} else {
|
||||
self.settings_state.remove_profile(&profile);
|
||||
}
|
||||
FocusedArea::Settings
|
||||
}
|
||||
@@ -259,6 +288,83 @@ impl App {
|
||||
}
|
||||
FocusedArea::Content
|
||||
}
|
||||
Some(confirm_popup::ConfirmTarget::InstanceRuntime { .. }) => {
|
||||
self.focused = FocusedArea::InstanceSettings;
|
||||
let confirmed = self
|
||||
.instance_settings
|
||||
.as_mut()
|
||||
.and_then(|state| state.confirmed_save());
|
||||
if let Some((updated, desktop)) = confirmed {
|
||||
self.apply_instance_settings(*updated, desktop);
|
||||
}
|
||||
self.focused
|
||||
}
|
||||
Some(confirm_popup::ConfirmTarget::LauncherCache) => {
|
||||
let meta_dir = crate::config::SETTINGS.read().paths.resolve_meta_dir();
|
||||
match crate::storage::clear_disposable_caches(&meta_dir) {
|
||||
Ok(()) => {
|
||||
self.reset_discovery_states();
|
||||
if let Some(state) = self.global_settings.as_mut() {
|
||||
state.invalidate_java_cache();
|
||||
}
|
||||
if let Some(state) = self.instance_settings.as_mut() {
|
||||
state.invalidate_java_cache();
|
||||
}
|
||||
error_buffer::push_message(
|
||||
tracing::Level::INFO,
|
||||
"Cleared launcher caches",
|
||||
);
|
||||
}
|
||||
Err(error) => error_buffer::push_message(
|
||||
tracing::Level::ERROR,
|
||||
format!("Failed to clear launcher caches: {error}"),
|
||||
),
|
||||
}
|
||||
FocusedArea::GlobalSettings
|
||||
}
|
||||
Some(confirm_popup::ConfirmTarget::AutomaticSelection {
|
||||
setting,
|
||||
instance,
|
||||
..
|
||||
}) => {
|
||||
match setting {
|
||||
confirm_popup::AutomaticSetting::Java if instance.is_some() => {
|
||||
self.focused = FocusedArea::InstanceSettings;
|
||||
let confirmed =
|
||||
self.instance_settings.as_mut().and_then(|state| {
|
||||
state.enable_auto_java();
|
||||
state.confirmed_save()
|
||||
});
|
||||
if let Some((updated, desktop)) = confirmed {
|
||||
self.apply_instance_settings(*updated, desktop);
|
||||
}
|
||||
}
|
||||
confirm_popup::AutomaticSetting::Account => {
|
||||
self.focused = FocusedArea::InstanceSettings;
|
||||
let confirmed =
|
||||
self.instance_settings.as_mut().and_then(|state| {
|
||||
state.enable_auto_account();
|
||||
state.confirmed_save()
|
||||
});
|
||||
if let Some((updated, desktop)) = confirmed {
|
||||
self.apply_instance_settings(*updated, desktop);
|
||||
}
|
||||
}
|
||||
confirm_popup::AutomaticSetting::Java => {
|
||||
self.focused = FocusedArea::GlobalSettings;
|
||||
let action = self.global_settings.as_mut().map(
|
||||
widgets::popups::global_settings::State::confirm_auto_java,
|
||||
);
|
||||
if let Some(widgets::popups::global_settings::Action::Save(
|
||||
config,
|
||||
)) = action
|
||||
{
|
||||
self.apply_global_settings(*config);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.focused
|
||||
}
|
||||
None => FocusedArea::Instances,
|
||||
};
|
||||
confirm_popup::clear_pending();
|
||||
@@ -275,6 +381,28 @@ impl App {
|
||||
Some(confirm_popup::ConfirmTarget::ConfigProfile { .. }) => {
|
||||
FocusedArea::Settings
|
||||
}
|
||||
Some(confirm_popup::ConfirmTarget::InstanceRuntime { .. }) => {
|
||||
let remaining = self
|
||||
.instance_settings
|
||||
.as_mut()
|
||||
.and_then(|state| state.cancel_runtime_change());
|
||||
if let Some((updated, desktop)) = remaining {
|
||||
self.apply_instance_settings(*updated, desktop);
|
||||
}
|
||||
FocusedArea::InstanceSettings
|
||||
}
|
||||
Some(confirm_popup::ConfirmTarget::LauncherCache) => {
|
||||
FocusedArea::GlobalSettings
|
||||
}
|
||||
Some(confirm_popup::ConfirmTarget::AutomaticSelection {
|
||||
instance, ..
|
||||
}) => {
|
||||
if instance.is_some() {
|
||||
FocusedArea::InstanceSettings
|
||||
} else {
|
||||
FocusedArea::GlobalSettings
|
||||
}
|
||||
}
|
||||
_ => FocusedArea::Instances,
|
||||
};
|
||||
confirm_popup::clear_pending();
|
||||
@@ -561,64 +689,56 @@ impl App {
|
||||
&key_event,
|
||||
&mut self.settings_state,
|
||||
self.instances_state.selected_instance(),
|
||||
&self.instance_manager.instances_dir,
|
||||
) {
|
||||
widgets::settings::SettingsAction::EditInstance(path)
|
||||
| widgets::settings::SettingsAction::EditGlobal(path) => {
|
||||
self.pending_editor = Some(path);
|
||||
widgets::settings::SettingsAction::OpenInstance => {
|
||||
self.open_instance_settings(FocusedArea::Settings);
|
||||
return Ok(());
|
||||
}
|
||||
widgets::settings::SettingsAction::ToggleDesktop => {
|
||||
if let Some(inst) = self.instances_state.selected_instance() {
|
||||
let name = inst.name.clone();
|
||||
match crate::instance::desktop::toggle(inst) {
|
||||
Ok(true) => {
|
||||
error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
level: tracing::Level::INFO,
|
||||
message: format!("Desktop shortcut created for '{name}'"),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
}
|
||||
Ok(false) => {
|
||||
error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
level: tracing::Level::INFO,
|
||||
message: format!("Desktop shortcut removed for '{name}'"),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to toggle desktop shortcut: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
widgets::settings::SettingsAction::OpenGlobal => {
|
||||
self.pre_overlay_focused = FocusedArea::Settings;
|
||||
self.global_settings = Some(
|
||||
widgets::popups::global_settings::State::with_detected_image_protocol(
|
||||
self.detected_image_protocol,
|
||||
),
|
||||
);
|
||||
self.focused = FocusedArea::GlobalSettings;
|
||||
return Ok(());
|
||||
}
|
||||
widgets::settings::SettingsAction::SelectProfile(profile) => {
|
||||
if let Some(inst) = self.instances_state.selected_instance().cloned() {
|
||||
let instance_dir = self.instance_manager.instances_dir.join(&inst.name);
|
||||
if let Some(instance) = self.instances_state.selected_instance().cloned() {
|
||||
if self
|
||||
.pending_instance_settings_updates
|
||||
.contains(&instance.name)
|
||||
{
|
||||
error_buffer::push_message(
|
||||
tracing::Level::WARN,
|
||||
super::app::RUNTIME_UPDATE_PENDING_MESSAGE,
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
let instance_dir = self.instance_manager.instances_dir.join(&instance.name);
|
||||
match crate::instance::config_sync::switch_profile(
|
||||
&inst.name,
|
||||
inst.config_sync_profile.as_deref(),
|
||||
&instance.name,
|
||||
instance.config_sync_profile.as_deref(),
|
||||
profile.as_deref(),
|
||||
&self.instance_manager.meta_dir,
|
||||
&instance_dir,
|
||||
) {
|
||||
Ok(selected) => {
|
||||
let mut updated = inst.clone();
|
||||
let mut updated = instance.clone();
|
||||
updated.config_sync_profile = selected;
|
||||
if let Err(e) = self.instance_manager.save(&updated) {
|
||||
tracing::error!("Failed to save config profile: {}", e);
|
||||
if let Err(error) = self.instance_manager.save(&updated) {
|
||||
tracing::error!("Failed to save config profile: {error}");
|
||||
} else {
|
||||
self.instances_state.replace_instance(&inst.name, updated);
|
||||
self.instances_state
|
||||
.replace_instance(&instance.name, updated);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
Err(error) => {
|
||||
error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
level: tracing::Level::ERROR,
|
||||
message: e.to_string(),
|
||||
message: error.to_string(),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
}
|
||||
@@ -649,6 +769,111 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
if self.focused == FocusedArea::GlobalSettings {
|
||||
let action = self
|
||||
.global_settings
|
||||
.as_mut()
|
||||
.map(|state| state.handle_key(&key_event))
|
||||
.unwrap_or(widgets::popups::global_settings::Action::Close);
|
||||
match action {
|
||||
widgets::popups::global_settings::Action::None => {}
|
||||
widgets::popups::global_settings::Action::Error(message) => {
|
||||
error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
level: tracing::Level::ERROR,
|
||||
message,
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
}
|
||||
widgets::popups::global_settings::Action::ConfirmJavaAuto => {
|
||||
confirm_popup::set_pending(confirm_popup::ConfirmTarget::AutomaticSelection {
|
||||
setting: confirm_popup::AutomaticSetting::Java,
|
||||
instance: None,
|
||||
});
|
||||
self.focused = FocusedArea::ConfirmDelete;
|
||||
}
|
||||
widgets::popups::global_settings::Action::ClearCache => {
|
||||
confirm_popup::set_pending(confirm_popup::ConfirmTarget::LauncherCache);
|
||||
self.focused = FocusedArea::ConfirmDelete;
|
||||
}
|
||||
widgets::popups::global_settings::Action::Close => {
|
||||
self.global_settings = None;
|
||||
self.focused = self.pre_overlay_focused;
|
||||
}
|
||||
widgets::popups::global_settings::Action::OpenRaw(path) => {
|
||||
self.pending_editor = Some(path);
|
||||
self.global_settings = None;
|
||||
self.focused = self.pre_overlay_focused;
|
||||
}
|
||||
widgets::popups::global_settings::Action::Save(config) => {
|
||||
self.apply_global_settings(*config);
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if self.focused == FocusedArea::InstanceSettings {
|
||||
let action = self
|
||||
.instance_settings
|
||||
.as_mut()
|
||||
.map(|state| state.handle_key(&key_event))
|
||||
.unwrap_or(widgets::popups::instance_settings::Action::Close);
|
||||
match action {
|
||||
widgets::popups::instance_settings::Action::None => {}
|
||||
widgets::popups::instance_settings::Action::Error(message) => {
|
||||
error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
level: tracing::Level::ERROR,
|
||||
message,
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
}
|
||||
widgets::popups::instance_settings::Action::Warning(message) => {
|
||||
error_buffer::push_message(tracing::Level::WARN, message);
|
||||
}
|
||||
widgets::popups::instance_settings::Action::Close => {
|
||||
self.instance_settings = None;
|
||||
self.focused = self.pre_overlay_focused;
|
||||
}
|
||||
widgets::popups::instance_settings::Action::OpenRaw => {
|
||||
if let Some(instance) = self.instances_state.selected_instance() {
|
||||
self.pending_editor = Some(
|
||||
self.instance_manager
|
||||
.instances_dir
|
||||
.join(&instance.name)
|
||||
.join("instance.json"),
|
||||
);
|
||||
}
|
||||
self.instance_settings = None;
|
||||
self.focused = self.pre_overlay_focused;
|
||||
}
|
||||
widgets::popups::instance_settings::Action::Save(updated, desktop) => {
|
||||
self.apply_instance_settings(*updated, desktop);
|
||||
}
|
||||
widgets::popups::instance_settings::Action::ConfirmRuntime { name } => {
|
||||
confirm_popup::set_pending(confirm_popup::ConfirmTarget::InstanceRuntime {
|
||||
name,
|
||||
});
|
||||
self.focused = FocusedArea::ConfirmDelete;
|
||||
}
|
||||
widgets::popups::instance_settings::Action::ConfirmJavaAuto { name } => {
|
||||
confirm_popup::set_pending(confirm_popup::ConfirmTarget::AutomaticSelection {
|
||||
setting: confirm_popup::AutomaticSetting::Java,
|
||||
instance: Some(name),
|
||||
});
|
||||
self.focused = FocusedArea::ConfirmDelete;
|
||||
}
|
||||
widgets::popups::instance_settings::Action::ConfirmAccountAuto { name } => {
|
||||
confirm_popup::set_pending(confirm_popup::ConfirmTarget::AutomaticSelection {
|
||||
setting: confirm_popup::AutomaticSetting::Account,
|
||||
instance: Some(name),
|
||||
});
|
||||
self.focused = FocusedArea::ConfirmDelete;
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
match self.focused {
|
||||
FocusedArea::Popup => {
|
||||
new_instance::handle_key(&key_event, &mut self.instances_state);
|
||||
@@ -732,6 +957,18 @@ impl App {
|
||||
KeyCode::Char('C') => self.focused = FocusedArea::Content,
|
||||
KeyCode::Char('A') => self.focused = FocusedArea::Account,
|
||||
KeyCode::Char('S') => self.focused = FocusedArea::Settings,
|
||||
KeyCode::Char('E') => {
|
||||
self.open_instance_settings(self.focused);
|
||||
}
|
||||
KeyCode::Char('G') => {
|
||||
self.pre_overlay_focused = self.focused;
|
||||
self.global_settings = Some(
|
||||
widgets::popups::global_settings::State::with_detected_image_protocol(
|
||||
self.detected_image_protocol,
|
||||
),
|
||||
);
|
||||
self.focused = FocusedArea::GlobalSettings;
|
||||
}
|
||||
KeyCode::Char('O') => {
|
||||
self.pre_overlay_focused = self.focused;
|
||||
self.focused = FocusedArea::OverviewExpanded;
|
||||
@@ -779,8 +1016,15 @@ impl App {
|
||||
{
|
||||
if let Some(instance) = self.instances_state.selected_instance() {
|
||||
let name = instance.name.clone();
|
||||
confirm_popup::set_pending_instance_delete(&name);
|
||||
self.focused = FocusedArea::ConfirmDelete;
|
||||
if self.pending_instance_settings_updates.contains(&name) {
|
||||
error_buffer::push_message(
|
||||
tracing::Level::WARN,
|
||||
super::app::RUNTIME_UPDATE_PENDING_MESSAGE,
|
||||
);
|
||||
} else {
|
||||
confirm_popup::set_pending_instance_delete(&name);
|
||||
self.focused = FocusedArea::ConfirmDelete;
|
||||
}
|
||||
}
|
||||
}
|
||||
// shift+enter = open .minecraft folder in file manager
|
||||
@@ -834,7 +1078,14 @@ impl App {
|
||||
&& !self.instances_state.search.active =>
|
||||
{
|
||||
if let Some(inst) = self.instances_state.selected_instance() {
|
||||
self.instances_state.renaming = Some(inst.name.clone());
|
||||
if self.pending_instance_settings_updates.contains(&inst.name) {
|
||||
error_buffer::push_message(
|
||||
tracing::Level::WARN,
|
||||
super::app::RUNTIME_UPDATE_PENDING_MESSAGE,
|
||||
);
|
||||
} else {
|
||||
self.instances_state.renaming = Some(inst.name.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
// esc = kill running instance. brutal but effective
|
||||
@@ -874,6 +1125,20 @@ impl App {
|
||||
}
|
||||
|
||||
fn spawn_modpack_update(&mut self) {
|
||||
if self
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.is_some_and(|instance| {
|
||||
self.pending_instance_settings_updates
|
||||
.contains(&instance.name)
|
||||
})
|
||||
{
|
||||
error_buffer::push_message(
|
||||
tracing::Level::WARN,
|
||||
super::app::RUNTIME_UPDATE_PENDING_MESSAGE,
|
||||
);
|
||||
return;
|
||||
}
|
||||
let Some(target) = self.instances_state.selected_modpack_update() else {
|
||||
return;
|
||||
};
|
||||
@@ -884,6 +1149,16 @@ impl App {
|
||||
let Some(instance) = self.instances_state.selected_instance() else {
|
||||
return;
|
||||
};
|
||||
if self
|
||||
.pending_instance_settings_updates
|
||||
.contains(&instance.name)
|
||||
{
|
||||
error_buffer::push_message(
|
||||
tracing::Level::WARN,
|
||||
super::app::RUNTIME_UPDATE_PENDING_MESSAGE,
|
||||
);
|
||||
return;
|
||||
}
|
||||
let Some(source) = instance.modpack_source.clone() else {
|
||||
return;
|
||||
};
|
||||
@@ -1783,6 +2058,15 @@ impl App {
|
||||
|
||||
fn delete_config_profile(&mut self, profile: &str) -> color_eyre::Result<()> {
|
||||
let instances = self.instance_manager.load_all();
|
||||
if let Some(instance) = instances.iter().find(|instance| {
|
||||
instance.config_sync_profile.as_deref() == Some(profile)
|
||||
&& crate::instance::runtime::is_active(&instance.name)
|
||||
}) {
|
||||
return Err(color_eyre::eyre::eyre!(
|
||||
"Stop '{}' before deleting its active config profile",
|
||||
instance.name
|
||||
));
|
||||
}
|
||||
for instance in instances
|
||||
.into_iter()
|
||||
.filter(|instance| instance.config_sync_profile.as_deref() == Some(profile))
|
||||
@@ -1802,7 +2086,6 @@ impl App {
|
||||
}
|
||||
|
||||
crate::instance::config_sync::delete_profile(&self.instance_manager.meta_dir, profile)?;
|
||||
self.settings_state.remove_profile(profile);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1918,6 +2201,168 @@ impl App {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn open_instance_settings(&mut self, return_focus: FocusedArea) {
|
||||
let Some(instance) = self.instances_state.selected_instance().cloned() else {
|
||||
return;
|
||||
};
|
||||
let mut state = widgets::popups::instance_settings::State::with_accounts(
|
||||
&instance,
|
||||
&self.instance_manager.meta_dir,
|
||||
self.account_state.store.accounts.clone(),
|
||||
);
|
||||
if self
|
||||
.pending_instance_settings_updates
|
||||
.contains(&instance.name)
|
||||
{
|
||||
state.mark_runtime_update_pending();
|
||||
}
|
||||
self.pre_overlay_focused = return_focus;
|
||||
self.instance_settings = Some(state);
|
||||
self.focused = FocusedArea::InstanceSettings;
|
||||
}
|
||||
|
||||
fn apply_global_settings(&mut self, config: crate::config::Config) {
|
||||
let result = crate::config::SETTINGS.save_launcher_settings(config);
|
||||
match result {
|
||||
Ok(outcome) => {
|
||||
if outcome.provider_changed {
|
||||
self.reset_discovery_states();
|
||||
}
|
||||
if outcome.modpack_updates_enabled {
|
||||
widgets::instances::spawn_modpack_update_checks(
|
||||
&self.instances_state.instances,
|
||||
);
|
||||
}
|
||||
if outcome.content_updates_enabled {
|
||||
self.spawn_selected_content_update_check();
|
||||
}
|
||||
if outcome.restart_required && outcome.restart_changed {
|
||||
error_buffer::push_message(
|
||||
tracing::Level::INFO,
|
||||
"Restart rmcl to apply storage and image changes",
|
||||
);
|
||||
}
|
||||
crate::feedback::request_redraw();
|
||||
}
|
||||
Err(error) => {
|
||||
if let Some(state) = self.global_settings.as_mut() {
|
||||
state.mark_save_failed();
|
||||
}
|
||||
error_buffer::push_message(tracing::Level::ERROR, error.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn apply_instance_settings(
|
||||
&mut self,
|
||||
mut updated: crate::instance::models::InstanceConfig,
|
||||
desktop: bool,
|
||||
) {
|
||||
let Some(previous) = self.instances_state.selected_instance().cloned() else {
|
||||
return;
|
||||
};
|
||||
let structural_change = previous.game_version != updated.game_version
|
||||
|| previous.loader != updated.loader
|
||||
|| previous.loader_version != updated.loader_version;
|
||||
if structural_change {
|
||||
if crate::instance::runtime::is_active(&previous.name) {
|
||||
error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
level: tracing::Level::ERROR,
|
||||
message: "Stop the instance before changing its runtime".to_owned(),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
if let Some(state) = self.instance_settings.as_mut() {
|
||||
let remaining = state.cancel_runtime_change();
|
||||
if let Some((updated, desktop)) = remaining {
|
||||
self.apply_instance_settings(*updated, desktop);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
self.pending_instance_settings_updates
|
||||
.insert(previous.name.clone());
|
||||
self.spawn_instance_settings_update(previous, updated, desktop);
|
||||
if let Some(state) = self.instance_settings.as_mut() {
|
||||
state.mark_runtime_update_pending();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let current = match self.instance_manager.load_one(&previous.name) {
|
||||
Ok(current) => current,
|
||||
Err(error) => {
|
||||
if let Some(state) = self.instance_settings.as_mut() {
|
||||
state.mark_save_failed();
|
||||
}
|
||||
error_buffer::push_message(tracing::Level::ERROR, error.to_string());
|
||||
return;
|
||||
}
|
||||
};
|
||||
updated = super::event::merge_instance_settings(&previous, &updated, current);
|
||||
match self.instance_manager.save(&updated) {
|
||||
Ok(()) => {
|
||||
let shortcut_result = crate::instance::desktop::set_enabled(&updated, desktop);
|
||||
let saved_desktop = match shortcut_result {
|
||||
Ok(()) => desktop,
|
||||
Err(error) => {
|
||||
error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
level: tracing::Level::ERROR,
|
||||
message: format!("Instance saved, but shortcut update failed: {error}"),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
crate::instance::desktop::exists(&updated.name)
|
||||
}
|
||||
};
|
||||
self.instances_state
|
||||
.replace_instance(&previous.name, updated.clone());
|
||||
if let Some(state) = self.instance_settings.as_mut() {
|
||||
state.mark_saved(&updated, saved_desktop);
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
if let Some(state) = self.instance_settings.as_mut() {
|
||||
state.mark_save_failed();
|
||||
}
|
||||
error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
level: tracing::Level::ERROR,
|
||||
message: error.to_string(),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn reset_discovery_states(&mut self) {
|
||||
self.mods_discovery_state =
|
||||
widgets::content::DiscoveryState::new(crate::instance::ContentKind::Mod);
|
||||
self.resource_packs_discovery_state =
|
||||
widgets::content::DiscoveryState::new(crate::instance::ContentKind::ResourcePack);
|
||||
self.shaders_discovery_state =
|
||||
widgets::content::DiscoveryState::new(crate::instance::ContentKind::Shader);
|
||||
self.datapacks_discovery_state =
|
||||
widgets::content::DiscoveryState::new(crate::instance::ContentKind::DataPack);
|
||||
}
|
||||
|
||||
pub(super) fn spawn_selected_content_update_check(&self) {
|
||||
let Some(instance) = self.instances_state.selected_instance().cloned() else {
|
||||
return;
|
||||
};
|
||||
let Some((name, manifest)) = self.content_manifest.as_ref() else {
|
||||
return;
|
||||
};
|
||||
if name != &instance.name {
|
||||
return;
|
||||
}
|
||||
let path = crate::storage::InstancePaths::new(
|
||||
self.instance_manager.instances_dir.join(&instance.name),
|
||||
)
|
||||
.content_updates();
|
||||
crate::instance::content::updates::spawn(instance, manifest.clone(), path);
|
||||
}
|
||||
}
|
||||
|
||||
fn delete_content_path(path: &std::path::Path) -> std::io::Result<()> {
|
||||
|
||||
+14
-6
@@ -49,7 +49,8 @@ pub async fn show() -> color_eyre::Result<()> {
|
||||
let mut picker = ratatui_image::picker::Picker::from_query_stdio()
|
||||
.unwrap_or_else(|_| ratatui_image::picker::Picker::halfblocks());
|
||||
let detected_protocol = picker.protocol_type();
|
||||
let requested_protocol = match crate::config::SETTINGS.ui.image_protocol {
|
||||
let requested_protocol = match crate::config::SETTINGS.read().ui.image_protocol {
|
||||
crate::config::settings::ImageProtocol::Auto => detected_protocol,
|
||||
crate::config::settings::ImageProtocol::Halfblocks
|
||||
| crate::config::settings::ImageProtocol::Quadrants => {
|
||||
ratatui_image::picker::ProtocolType::Halfblocks
|
||||
@@ -68,14 +69,14 @@ pub async fn show() -> color_eyre::Result<()> {
|
||||
};
|
||||
picker.set_protocol_type(requested_protocol);
|
||||
|
||||
let mut app = app::App::new(picker);
|
||||
let mut app = app::App::new(picker, detected_protocol);
|
||||
match run_layout_migration_screen(&mut terminal, &mut app).await? {
|
||||
MigrationScreenOutcome::NotNeeded => {}
|
||||
MigrationScreenOutcome::Migrated => {
|
||||
// the modal uses pre-migration state as its background. rebuild the
|
||||
// app after confirmation so no instance or profile data stays stale
|
||||
let picker = app.into_picker();
|
||||
app = app::App::new(picker);
|
||||
app = app::App::new(picker, detected_protocol);
|
||||
}
|
||||
MigrationScreenOutcome::Quit => return Ok(()),
|
||||
}
|
||||
@@ -106,13 +107,20 @@ async fn run_layout_migration_screen(
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
||||
let instances_dir = crate::config::SETTINGS.paths.resolve_instances_dir();
|
||||
let meta_dir = crate::config::SETTINGS.paths.resolve_meta_dir();
|
||||
let instances_dir = crate::config::SETTINGS.read().paths.resolve_instances_dir();
|
||||
let meta_dir = crate::config::SETTINGS.read().paths.resolve_meta_dir();
|
||||
let config = crate::config::get_config_path().join("config.toml");
|
||||
if !crate::layout_migration::is_needed(&instances_dir, &meta_dir) {
|
||||
crate::layout_migration::initialize_new_layout(&meta_dir)?;
|
||||
if let Err(error) = crate::config::upgrade_config_file(&config) {
|
||||
tracing::warn!("Could not upgrade launcher config: {error}");
|
||||
crate::feedback::errors::push_message(
|
||||
tracing::Level::ERROR,
|
||||
format!("Could not upgrade config.toml: {error}"),
|
||||
);
|
||||
}
|
||||
return Ok(MigrationScreenOutcome::NotNeeded);
|
||||
}
|
||||
let config = crate::config::get_config_path().join("config.toml");
|
||||
|
||||
loop {
|
||||
let progress = Arc::new(Mutex::new(crate::layout_migration::MigrationProgress {
|
||||
|
||||
+33
-13
@@ -137,7 +137,6 @@ impl App {
|
||||
self.focused,
|
||||
&mut self.settings_state,
|
||||
self.instances_state.selected_instance(),
|
||||
&self.instance_manager.instances_dir,
|
||||
);
|
||||
widgets::status::render(
|
||||
frame,
|
||||
@@ -150,6 +149,20 @@ impl App {
|
||||
self.render_log_overlay(frame);
|
||||
}
|
||||
|
||||
if self.focused == FocusedArea::InstanceSettings
|
||||
&& let Some(state) = self.instance_settings.as_mut()
|
||||
{
|
||||
let area = widgets::popups::instance_settings::popup_rect(frame.area(), state);
|
||||
widgets::popups::instance_settings::render(frame, area, state);
|
||||
}
|
||||
|
||||
if self.focused == FocusedArea::GlobalSettings
|
||||
&& let Some(state) = self.global_settings.as_mut()
|
||||
{
|
||||
let area = widgets::popups::global_settings::popup_rect(frame.area(), state);
|
||||
widgets::popups::global_settings::render(frame, area, state);
|
||||
}
|
||||
|
||||
// error toasts stack from the top, each one below the previous
|
||||
let all_errors = error_buffer::peek_all_errors();
|
||||
self.sync_error_effects(&all_errors);
|
||||
@@ -331,7 +344,7 @@ impl App {
|
||||
}
|
||||
|
||||
// drives the slide-in / idle / slide-out state machine for each error toast.
|
||||
// transitions to FadingOut once it's within fly_out_ms of auto-dismiss time
|
||||
// transitions to FadingOut at the configured slide-start time
|
||||
fn render_error_effect(
|
||||
&mut self,
|
||||
frame: &mut Frame,
|
||||
@@ -343,9 +356,13 @@ impl App {
|
||||
use crate::config::theme::THEME;
|
||||
let theme = THEME.as_ref();
|
||||
let bg = theme.background();
|
||||
let fly_out_ms = SETTINGS.ui.error_fly_out_ms as u128;
|
||||
let fly_start_ms = SETTINGS.ui.error_auto_dismiss_ms as u128
|
||||
- fly_out_ms.min(SETTINGS.ui.error_auto_dismiss_ms as u128);
|
||||
let (fly_out_ms, fly_start_ms) = {
|
||||
let settings = SETTINGS.read();
|
||||
(
|
||||
settings.ui.error_fly_out_ms as u128,
|
||||
settings.ui.error_slide_start_ms as u128,
|
||||
)
|
||||
};
|
||||
|
||||
if elapsed_ms >= fly_start_ms {
|
||||
let entry = self
|
||||
@@ -430,15 +447,18 @@ fn render_provider_conflict(frame: &mut Frame, conflict: &super::app::ProviderCo
|
||||
)))
|
||||
});
|
||||
let mut state = ListState::default().with_selected(Some(conflict.selected));
|
||||
let mut block = Block::default()
|
||||
.title(Line::from(format!(" Choose provider for {title} ")))
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BORDER_STYLE.to_border_type())
|
||||
.border_style(Style::default().fg(theme.accent()));
|
||||
if crate::tui::widgets::popups::shortcut_hints_visible(
|
||||
crate::config::settings::ShortcutHintScope::Popups,
|
||||
) {
|
||||
block = block.title_bottom(Line::from(" [j/k] select [Enter] use [Esc] later "));
|
||||
}
|
||||
let list = List::new(items)
|
||||
.block(
|
||||
Block::default()
|
||||
.title(Line::from(format!(" Choose provider for {title} ")))
|
||||
.title_bottom(Line::from(" [j/k] select [Enter] use [Esc] later "))
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BORDER_STYLE.to_border_type())
|
||||
.border_style(Style::default().fg(theme.accent())),
|
||||
)
|
||||
.block(block)
|
||||
.style(Style::default().fg(theme.text()).bg(theme.surface()))
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
|
||||
@@ -26,6 +26,26 @@ fn edited_instance_config_reloads_into_the_ui() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_update_merges_only_confirmed_fields_into_latest_config() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("Merge Runtime");
|
||||
let previous = ui.app.instances_state.selected_instance().unwrap().clone();
|
||||
let mut updated = previous.clone();
|
||||
updated.game_version = "1.21.2".to_owned();
|
||||
updated.memory_max = Some("8G".to_owned());
|
||||
let mut current = previous.clone();
|
||||
current.config_sync_profile = Some("shared".to_owned());
|
||||
current.preferred_account = Some("newer-account".to_owned());
|
||||
|
||||
let merged = merge_instance_settings(&previous, &updated, current);
|
||||
|
||||
assert_eq!(merged.game_version, "1.21.2");
|
||||
assert_eq!(merged.memory_max.as_deref(), Some("8G"));
|
||||
assert_eq!(merged.config_sync_profile.as_deref(), Some("shared"));
|
||||
assert_eq!(merged.preferred_account.as_deref(), Some("newer-account"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn completed_background_instance_is_drained_into_the_ui() {
|
||||
let mut ui = UiHarness::new();
|
||||
@@ -57,6 +77,288 @@ fn completed_background_instance_is_drained_into_the_ui() {
|
||||
assert_eq!(ui.app.mods_state.loaded_for.as_deref(), Some("Pending"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unrelated_background_result_does_not_complete_runtime_update() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("Pending Runtime");
|
||||
ui.app
|
||||
.pending_instance_settings_updates
|
||||
.insert("Pending Runtime".to_owned());
|
||||
let config = ui.app.instances_state.selected_instance().unwrap().clone();
|
||||
PENDING_INSTANCES.lock().unwrap().push(config);
|
||||
|
||||
ui.app.drain_pending_instances();
|
||||
|
||||
assert!(
|
||||
ui.app
|
||||
.pending_instance_settings_updates
|
||||
.contains("Pending Runtime")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pending_runtime_update_blocks_instance_rename() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("Pending Rename");
|
||||
ui.app
|
||||
.pending_instance_settings_updates
|
||||
.insert("Pending Rename".to_owned());
|
||||
|
||||
ui.key(crossterm::event::KeyCode::Char('r'));
|
||||
|
||||
assert!(ui.app.instances_state.renaming.is_none());
|
||||
assert_eq!(
|
||||
crate::feedback::errors::peek_error().map(|error| error.message),
|
||||
Some(RUNTIME_UPDATE_PENDING_MESSAGE.to_owned())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_settings_update_keeps_the_editor_open_and_handles_results() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("Runtime Settings");
|
||||
ui.key(crossterm::event::KeyCode::Char('E'));
|
||||
let state = ui.app.instance_settings.as_mut().unwrap();
|
||||
state.draft.game_version = "1.21.2".to_owned();
|
||||
state.mark_runtime_update_pending();
|
||||
ui.app
|
||||
.pending_instance_settings_updates
|
||||
.insert("Runtime Settings".to_owned());
|
||||
|
||||
ui.key(crossterm::event::KeyCode::Esc);
|
||||
assert!(ui.app.instance_settings.is_none());
|
||||
ui.key(crossterm::event::KeyCode::Char('E'));
|
||||
assert!(
|
||||
ui.app
|
||||
.instance_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.runtime_update_pending_for("Runtime Settings")
|
||||
);
|
||||
|
||||
let mut updated = ui.app.instances_state.selected_instance().unwrap().clone();
|
||||
updated.game_version = "1.21.2".to_owned();
|
||||
ui.app.instance_manager.save(&updated).unwrap();
|
||||
COMPLETED_INSTANCE_SETTINGS_UPDATES
|
||||
.lock()
|
||||
.unwrap()
|
||||
.push(updated);
|
||||
ui.app.drain_completed_instance_settings_updates();
|
||||
|
||||
let state = ui.app.instance_settings.as_ref().unwrap();
|
||||
assert_eq!(state.draft.game_version, "1.21.2");
|
||||
assert!(!state.runtime_update_pending_for("Runtime Settings"));
|
||||
assert!(ui.app.pending_instance_settings_updates.is_empty());
|
||||
|
||||
let state = ui.app.instance_settings.as_mut().unwrap();
|
||||
state.draft.game_version = "1.21.3".to_owned();
|
||||
state.mark_runtime_update_pending();
|
||||
ui.app
|
||||
.pending_instance_settings_updates
|
||||
.insert("Runtime Settings".to_owned());
|
||||
FAILED_INSTANCE_SETTINGS_UPDATES
|
||||
.lock()
|
||||
.unwrap()
|
||||
.push("Runtime Settings".to_owned());
|
||||
ui.app.drain_failed_instance_settings_updates();
|
||||
|
||||
let state = ui.app.instance_settings.as_ref().unwrap();
|
||||
assert_eq!(state.draft.game_version, "1.21.2");
|
||||
assert!(!state.runtime_update_pending_for("Runtime Settings"));
|
||||
assert!(ui.app.pending_instance_settings_updates.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn structural_settings_update_repairs_runtime_before_persisting() {
|
||||
use sha1::{Digest, Sha1};
|
||||
use wiremock::matchers::{method, path};
|
||||
use wiremock::{Mock, MockServer, ResponseTemplate};
|
||||
|
||||
fn sha1(bytes: &[u8]) -> String {
|
||||
format!("{:x}", Sha1::digest(bytes))
|
||||
}
|
||||
|
||||
let _guard = crate::tests::TEST_LOCK
|
||||
.lock()
|
||||
.unwrap_or_else(|error| error.into_inner());
|
||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap();
|
||||
runtime.block_on(async {
|
||||
let server = MockServer::start().await;
|
||||
let client_jar = b"client";
|
||||
let library_jar = b"library";
|
||||
for (endpoint, body) in [
|
||||
("/client.jar", client_jar.as_slice()),
|
||||
("/library.jar", library_jar.as_slice()),
|
||||
] {
|
||||
Mock::given(method("GET"))
|
||||
.and(path(endpoint))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_bytes(body.to_vec()))
|
||||
.expect(1)
|
||||
.mount(&server)
|
||||
.await;
|
||||
}
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/assets.json"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
|
||||
"objects": {}
|
||||
})))
|
||||
.expect(1)
|
||||
.mount(&server)
|
||||
.await;
|
||||
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let instances_dir = temp.path().join("instances");
|
||||
let meta_dir = temp.path().join("meta");
|
||||
let instance_dir = instances_dir.join("Migrating");
|
||||
std::fs::create_dir_all(&instance_dir).unwrap();
|
||||
let manager = InstanceManager::new(&instances_dir, &meta_dir);
|
||||
let mut previous = crate::instance::InstanceConfig {
|
||||
name: "Migrating".to_owned(),
|
||||
game_version: "1.20.1".to_owned(),
|
||||
loader: crate::instance::ModLoader::Vanilla,
|
||||
loader_version: None,
|
||||
created: chrono::Utc::now(),
|
||||
last_played: None,
|
||||
java_path: None,
|
||||
memory_max: None,
|
||||
memory_min: None,
|
||||
jvm_args: Vec::new(),
|
||||
environment: Default::default(),
|
||||
window_mode: Default::default(),
|
||||
inherit_window_mode: false,
|
||||
resolution: None,
|
||||
inherit_resolution: false,
|
||||
preferred_account: None,
|
||||
pre_launch_command: Default::default(),
|
||||
post_exit_command: Default::default(),
|
||||
glfw_path: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
};
|
||||
manager.save(&previous).unwrap();
|
||||
|
||||
let metadata = crate::storage::MetadataPaths::new(&meta_dir);
|
||||
let version_dir = metadata.versions().join("1.21.2");
|
||||
std::fs::create_dir_all(&version_dir).unwrap();
|
||||
std::fs::write(
|
||||
version_dir.join("meta.json"),
|
||||
serde_json::to_vec(&serde_json::json!({
|
||||
"id": "1.21.2",
|
||||
"mainClass": "net.minecraft.client.main.Main",
|
||||
"arguments": { "game": [], "jvm": [] },
|
||||
"assetIndex": {
|
||||
"id": "1.21.2",
|
||||
"url": format!("{}/assets.json", server.uri()),
|
||||
"sha1": "unused"
|
||||
},
|
||||
"downloads": {
|
||||
"client": {
|
||||
"url": format!("{}/client.jar", server.uri()),
|
||||
"sha1": sha1(client_jar),
|
||||
"size": client_jar.len()
|
||||
}
|
||||
},
|
||||
"libraries": [{
|
||||
"name": "example:test:1",
|
||||
"downloads": {
|
||||
"artifact": {
|
||||
"url": format!("{}/library.jar", server.uri()),
|
||||
"path": "example/test/1/test-1.jar",
|
||||
"sha1": sha1(library_jar),
|
||||
"size": library_jar.len()
|
||||
}
|
||||
}
|
||||
}],
|
||||
"javaVersion": { "majorVersion": 21 }
|
||||
}))
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut updated = previous.clone();
|
||||
updated.game_version = "1.21.2".to_owned();
|
||||
updated.memory_max = Some("4G".to_owned());
|
||||
let applied = apply_instance_settings_update(&manager, &previous, updated)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(applied.game_version, "1.21.2");
|
||||
previous = manager.load_one("Migrating").unwrap();
|
||||
assert_eq!(previous.game_version, "1.21.2");
|
||||
assert_eq!(previous.memory_max.as_deref(), Some("4G"));
|
||||
assert_eq!(
|
||||
std::fs::read(version_dir.join("1.21.2.jar")).unwrap(),
|
||||
client_jar
|
||||
);
|
||||
assert_eq!(
|
||||
std::fs::read(metadata.libraries().join("example/test/1/test-1.jar")).unwrap(),
|
||||
library_jar
|
||||
);
|
||||
assert!(metadata.assets().join("indexes/1.21.2.json").exists());
|
||||
crate::feedback::progress::clear();
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failed_structural_settings_update_keeps_previous_config() {
|
||||
let _guard = crate::tests::TEST_LOCK
|
||||
.lock()
|
||||
.unwrap_or_else(|error| error.into_inner());
|
||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap();
|
||||
runtime.block_on(async {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let instances_dir = temp.path().join("instances");
|
||||
let meta_dir = temp.path().join("meta");
|
||||
std::fs::create_dir_all(instances_dir.join("Stable")).unwrap();
|
||||
let manager = InstanceManager::new(&instances_dir, &meta_dir);
|
||||
let previous = crate::instance::InstanceConfig {
|
||||
name: "Stable".to_owned(),
|
||||
game_version: "1.20.1".to_owned(),
|
||||
loader: crate::instance::ModLoader::Vanilla,
|
||||
loader_version: None,
|
||||
created: chrono::Utc::now(),
|
||||
last_played: None,
|
||||
java_path: None,
|
||||
memory_max: None,
|
||||
memory_min: None,
|
||||
jvm_args: Vec::new(),
|
||||
environment: Default::default(),
|
||||
window_mode: Default::default(),
|
||||
inherit_window_mode: false,
|
||||
resolution: None,
|
||||
inherit_resolution: false,
|
||||
preferred_account: None,
|
||||
pre_launch_command: Default::default(),
|
||||
post_exit_command: Default::default(),
|
||||
glfw_path: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
};
|
||||
manager.save(&previous).unwrap();
|
||||
|
||||
let metadata = crate::storage::MetadataPaths::new(&meta_dir);
|
||||
let version_dir = metadata.versions().join("missing-runtime");
|
||||
std::fs::create_dir_all(&version_dir).unwrap();
|
||||
std::fs::write(version_dir.join("meta.json"), b"not json").unwrap();
|
||||
let mut updated = previous.clone();
|
||||
updated.game_version = "missing-runtime".to_owned();
|
||||
|
||||
assert!(
|
||||
apply_instance_settings_update(&manager, &previous, updated)
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(manager.load_one("Stable").unwrap().game_version, "1.20.1");
|
||||
crate::feedback::progress::clear();
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn editor_kind_is_detected_from_the_executable_name() {
|
||||
assert!(editor_runs_in_terminal("/usr/bin/nvim"));
|
||||
|
||||
+493
-8
@@ -54,9 +54,6 @@ fn escape_returns_through_nested_sections() {
|
||||
assert_eq!(ui.app.focused, FocusedArea::Instances);
|
||||
|
||||
ui.app.focused = FocusedArea::Settings;
|
||||
ui.key(KeyCode::Char('a'));
|
||||
ui.key(KeyCode::Esc);
|
||||
assert_eq!(ui.app.focused, FocusedArea::Settings);
|
||||
ui.key(KeyCode::Esc);
|
||||
assert_eq!(ui.app.focused, FocusedArea::Instances);
|
||||
|
||||
@@ -562,7 +559,13 @@ fn deleting_a_required_library_warns_but_can_continue() {
|
||||
#[test]
|
||||
fn confirmed_account_delete_updates_the_account_panel() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("preferred-account-test");
|
||||
ui.add_account("Player");
|
||||
ui.app.instances_state.instances[0].preferred_account = Some("Player".to_owned());
|
||||
ui.app
|
||||
.instance_manager
|
||||
.save(&ui.app.instances_state.instances[0])
|
||||
.unwrap();
|
||||
ui.app.focused = FocusedArea::Account;
|
||||
|
||||
ui.key(KeyCode::Char('d'));
|
||||
@@ -571,22 +574,504 @@ fn confirmed_account_delete_updates_the_account_panel() {
|
||||
assert_eq!(ui.app.focused, FocusedArea::Account);
|
||||
assert!(ui.app.account_state.store.accounts.is_empty());
|
||||
assert_eq!(ui.app.account_state.list_state.selected, None);
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.unwrap()
|
||||
.preferred_account,
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instance_manager
|
||||
.load_one("preferred-account-test")
|
||||
.unwrap()
|
||||
.preferred_account,
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settings_profile_can_be_created_from_key_events() {
|
||||
fn settings_panel_routes_legacy_edit_keys_to_tui_popups() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("settings-test");
|
||||
ui.app.focused = FocusedArea::Settings;
|
||||
|
||||
ui.key(KeyCode::Right);
|
||||
ui.key(KeyCode::Char('e'));
|
||||
assert_eq!(ui.app.focused, FocusedArea::InstanceSettings);
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("Instance Settings · settings-test"));
|
||||
assert!(!ui.screen().contains("Instance Settings *"));
|
||||
assert!(ui.screen().contains("settings-test"));
|
||||
assert!(ui.screen().contains("Game version"));
|
||||
assert!(ui.screen().contains("Memory min"));
|
||||
assert!(ui.screen().contains("Desktop"));
|
||||
assert!(ui.screen().contains('◆'));
|
||||
assert!(!ui.screen().contains('█'));
|
||||
assert!(!ui.screen().contains("● enabled"));
|
||||
assert!(!ui.screen().contains("Integration"));
|
||||
assert!(!ui.screen().contains('▰'));
|
||||
ui.key(KeyCode::Down);
|
||||
ui.key(KeyCode::Enter);
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("Mod Loader · settings-test"));
|
||||
assert!(ui.screen().contains("Fabric"));
|
||||
assert!(ui.screen().contains("Forge"));
|
||||
ui.key(KeyCode::Esc);
|
||||
for _ in 0..6 {
|
||||
ui.key(KeyCode::Down);
|
||||
}
|
||||
ui.key(KeyCode::Enter);
|
||||
for character in "-Xfoo".chars() {
|
||||
ui.key(KeyCode::Char(character));
|
||||
}
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("-Xfoo"));
|
||||
ui.key(KeyCode::Enter);
|
||||
assert_eq!(ui.app.focused, FocusedArea::InstanceSettings);
|
||||
assert_eq!(
|
||||
ui.app.instances_state.selected_instance().unwrap().jvm_args,
|
||||
["-Xfoo"]
|
||||
);
|
||||
ui.key(KeyCode::Esc);
|
||||
assert_eq!(ui.app.focused, FocusedArea::Settings);
|
||||
|
||||
ui.key(KeyCode::Char('g'));
|
||||
assert_eq!(ui.app.focused, FocusedArea::GlobalSettings);
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("Launcher Settings"));
|
||||
assert!(ui.screen().contains("Appearance"));
|
||||
assert!(ui.screen().contains("Image rendering"));
|
||||
assert!(ui.screen().contains("Memory max"));
|
||||
assert!(ui.screen().contains('◆'));
|
||||
assert!(!ui.screen().contains('█'));
|
||||
assert!(!ui.screen().contains('▰'));
|
||||
ui.key(KeyCode::Enter);
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("Theme"));
|
||||
ui.key(KeyCode::Esc);
|
||||
ui.key(KeyCode::Esc);
|
||||
assert_eq!(ui.app.focused, FocusedArea::Settings);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn launcher_settings_expand_to_storage_and_confirm_cache_cleanup() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("global-settings-test");
|
||||
ui.key(KeyCode::Char('G'));
|
||||
|
||||
for _ in 0..18 {
|
||||
ui.key(KeyCode::Char('j'));
|
||||
}
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("Storage"));
|
||||
assert!(ui.screen().contains("Instances"));
|
||||
assert!(ui.screen().contains("Metadata"));
|
||||
|
||||
for _ in 18..24 {
|
||||
ui.key(KeyCode::Char('j'));
|
||||
}
|
||||
ui.key(KeyCode::Enter);
|
||||
assert_eq!(ui.app.focused, FocusedArea::ConfirmDelete);
|
||||
assert!(matches!(
|
||||
confirm::pending_target(),
|
||||
Some(confirm::ConfirmTarget::LauncherCache)
|
||||
));
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("Clear caches"));
|
||||
ui.key(KeyCode::Esc);
|
||||
assert_eq!(ui.app.focused, FocusedArea::GlobalSettings);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_settings_use_the_shared_confirmation_popup() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("runtime-test");
|
||||
ui.app.focused = FocusedArea::Settings;
|
||||
ui.key(KeyCode::Right);
|
||||
ui.key(KeyCode::Char('e'));
|
||||
ui.app
|
||||
.instance_settings
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.draft
|
||||
.game_version = "1.21.2".to_owned();
|
||||
|
||||
for _ in 0..5 {
|
||||
ui.key(KeyCode::Char('j'));
|
||||
}
|
||||
ui.key(KeyCode::Char('l'));
|
||||
|
||||
assert_eq!(ui.app.focused, FocusedArea::ConfirmDelete);
|
||||
assert!(matches!(
|
||||
confirm::pending_target(),
|
||||
Some(confirm::ConfirmTarget::InstanceRuntime { name, .. }) if name == "runtime-test"
|
||||
));
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("Change runtime"));
|
||||
assert!(!ui.screen().contains("Target:"));
|
||||
assert!(
|
||||
ui.screen()
|
||||
.contains("Some installed mods may be incompatible")
|
||||
);
|
||||
assert!(!ui.screen().contains("incompatible."));
|
||||
assert!(
|
||||
!crate::feedback::errors::ERROR_EVENTS
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|event| {
|
||||
event.level == tracing::Level::WARN
|
||||
&& event.message == "Some installed mods may be incompatible"
|
||||
})
|
||||
);
|
||||
|
||||
ui.key(KeyCode::Esc);
|
||||
assert_eq!(ui.app.focused, FocusedArea::InstanceSettings);
|
||||
ui.key(KeyCode::Esc);
|
||||
assert_eq!(ui.app.focused, FocusedArea::Settings);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn jvm_arguments_use_the_same_editor_controls_as_environment() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("jvm-clear-test");
|
||||
ui.key(KeyCode::Char('E'));
|
||||
ui.app.instance_settings.as_mut().unwrap().draft.jvm_args =
|
||||
vec!["-XX:+UseG1GC".to_owned(), "-Xss1M".to_owned()];
|
||||
|
||||
for _ in 0..7 {
|
||||
ui.key(KeyCode::Char('j'));
|
||||
}
|
||||
ui.key(KeyCode::Char('d'));
|
||||
|
||||
assert_eq!(ui.app.focused, FocusedArea::InstanceSettings);
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instance_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.draft
|
||||
.jvm_args
|
||||
.len(),
|
||||
2
|
||||
);
|
||||
ui.draw();
|
||||
assert!(!ui.screen().contains("[d] clear"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enabling_a_different_automatic_java_requires_confirmation() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("java-auto-test");
|
||||
ui.key(KeyCode::Char('E'));
|
||||
ui.app.instance_settings.as_mut().unwrap().draft.java_path = Some("/custom/java".to_owned());
|
||||
|
||||
for _ in 0..4 {
|
||||
ui.key(KeyCode::Char('j'));
|
||||
}
|
||||
ui.key(KeyCode::Char('a'));
|
||||
for character in "qConfig".chars() {
|
||||
|
||||
assert_eq!(ui.app.focused, FocusedArea::ConfirmDelete);
|
||||
assert!(matches!(
|
||||
confirm::pending_target(),
|
||||
Some(confirm::ConfirmTarget::AutomaticSelection {
|
||||
setting: confirm::AutomaticSetting::Java,
|
||||
instance: Some(name),
|
||||
..
|
||||
}) if name == "java-auto-test"
|
||||
));
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("Enable automatic Java"));
|
||||
assert!(
|
||||
ui.screen()
|
||||
.contains("Use the automatically selected Java runtime")
|
||||
);
|
||||
assert!(!ui.screen().contains("/custom/java"));
|
||||
|
||||
ui.key(KeyCode::Esc);
|
||||
assert_eq!(ui.app.focused, FocusedArea::InstanceSettings);
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instance_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.draft
|
||||
.java_path
|
||||
.as_deref(),
|
||||
Some("/custom/java")
|
||||
);
|
||||
ui.key(KeyCode::Char('a'));
|
||||
|
||||
ui.key(KeyCode::Enter);
|
||||
|
||||
assert_eq!(ui.app.focused, FocusedArea::InstanceSettings);
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.unwrap()
|
||||
.java_path,
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enabling_a_different_automatic_account_requires_confirmation() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("account-auto-test");
|
||||
ui.add_account("Active");
|
||||
ui.app
|
||||
.account_state
|
||||
.store
|
||||
.accounts
|
||||
.push(crate::auth::Account {
|
||||
uuid: "preferred".to_owned(),
|
||||
username: "Preferred".to_owned(),
|
||||
account_type: crate::auth::AccountType::Microsoft,
|
||||
active: false,
|
||||
refresh_token: Some("refresh".to_owned()),
|
||||
cached_mc_token: None,
|
||||
cached_mc_token_expires_at: None,
|
||||
});
|
||||
ui.app.instances_state.instances[0].preferred_account = Some("preferred".to_owned());
|
||||
ui.app
|
||||
.instance_manager
|
||||
.save(&ui.app.instances_state.instances[0])
|
||||
.unwrap();
|
||||
ui.key(KeyCode::Char('E'));
|
||||
for _ in 0..3 {
|
||||
ui.key(KeyCode::Char('j'));
|
||||
}
|
||||
|
||||
ui.key(KeyCode::Char('a'));
|
||||
|
||||
assert_eq!(ui.app.focused, FocusedArea::ConfirmDelete);
|
||||
assert!(matches!(
|
||||
confirm::pending_target(),
|
||||
Some(confirm::ConfirmTarget::AutomaticSelection {
|
||||
setting: confirm::AutomaticSetting::Account,
|
||||
instance: Some(name),
|
||||
}) if name == "account-auto-test"
|
||||
));
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("Enable automatic account"));
|
||||
assert!(ui.screen().contains("Use the currently active account"));
|
||||
assert!(!ui.screen().contains("Preferred → Active"));
|
||||
|
||||
ui.key(KeyCode::Esc);
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instance_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.draft
|
||||
.preferred_account
|
||||
.as_deref(),
|
||||
Some("preferred")
|
||||
);
|
||||
ui.key(KeyCode::Char('a'));
|
||||
ui.key(KeyCode::Enter);
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.unwrap()
|
||||
.preferred_account,
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn instance_settings_validation_errors_use_the_toast_buffer() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("toast-test");
|
||||
ui.key(KeyCode::Char('E'));
|
||||
let state = ui.app.instance_settings.as_mut().unwrap();
|
||||
state.draft.loader = crate::instance::ModLoader::Vanilla;
|
||||
state.draft.loader_version = None;
|
||||
|
||||
ui.key(KeyCode::Char('j'));
|
||||
ui.key(KeyCode::Char('j'));
|
||||
ui.key(KeyCode::Enter);
|
||||
|
||||
assert!(
|
||||
crate::feedback::errors::ERROR_EVENTS
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|error| error.message == "Vanilla does not use a loader version")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enabling_an_empty_launch_hook_uses_a_warning_toast() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("empty-hook-test");
|
||||
ui.key(KeyCode::Char('E'));
|
||||
for _ in 0..13 {
|
||||
ui.key(KeyCode::Char('j'));
|
||||
}
|
||||
|
||||
ui.key(KeyCode::Char(' '));
|
||||
|
||||
assert!(
|
||||
crate::feedback::errors::ERROR_EVENTS
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|event| {
|
||||
event.level == tracing::Level::WARN
|
||||
&& event.message == "Enter a pre-launch command before enabling it"
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settings_use_java_memory_and_resolution_controls() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("controls-test");
|
||||
ui.key(KeyCode::Char('E'));
|
||||
|
||||
for _ in 0..4 {
|
||||
ui.key(KeyCode::Char('j'));
|
||||
}
|
||||
ui.key(KeyCode::Enter);
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("Java Runtime"));
|
||||
assert!(!ui.screen().contains("auto"));
|
||||
assert!(!ui.screen().contains("custom"));
|
||||
assert!(!ui.screen().contains("Automatic"));
|
||||
assert!(!ui.screen().contains("Custom path"));
|
||||
assert!(!ui.screen().contains("Manual"));
|
||||
ui.key(KeyCode::Esc);
|
||||
|
||||
ui.app.instance_settings.as_mut().unwrap().draft.memory_min = Some("512M".to_owned());
|
||||
ui.key(KeyCode::Char('j'));
|
||||
ui.key(KeyCode::Char('l'));
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instance_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.draft
|
||||
.memory_min
|
||||
.as_deref(),
|
||||
Some("1G")
|
||||
);
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.unwrap()
|
||||
.memory_min
|
||||
.as_deref(),
|
||||
Some("1G")
|
||||
);
|
||||
|
||||
for _ in 0..6 {
|
||||
ui.key(KeyCode::Char('j'));
|
||||
}
|
||||
ui.key(KeyCode::Enter);
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("Resolution"));
|
||||
assert!(ui.screen().contains("1920x1080"));
|
||||
assert!(!ui.screen().contains("Preset"));
|
||||
assert!(!ui.screen().contains("Inherit"));
|
||||
assert!(!ui.screen().contains("custom"));
|
||||
ui.key(KeyCode::Esc);
|
||||
ui.key(KeyCode::Esc);
|
||||
|
||||
ui.key(KeyCode::Char('G'));
|
||||
for _ in 0..6 {
|
||||
ui.key(KeyCode::Char('j'));
|
||||
}
|
||||
ui.key(KeyCode::Enter);
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("Java Runtime"));
|
||||
assert!(!ui.screen().contains("auto"));
|
||||
assert!(!ui.screen().contains("Automatic"));
|
||||
ui.key(KeyCode::Esc);
|
||||
ui.key(KeyCode::Esc);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn instance_launch_options_autosave_through_the_editor() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("launch-options-test");
|
||||
ui.add_account("Player");
|
||||
ui.key(KeyCode::Char('E'));
|
||||
|
||||
for _ in 0..3 {
|
||||
ui.key(KeyCode::Char('j'));
|
||||
}
|
||||
ui.key(KeyCode::Enter);
|
||||
ui.key(KeyCode::Enter);
|
||||
|
||||
for _ in 0..5 {
|
||||
ui.key(KeyCode::Char('j'));
|
||||
}
|
||||
ui.key(KeyCode::Enter);
|
||||
for character in "MESA_LOADER_DRIVER_OVERRIDE=zink".chars() {
|
||||
ui.key(KeyCode::Char(character));
|
||||
}
|
||||
ui.key(KeyCode::Enter);
|
||||
|
||||
assert!(!ui.app.exit);
|
||||
assert_eq!(ui.app.focused, FocusedArea::Settings);
|
||||
assert_eq!(ui.app.settings_state.profiles, ["qConfig"]);
|
||||
ui.key(KeyCode::Char('j'));
|
||||
ui.key(KeyCode::Char('j'));
|
||||
ui.key(KeyCode::Enter);
|
||||
|
||||
ui.key(KeyCode::Char('k'));
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("Java"));
|
||||
ui.key(KeyCode::Char('c'));
|
||||
for character in "/opt/lib/libglfw.so.3".chars() {
|
||||
ui.key(KeyCode::Char(character));
|
||||
}
|
||||
ui.key(KeyCode::Enter);
|
||||
|
||||
let saved = ui
|
||||
.app
|
||||
.instance_manager
|
||||
.load_one("launch-options-test")
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
saved
|
||||
.environment
|
||||
.get("MESA_LOADER_DRIVER_OVERRIDE")
|
||||
.map(String::as_str),
|
||||
Some("zink")
|
||||
);
|
||||
assert_eq!(saved.window_mode, crate::instance::WindowMode::Fullscreen);
|
||||
assert_eq!(saved.preferred_account.as_deref(), Some("Player"));
|
||||
assert_eq!(saved.glfw_path.as_deref(), Some("/opt/lib/libglfw.so.3"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settings_panel_keeps_direct_profile_management() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("profile-test");
|
||||
ui.app.focused = FocusedArea::Settings;
|
||||
|
||||
ui.key(KeyCode::Char('a'));
|
||||
for character in "main".chars() {
|
||||
ui.key(KeyCode::Char(character));
|
||||
}
|
||||
ui.key(KeyCode::Enter);
|
||||
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.unwrap()
|
||||
.config_sync_profile
|
||||
.as_deref(),
|
||||
Some("main")
|
||||
);
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("main"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -26,6 +26,18 @@ impl UiHarness {
|
||||
pub fn new() -> Self {
|
||||
let guard = TEST_LOCK.lock().unwrap_or_else(|error| error.into_inner());
|
||||
widgets::popups::confirm::clear_pending();
|
||||
crate::tui::app::FAILED_INSTANCE_SETTINGS_UPDATES
|
||||
.lock()
|
||||
.unwrap_or_else(|error| error.into_inner())
|
||||
.clear();
|
||||
crate::tui::app::COMPLETED_INSTANCE_SETTINGS_UPDATES
|
||||
.lock()
|
||||
.unwrap_or_else(|error| error.into_inner())
|
||||
.clear();
|
||||
crate::tui::app::PENDING_INSTANCES
|
||||
.lock()
|
||||
.unwrap_or_else(|error| error.into_inner())
|
||||
.clear();
|
||||
widgets::popups::new_instance::reset_for_test();
|
||||
widgets::popups::import_modpack::reset_for_test();
|
||||
crate::feedback::errors::ERROR_EVENTS
|
||||
@@ -83,7 +95,11 @@ impl UiHarness {
|
||||
logs_state: widgets::logs_viewer::LogsState::default(),
|
||||
account_state,
|
||||
settings_state: widgets::settings::SettingsState::new(meta_dir),
|
||||
instance_settings: None,
|
||||
pending_instance_settings_updates: Default::default(),
|
||||
global_settings: None,
|
||||
picker,
|
||||
detected_image_protocol: ratatui_image::picker::ProtocolType::Halfblocks,
|
||||
instance_manager,
|
||||
log_overlay_scroll: 0,
|
||||
log_overlay_max_scroll: 0,
|
||||
@@ -127,7 +143,15 @@ impl UiHarness {
|
||||
memory_max: None,
|
||||
memory_min: None,
|
||||
jvm_args: Vec::new(),
|
||||
environment: Default::default(),
|
||||
window_mode: Default::default(),
|
||||
inherit_window_mode: false,
|
||||
resolution: None,
|
||||
inherit_resolution: false,
|
||||
preferred_account: None,
|
||||
pre_launch_command: Default::default(),
|
||||
post_exit_command: Default::default(),
|
||||
glfw_path: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
};
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ expression: ui.screen()
|
||||
"│ ││ │"
|
||||
"│ │╰[l] launch [⏎] content [Shift+⏎] open dir [Esc] kill [a] add [m] modpacks╯"
|
||||
"│ │╭Accounts─────────╮╭Settings───────────────────────────╮╭Overview──────────────╮"
|
||||
"│ ││No accounts. ││▸ instance default ││Ready │"
|
||||
"│ ││No accounts. ││No instance selected. ││Ready │"
|
||||
"│ ││ ││ ││ │"
|
||||
"│ ││ ││ ││ │"
|
||||
"╰──────────────────╯╰─────────────────╯╰───────────────────────────────────╯╰──────────────────────╯"
|
||||
+1
-1
@@ -28,7 +28,7 @@ expression: ui.screen()
|
||||
"│ ││ │"
|
||||
"│ │╰[l] launch [⏎] content [Shift+⏎] open dir [Esc] kill [a] add [m] modpacks╯"
|
||||
"│ │╭Accounts─────────╮╭Settings───────────────────────────╮╭Overview──────────────╮"
|
||||
"│ ││No accounts. ││▸ instance default ││Ready │"
|
||||
"│ ││No accounts. ││No instance selected. ││Ready │"
|
||||
"│ ││ ││ ││ │"
|
||||
"│ ││ ││ ││ │"
|
||||
"╰──────────────────╯╰─────────────────╯╰───────────────────────────────────╯╰──────────────────────╯"
|
||||
@@ -43,7 +43,15 @@ fn instance(name: &str, version: &str) -> InstanceConfig {
|
||||
memory_max: None,
|
||||
memory_min: None,
|
||||
jvm_args: Vec::new(),
|
||||
environment: Default::default(),
|
||||
window_mode: Default::default(),
|
||||
inherit_window_mode: false,
|
||||
resolution: None,
|
||||
inherit_resolution: false,
|
||||
preferred_account: None,
|
||||
pre_launch_command: Default::default(),
|
||||
post_exit_command: Default::default(),
|
||||
glfw_path: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
}
|
||||
|
||||
@@ -47,7 +47,15 @@ fn synthetic_instance(name: &str) -> InstanceConfig {
|
||||
memory_max: None,
|
||||
memory_min: None,
|
||||
jvm_args: vec![],
|
||||
environment: Default::default(),
|
||||
window_mode: Default::default(),
|
||||
inherit_window_mode: false,
|
||||
resolution: None,
|
||||
inherit_resolution: false,
|
||||
preferred_account: None,
|
||||
pre_launch_command: Default::default(),
|
||||
post_exit_command: Default::default(),
|
||||
glfw_path: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
}
|
||||
|
||||
@@ -11,10 +11,22 @@ fn frame() -> Rect {
|
||||
|
||||
#[test]
|
||||
fn returns_none_after_dismiss_timeout() {
|
||||
let past_dismiss = SETTINGS.ui.error_auto_dismiss_ms as u128 + 1;
|
||||
let past_dismiss = SETTINGS.read().ui.error_auto_dismiss_ms as u128 + 1;
|
||||
assert!(popup_area(frame(), "msg", 0, past_dismiss).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_none_after_slide_out_finishes() {
|
||||
let settings = SETTINGS.read();
|
||||
let after_slide = settings
|
||||
.ui
|
||||
.error_slide_start_ms
|
||||
.saturating_add(settings.ui.error_fly_out_ms) as u128;
|
||||
drop(settings);
|
||||
|
||||
assert!(popup_area(frame(), "msg", 0, after_slide).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_some_inside_dismiss_window() {
|
||||
assert!(popup_area(frame(), "msg", 0, 0).is_some());
|
||||
|
||||
@@ -8,7 +8,11 @@ use super::{
|
||||
|
||||
#[test]
|
||||
fn fitted_keybinds_use_terminal_width_and_omit_overflow() {
|
||||
let line = keybind_line_fitted(&[("⏎", " select"), ("a", " add")], 10);
|
||||
let line = keybind_line_fitted(
|
||||
crate::config::settings::ShortcutHintScope::Accounts,
|
||||
&[("⏎", " select"), ("a", " add")],
|
||||
10,
|
||||
);
|
||||
|
||||
assert_eq!(line.width(), 10);
|
||||
assert_eq!(line.to_string(), "[⏎] select");
|
||||
|
||||
@@ -17,3 +17,15 @@ fn removing_selected_last_profile_clamps_selection() {
|
||||
assert_eq!(state.active_profile, None);
|
||||
assert_eq!(state.list_state.selected, Some(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn info_pane_does_not_bind_desktop_toggle() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let mut state = SettingsState::new(tmp.path().to_path_buf());
|
||||
state.pane = SettingsPane::Info;
|
||||
|
||||
assert!(matches!(
|
||||
handle_key(&KeyEvent::from(KeyCode::Char('d')), &mut state, None),
|
||||
SettingsAction::None
|
||||
));
|
||||
}
|
||||
@@ -225,6 +225,7 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut A
|
||||
|
||||
let keybind_line = if focused == FocusedArea::Account {
|
||||
Some(super::popups::keybind_line_fitted(
|
||||
crate::config::settings::ShortcutHintScope::Accounts,
|
||||
&[
|
||||
("⏎", " select"),
|
||||
("a", " add"),
|
||||
|
||||
@@ -138,6 +138,7 @@ pub(crate) fn spawn_provider_search(
|
||||
search_provider(
|
||||
registry.get("modrinth"),
|
||||
crate::config::SETTINGS
|
||||
.read()
|
||||
.content
|
||||
.discovery_provider_enabled("modrinth"),
|
||||
&target,
|
||||
@@ -148,6 +149,7 @@ pub(crate) fn spawn_provider_search(
|
||||
search_provider(
|
||||
registry.get("curseforge"),
|
||||
crate::config::SETTINGS
|
||||
.read()
|
||||
.content
|
||||
.discovery_provider_enabled("curseforge"),
|
||||
&target,
|
||||
@@ -177,7 +179,7 @@ pub(crate) fn spawn_provider_search(
|
||||
}
|
||||
let mut merged = merge_provider_results(
|
||||
pages,
|
||||
crate::config::SETTINGS.content.preferred_provider(),
|
||||
crate::config::SETTINGS.read().content.preferred_provider(),
|
||||
known_projects,
|
||||
);
|
||||
refresh_source_installed_versions(&mut merged.sources, &target);
|
||||
@@ -795,7 +797,11 @@ impl DiscoveryState {
|
||||
installed_path: Option<PathBuf>,
|
||||
target_world: Option<(String, PathBuf)>,
|
||||
) -> Option<VersionsRequest> {
|
||||
let preferred = crate::config::SETTINGS.content.preferred_provider();
|
||||
let preferred = crate::config::SETTINGS
|
||||
.read()
|
||||
.content
|
||||
.preferred_provider()
|
||||
.to_owned();
|
||||
sources.sort_by_key(|source| source.provider != preferred);
|
||||
let source = sources.first()?.clone();
|
||||
self.next_action_request_id = self.next_action_request_id.wrapping_add(1);
|
||||
|
||||
@@ -542,7 +542,7 @@ impl ContentListState {
|
||||
|
||||
let use_image_protocol =
|
||||
picker.protocol_type() != ratatui_image::picker::ProtocolType::Halfblocks;
|
||||
let use_quadrants = crate::config::SETTINGS.ui.image_protocol
|
||||
let use_quadrants = crate::config::SETTINGS.read().ui.image_protocol
|
||||
== crate::config::settings::ImageProtocol::Quadrants;
|
||||
if !use_image_protocol {
|
||||
self.image_protocols.clear();
|
||||
@@ -1685,10 +1685,7 @@ pub fn render(
|
||||
theme.success()
|
||||
}
|
||||
});
|
||||
let title_suffix_style = Style::default()
|
||||
.fg(theme.background())
|
||||
.bg(title_suffix_color)
|
||||
.add_modifier(Modifier::BOLD);
|
||||
let title_suffix_style = crate::tui::widgets::status_badge_style(title_suffix_color);
|
||||
let footer_label_style = Style::default().fg(if world_details.is_some() {
|
||||
theme.text_dim()
|
||||
} else {
|
||||
|
||||
@@ -248,10 +248,7 @@ pub fn render(
|
||||
let mut content_titles = vec![
|
||||
Span::styled(
|
||||
mode_label(mode),
|
||||
Style::default()
|
||||
.fg(theme.background())
|
||||
.bg(mode_background)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
crate::tui::widgets::status_badge_style(mode_background),
|
||||
),
|
||||
Span::raw(" "),
|
||||
];
|
||||
@@ -458,6 +455,11 @@ pub fn render(
|
||||
}
|
||||
// The main panel footer stays on its border; lower-priority hints are omitted when narrow.
|
||||
block = block.title_bottom(crate::tui::widgets::popups::keybind_line_fitted(
|
||||
if focused == FocusedArea::Instances {
|
||||
crate::config::settings::ShortcutHintScope::Instances
|
||||
} else {
|
||||
crate::config::settings::ShortcutHintScope::Content
|
||||
},
|
||||
&keybinds,
|
||||
area.width.saturating_sub(2),
|
||||
));
|
||||
@@ -504,7 +506,10 @@ pub fn render(
|
||||
}
|
||||
let loading_text = format!(
|
||||
"Searching {}...",
|
||||
crate::config::SETTINGS.content.discovery_provider_label()
|
||||
crate::config::SETTINGS
|
||||
.read()
|
||||
.content
|
||||
.discovery_provider_label()
|
||||
);
|
||||
render_discovery(
|
||||
frame,
|
||||
@@ -671,7 +676,10 @@ fn render_downloadable(
|
||||
if mode == ContentMode::Discover {
|
||||
let loading_text = format!(
|
||||
"Searching {}...",
|
||||
crate::config::SETTINGS.content.discovery_provider_label()
|
||||
crate::config::SETTINGS
|
||||
.read()
|
||||
.content
|
||||
.discovery_provider_label()
|
||||
);
|
||||
render_discovery(
|
||||
frame,
|
||||
@@ -992,7 +1000,7 @@ pub(crate) fn render_version_popup(
|
||||
.style(Style::default().fg(THEME.as_ref().text_dim()))
|
||||
.render(area, buffer);
|
||||
} else {
|
||||
crate::tui::widgets::popups::new_instance::render_select_list(
|
||||
crate::tui::widgets::popups::select_list::render(
|
||||
items.clone(),
|
||||
selected,
|
||||
area,
|
||||
|
||||
@@ -36,12 +36,18 @@ static MODPACK_UPDATE_SLOTS: LazyLock<Arc<tokio::sync::Semaphore>> =
|
||||
LazyLock::new(|| Arc::new(tokio::sync::Semaphore::new(4)));
|
||||
|
||||
pub fn spawn_modpack_update_checks(instances: &[InstanceConfig]) {
|
||||
if !crate::config::SETTINGS.read().general.check_modpack_updates {
|
||||
return;
|
||||
}
|
||||
for instance in instances {
|
||||
spawn_modpack_update_check(instance);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn_modpack_update_check(instance: &InstanceConfig) {
|
||||
if !crate::config::SETTINGS.read().general.check_modpack_updates {
|
||||
return;
|
||||
}
|
||||
let Some(source) = instance.modpack_source.clone() else {
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -509,33 +509,34 @@ fn render_list(frame: &mut Frame, area: Rect, state: &mut LogsState, is_focused:
|
||||
})
|
||||
.collect();
|
||||
let search = &state.search;
|
||||
let success = theme.success();
|
||||
let accent = theme.accent();
|
||||
let text = theme.text();
|
||||
let background = theme.background();
|
||||
let stripe = theme.stripe();
|
||||
|
||||
let builder = ListBuilder::new(move |context| {
|
||||
let (name, is_live) = &entries_snapshot[context.index];
|
||||
let show_selected = list_focused && context.is_selected;
|
||||
|
||||
let style = if *is_live && show_selected {
|
||||
Style::default()
|
||||
.fg(theme.success())
|
||||
.add_modifier(Modifier::BOLD)
|
||||
Style::default().fg(success).add_modifier(Modifier::BOLD)
|
||||
} else if *is_live {
|
||||
Style::default().fg(theme.success())
|
||||
Style::default().fg(success)
|
||||
} else if show_selected {
|
||||
Style::default()
|
||||
.fg(theme.accent())
|
||||
.add_modifier(Modifier::BOLD)
|
||||
Style::default().fg(accent).add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
Style::default().fg(theme.text())
|
||||
Style::default().fg(text)
|
||||
};
|
||||
|
||||
let bg = if context.index % 2 == 0 {
|
||||
theme.background()
|
||||
background
|
||||
} else {
|
||||
theme.stripe()
|
||||
stripe
|
||||
};
|
||||
|
||||
let selector = if show_selected {
|
||||
Span::styled("\u{258c} ", Style::default().fg(theme.accent()))
|
||||
Span::styled("\u{258c} ", Style::default().fg(accent))
|
||||
} else {
|
||||
Span::raw(" ")
|
||||
};
|
||||
|
||||
@@ -1651,7 +1651,7 @@ fn render_image(
|
||||
width: area.width,
|
||||
height: full_height,
|
||||
protocol: picker.protocol_type(),
|
||||
mode: crate::config::SETTINGS.ui.image_protocol,
|
||||
mode: crate::config::SETTINGS.read().ui.image_protocol,
|
||||
};
|
||||
if image
|
||||
.prepared
|
||||
|
||||
+12
-1
@@ -6,7 +6,7 @@
|
||||
use crate::config::theme::THEME;
|
||||
use crossterm::event::KeyEvent;
|
||||
use ratatui::{
|
||||
style::Style,
|
||||
style::{Color, Modifier, Style},
|
||||
text::{Line, Span},
|
||||
};
|
||||
|
||||
@@ -38,6 +38,17 @@ pub fn styled_title(title: &str, highlight: bool) -> Line<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn status_badge_style(color: Color) -> Style {
|
||||
Style::default()
|
||||
.fg(THEME.as_ref().background())
|
||||
.bg(color)
|
||||
.add_modifier(Modifier::BOLD)
|
||||
}
|
||||
|
||||
pub(crate) fn status_badge(label: impl Into<String>, color: Color) -> Span<'static> {
|
||||
Span::styled(format!(" {} ", label.into()), status_badge_style(color))
|
||||
}
|
||||
|
||||
pub trait WidgetKey {
|
||||
fn handle_key(&mut self, key_event: &KeyEvent);
|
||||
}
|
||||
@@ -13,7 +13,7 @@ use ratatui::{
|
||||
widgets::{Block, Clear, Paragraph, Widget},
|
||||
};
|
||||
|
||||
use crate::config::theme::BORDER_STYLE;
|
||||
use crate::config::{settings::ShortcutHintScope, theme::BORDER_STYLE};
|
||||
|
||||
type ContentFn<'a> = Box<dyn Fn(Rect, &mut Buffer) + 'a>;
|
||||
|
||||
@@ -56,7 +56,9 @@ impl<'a> Widget for PopupFrame<'a> {
|
||||
block = block.title_top(sl.alignment(Alignment::Right));
|
||||
}
|
||||
|
||||
if let Some(kb) = self.keybinds {
|
||||
if let Some(kb) = self.keybinds
|
||||
&& super::shortcut_hints_visible(ShortcutHintScope::Popups)
|
||||
{
|
||||
block = block.title_bottom(kb.alignment(Alignment::Right));
|
||||
}
|
||||
|
||||
|
||||
@@ -45,12 +45,45 @@ pub enum ConfirmTarget {
|
||||
OrphanDependencies {
|
||||
paths: Vec<std::path::PathBuf>,
|
||||
},
|
||||
InstanceRuntime {
|
||||
name: String,
|
||||
},
|
||||
LauncherCache,
|
||||
AutomaticSelection {
|
||||
setting: AutomaticSetting,
|
||||
instance: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum AutomaticSetting {
|
||||
Java,
|
||||
Account,
|
||||
}
|
||||
|
||||
impl AutomaticSetting {
|
||||
fn title(self) -> &'static str {
|
||||
match self {
|
||||
Self::Java => " Enable automatic Java ",
|
||||
Self::Account => " Enable automatic account ",
|
||||
}
|
||||
}
|
||||
|
||||
fn description(self) -> &'static str {
|
||||
match self {
|
||||
Self::Java => "Use the automatically selected Java runtime",
|
||||
Self::Account => "Use the currently active account",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ConfirmTarget {
|
||||
fn title(&self) -> String {
|
||||
match self {
|
||||
Self::OrphanDependencies { .. } => " Remove unused dependencies ".to_owned(),
|
||||
Self::InstanceRuntime { .. } => " Change runtime ".to_owned(),
|
||||
Self::LauncherCache => " Clear caches ".to_owned(),
|
||||
Self::AutomaticSelection { setting, .. } => setting.title().to_owned(),
|
||||
_ => format!(" Delete '{}' ", self.name()),
|
||||
}
|
||||
}
|
||||
@@ -89,6 +122,13 @@ impl ConfirmTarget {
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n"),
|
||||
ConfirmTarget::InstanceRuntime { .. } => {
|
||||
"Some installed mods may be incompatible".to_owned()
|
||||
}
|
||||
ConfirmTarget::LauncherCache => {
|
||||
"Provider metadata and Java detection will be rebuilt".to_owned()
|
||||
}
|
||||
ConfirmTarget::AutomaticSelection { setting, .. } => setting.description().to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +139,11 @@ impl ConfirmTarget {
|
||||
ConfirmTarget::ConfigProfile { profile } => profile,
|
||||
ConfirmTarget::Content { name, .. } => name,
|
||||
ConfirmTarget::OrphanDependencies { .. } => "unused dependencies",
|
||||
ConfirmTarget::InstanceRuntime { name, .. } => name,
|
||||
ConfirmTarget::LauncherCache => "launcher caches",
|
||||
ConfirmTarget::AutomaticSelection { instance, .. } => {
|
||||
instance.as_deref().unwrap_or("launcher")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +151,9 @@ impl ConfirmTarget {
|
||||
match self {
|
||||
Self::Content { dependents, .. } if !dependents.is_empty() => " delete anyway",
|
||||
Self::OrphanDependencies { .. } => " remove all",
|
||||
Self::InstanceRuntime { .. } => " change",
|
||||
Self::LauncherCache => " clear",
|
||||
Self::AutomaticSelection { .. } => " enable",
|
||||
_ => " confirm",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,16 @@ pub fn popup_area(frame_area: Rect, message: &str, base_y: u16, elapsed_ms: u128
|
||||
const MAX_W: usize = 58;
|
||||
const MIN_W: usize = 22;
|
||||
|
||||
if elapsed_ms >= SETTINGS.ui.error_auto_dismiss_ms as u128 {
|
||||
let visible_until = {
|
||||
let settings = SETTINGS.read();
|
||||
settings.ui.error_auto_dismiss_ms.min(
|
||||
settings
|
||||
.ui
|
||||
.error_slide_start_ms
|
||||
.saturating_add(settings.ui.error_fly_out_ms),
|
||||
) as u128
|
||||
};
|
||||
if elapsed_ms >= visible_until {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -480,7 +480,7 @@ async fn resolve_version_id(
|
||||
) {
|
||||
match modrinth::fetch_version(client, version_id).await {
|
||||
Ok(version) => {
|
||||
let meta_dir = crate::config::SETTINGS.paths.resolve_meta_dir();
|
||||
let meta_dir = crate::config::SETTINGS.read().paths.resolve_meta_dir();
|
||||
let tmp_dir = crate::storage::MetadataPaths::new(&meta_dir).temporary();
|
||||
if let Err(e) = tokio::fs::create_dir_all(&tmp_dir).await {
|
||||
set_error_and_back(
|
||||
@@ -558,7 +558,7 @@ fn start_version_download(state: &mut ImportWizardState) {
|
||||
|
||||
tokio::spawn(async move {
|
||||
let client = crate::net::HttpClient::new();
|
||||
let meta_dir = crate::config::SETTINGS.paths.resolve_meta_dir();
|
||||
let meta_dir = crate::config::SETTINGS.read().paths.resolve_meta_dir();
|
||||
let tmp_dir = crate::storage::MetadataPaths::new(&meta_dir).temporary();
|
||||
if let Err(e) = tokio::fs::create_dir_all(&tmp_dir).await {
|
||||
set_error_and_back(
|
||||
@@ -618,7 +618,7 @@ fn spawn_discovery_request_with_query(
|
||||
crate::tui::widgets::content::discovery::spawn_provider_search(
|
||||
query,
|
||||
crate::tui::widgets::content::discovery::DiscoveryTarget::Modpacks,
|
||||
crate::config::SETTINGS.paths.resolve_meta_dir(),
|
||||
crate::config::SETTINGS.read().paths.resolve_meta_dir(),
|
||||
request,
|
||||
);
|
||||
}
|
||||
@@ -667,9 +667,10 @@ fn start_discovered_download(request: crate::tui::widgets::content::discovery::I
|
||||
tokio::spawn(async move {
|
||||
let client = crate::net::HttpClient::new();
|
||||
let registry = crate::instance::content::provider::ProviderRegistry::configured(client);
|
||||
let tmp_dir =
|
||||
crate::storage::MetadataPaths::new(crate::config::SETTINGS.paths.resolve_meta_dir())
|
||||
.temporary();
|
||||
let tmp_dir = crate::storage::MetadataPaths::new(
|
||||
crate::config::SETTINGS.read().paths.resolve_meta_dir(),
|
||||
)
|
||||
.temporary();
|
||||
let result: Result<crate::instance::import::ImportSummary, crate::net::NetError> = async {
|
||||
let source = crate::instance::ProviderProject {
|
||||
provider: request.provider.clone(),
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -7,15 +7,22 @@
|
||||
pub mod base;
|
||||
pub mod confirm;
|
||||
pub mod error;
|
||||
pub mod global_settings;
|
||||
pub mod import_modpack;
|
||||
pub mod instance_settings;
|
||||
mod load_state;
|
||||
pub mod modpack_update;
|
||||
pub mod new_instance;
|
||||
pub(crate) mod select_list;
|
||||
pub(crate) mod settings_controls;
|
||||
pub mod version_lists;
|
||||
|
||||
pub use load_state::LoadState;
|
||||
|
||||
use ratatui::{layout::Rect, text::Span};
|
||||
|
||||
use crate::config::settings::ShortcutHintScope;
|
||||
|
||||
pub(crate) fn compare_game_versions(a: &str, b: &str) -> std::cmp::Ordering {
|
||||
let parse_parts = |version: &str| {
|
||||
version
|
||||
@@ -80,6 +87,13 @@ pub fn top_right_rect(frame: Rect, inner_w: usize, inner_h: usize) -> Rect {
|
||||
}
|
||||
|
||||
pub fn keybind_line(binds: &[(&str, &str)]) -> ratatui::text::Line<'static> {
|
||||
if !shortcut_hints_visible(ShortcutHintScope::Popups) {
|
||||
return ratatui::text::Line::default();
|
||||
}
|
||||
styled_keybind_line(binds)
|
||||
}
|
||||
|
||||
fn styled_keybind_line(binds: &[(&str, &str)]) -> ratatui::text::Line<'static> {
|
||||
use crate::config::theme::THEME;
|
||||
use ratatui::{
|
||||
style::{Modifier, Style},
|
||||
@@ -104,7 +118,18 @@ pub fn keybind_line(binds: &[(&str, &str)]) -> ratatui::text::Line<'static> {
|
||||
Line::from(spans)
|
||||
}
|
||||
|
||||
pub fn keybind_line_fitted(binds: &[(&str, &str)], max_width: u16) -> ratatui::text::Line<'static> {
|
||||
pub fn keybind_line_fitted(
|
||||
scope: ShortcutHintScope,
|
||||
binds: &[(&str, &str)],
|
||||
max_width: u16,
|
||||
) -> ratatui::text::Line<'static> {
|
||||
if !shortcut_hints_visible(scope) {
|
||||
return ratatui::text::Line::default();
|
||||
}
|
||||
fitted_keybind_line(binds, max_width)
|
||||
}
|
||||
|
||||
fn fitted_keybind_line(binds: &[(&str, &str)], max_width: u16) -> ratatui::text::Line<'static> {
|
||||
let mut width = 0;
|
||||
let mut count = 0;
|
||||
for (key, label) in binds {
|
||||
@@ -116,7 +141,11 @@ pub fn keybind_line_fitted(binds: &[(&str, &str)], max_width: u16) -> ratatui::t
|
||||
count += 1;
|
||||
}
|
||||
|
||||
keybind_line(&binds[..count]).right_aligned()
|
||||
styled_keybind_line(&binds[..count]).right_aligned()
|
||||
}
|
||||
|
||||
pub(crate) fn shortcut_hints_visible(scope: ShortcutHintScope) -> bool {
|
||||
crate::config::SETTINGS.read().ui.show_shortcut_hints(scope)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -146,13 +146,17 @@ pub fn render(frame: &mut Frame, state: &State) {
|
||||
Action::Reinstall => (" Reinstalling modpack ", " Please wait "),
|
||||
},
|
||||
};
|
||||
let block = Block::default()
|
||||
let mut block = Block::default()
|
||||
.title(title)
|
||||
.title_bottom(Line::from(footer).centered())
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BORDER_STYLE.to_border_type())
|
||||
.border_style(Style::default().fg(theme.accent()))
|
||||
.style(Style::default().fg(theme.text()).bg(theme.surface()));
|
||||
if state.phase == Phase::Applying
|
||||
|| super::shortcut_hints_visible(crate::config::settings::ShortcutHintScope::Popups)
|
||||
{
|
||||
block = block.title_bottom(Line::from(footer).centered());
|
||||
}
|
||||
match state.phase {
|
||||
Phase::Preparing => frame.render_widget(
|
||||
Paragraph::new(format!("Preparing the selected modpack {action}…")).block(block),
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
mod render;
|
||||
mod state;
|
||||
|
||||
pub use super::LoadState;
|
||||
pub(crate) use render::render_select_list;
|
||||
pub use render::{popup_rect, render};
|
||||
pub use state::{WizardParams, WizardState, WizardStep, handle_key, take_result};
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ use ratatui::{
|
||||
layout::{Constraint, Direction, Layout, Rect},
|
||||
style::{Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{List, ListItem, ListState, Paragraph, StatefulWidget, Widget, Wrap},
|
||||
widgets::{ListItem, Paragraph, Widget, Wrap},
|
||||
};
|
||||
use tui_prompts::State as PromptState;
|
||||
|
||||
@@ -202,40 +202,14 @@ fn render_version_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffe
|
||||
})
|
||||
.collect();
|
||||
|
||||
render_select_list(items, state.version_idx, area, buf);
|
||||
super::super::select_list::render(items, state.version_idx, area, buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn render_select_list(
|
||||
items: Vec<ListItem<'_>>,
|
||||
selected: usize,
|
||||
area: Rect,
|
||||
buffer: &mut ratatui::buffer::Buffer,
|
||||
) {
|
||||
let list = List::new(items)
|
||||
.highlight_style(Style::default().add_modifier(Modifier::BOLD))
|
||||
.highlight_symbol(Span::styled(
|
||||
"▶ ",
|
||||
Style::default()
|
||||
.fg(THEME.as_ref().accent())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
));
|
||||
let mut state = ListState::default().with_selected(Some(selected));
|
||||
StatefulWidget::render(list, area, buffer, &mut state);
|
||||
}
|
||||
|
||||
fn render_loader_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
||||
let theme = THEME.as_ref();
|
||||
let loaders = [
|
||||
ModLoader::Vanilla,
|
||||
ModLoader::Fabric,
|
||||
ModLoader::Forge,
|
||||
ModLoader::NeoForge,
|
||||
ModLoader::Quilt,
|
||||
];
|
||||
|
||||
let items: Vec<ListItem> = loaders
|
||||
let items: Vec<ListItem> = super::super::select_list::MOD_LOADERS
|
||||
.into_iter()
|
||||
.map(|loader| {
|
||||
ListItem::new(Line::from(Span::styled(
|
||||
@@ -245,16 +219,7 @@ fn render_loader_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer
|
||||
})
|
||||
.collect();
|
||||
|
||||
let list = List::new(items)
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.fg(theme.accent())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.highlight_symbol("▶ ");
|
||||
|
||||
let mut list_state = ListState::default().with_selected(Some(state.loader_idx));
|
||||
StatefulWidget::render(list, area, buf, &mut list_state);
|
||||
super::super::select_list::render(items, state.loader_idx, area, buf);
|
||||
}
|
||||
|
||||
fn render_loader_version_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
||||
@@ -289,16 +254,7 @@ fn render_loader_version_step(state: &WizardState, area: Rect, buf: &mut ratatui
|
||||
})
|
||||
.collect();
|
||||
|
||||
let list = List::new(items)
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.fg(theme.accent())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.highlight_symbol("▶ ");
|
||||
|
||||
let mut list_state = ListState::default().with_selected(Some(state.loader_version_idx));
|
||||
StatefulWidget::render(list, area, buf, &mut list_state);
|
||||
super::super::select_list::render(items, state.loader_version_idx, area, buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,7 @@
|
||||
// flow: Name -> Loader -> Version -> LoaderVersion -> Confirm
|
||||
// version lists are fetched lazily from the network when you reach that step.
|
||||
|
||||
use crate::instance::{
|
||||
loader::{GameVersion, get_installer},
|
||||
models::ModLoader,
|
||||
};
|
||||
use crate::instance::{loader::GameVersion, models::ModLoader};
|
||||
use crate::tui::widgets::instances;
|
||||
use crossterm::event::{KeyCode, KeyEvent};
|
||||
use std::sync::LazyLock;
|
||||
@@ -88,14 +85,7 @@ impl WizardState {
|
||||
}
|
||||
|
||||
pub fn selected_loader(&self) -> ModLoader {
|
||||
const LOADERS: [ModLoader; 5] = [
|
||||
ModLoader::Vanilla,
|
||||
ModLoader::Fabric,
|
||||
ModLoader::Forge,
|
||||
ModLoader::NeoForge,
|
||||
ModLoader::Quilt,
|
||||
];
|
||||
LOADERS[self.loader_idx % 5]
|
||||
super::super::select_list::MOD_LOADERS[self.loader_idx % 5]
|
||||
}
|
||||
|
||||
pub fn selected_loader_version(&self) -> Option<String> {
|
||||
@@ -405,12 +395,9 @@ pub(crate) fn ensure_versions_loaded(state: &mut WizardState) {
|
||||
let versions_arc = WIZARD_STATE.clone();
|
||||
let loader = state.selected_loader();
|
||||
tokio::spawn(async move {
|
||||
let client = crate::net::HttpClient::new();
|
||||
let installer = get_installer(loader);
|
||||
match installer.get_game_versions(&client).await {
|
||||
Ok(mut versions) => match versions_arc.lock() {
|
||||
match super::super::version_lists::game_versions(loader).await {
|
||||
Ok(versions) => match versions_arc.lock() {
|
||||
Ok(mut s) => {
|
||||
sort_versions_semver(&mut versions);
|
||||
s.versions = LoadState::Loaded(versions);
|
||||
clamp_version_index(&mut s);
|
||||
}
|
||||
@@ -442,9 +429,7 @@ pub(crate) fn ensure_loader_versions_loaded(
|
||||
state.loader_versions = LoadState::Loading;
|
||||
let versions_arc = WIZARD_STATE.clone();
|
||||
tokio::spawn(async move {
|
||||
let client = crate::net::HttpClient::new();
|
||||
let installer = get_installer(loader);
|
||||
match installer.get_versions(&client, &game_version).await {
|
||||
match super::super::version_lists::loader_versions(loader, &game_version).await {
|
||||
Ok(versions) => match versions_arc.lock() {
|
||||
Ok(mut s) => {
|
||||
s.loader_versions = LoadState::Loaded(versions);
|
||||
@@ -466,10 +451,6 @@ pub(crate) fn ensure_loader_versions_loaded(
|
||||
});
|
||||
}
|
||||
|
||||
fn sort_versions_semver(versions: &mut [GameVersion]) {
|
||||
versions.sort_by(|a, b| super::super::compare_game_versions(&b.id, &a.id));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../../../tests/widgets/popups/new_instance/state.rs"]
|
||||
mod tests;
|
||||
@@ -0,0 +1,94 @@
|
||||
// SPDX-FileCopyrightText: 2026 Constantin Bauer
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
// Shared selection list used by the new-instance wizard and settings pickers.
|
||||
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::Rect,
|
||||
style::{Modifier, Style},
|
||||
text::Span,
|
||||
widgets::{List, ListItem, ListState, StatefulWidget},
|
||||
};
|
||||
|
||||
use crate::config::theme::THEME;
|
||||
use crate::instance::models::ModLoader;
|
||||
|
||||
pub(crate) const MOD_LOADERS: [ModLoader; 5] = [
|
||||
ModLoader::Vanilla,
|
||||
ModLoader::Fabric,
|
||||
ModLoader::Forge,
|
||||
ModLoader::NeoForge,
|
||||
ModLoader::Quilt,
|
||||
];
|
||||
|
||||
pub(crate) fn render(items: Vec<ListItem<'_>>, selected: usize, area: Rect, buffer: &mut Buffer) {
|
||||
let list = List::new(items)
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.fg(THEME.as_ref().accent())
|
||||
.bg(THEME.as_ref().stripe())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.highlight_symbol(Span::styled(
|
||||
"▶ ",
|
||||
Style::default()
|
||||
.fg(THEME.as_ref().accent())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
));
|
||||
let mut state = ListState::default().with_selected(Some(selected));
|
||||
StatefulWidget::render(list, area, buffer, &mut state);
|
||||
}
|
||||
|
||||
pub(crate) fn render_styled(
|
||||
items: Vec<ListItem<'_>>,
|
||||
selected: usize,
|
||||
area: Rect,
|
||||
buffer: &mut Buffer,
|
||||
) {
|
||||
let theme = THEME.as_ref();
|
||||
let items = items
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(index, item)| {
|
||||
if index == selected {
|
||||
item.style(Style::default().bg(theme.stripe()))
|
||||
} else {
|
||||
item
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let list = List::new(items)
|
||||
.highlight_style(Style::default().add_modifier(Modifier::BOLD))
|
||||
.highlight_symbol(Span::styled(
|
||||
"▶ ",
|
||||
Style::default()
|
||||
.fg(theme.accent())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
));
|
||||
let mut state = ListState::default().with_selected(Some(selected));
|
||||
StatefulWidget::render(list, area, buffer, &mut state);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ratatui::text::Line;
|
||||
|
||||
use super::*;
|
||||
use crate::tui::widgets::status_badge;
|
||||
|
||||
#[test]
|
||||
fn styled_list_preserves_badges_on_the_selected_row() {
|
||||
let theme = THEME.as_ref();
|
||||
let area = Rect::new(0, 0, 30, 1);
|
||||
let mut buffer = Buffer::empty(area);
|
||||
let badge = status_badge("Auto", theme.success());
|
||||
let items = vec![ListItem::new(Line::from(vec![Span::raw("Java "), badge]))];
|
||||
|
||||
render_styled(items, 0, area, &mut buffer);
|
||||
|
||||
let badge_cell = buffer.cell((8, 0)).unwrap();
|
||||
assert_eq!(badge_cell.bg, theme.success());
|
||||
assert_eq!(badge_cell.fg, theme.background());
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,27 @@
|
||||
// SPDX-FileCopyrightText: 2026 Constantin Bauer
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
// shared network loading for Minecraft and mod-loader version pickers.
|
||||
|
||||
use crate::instance::{
|
||||
loader::{GameVersion, get_installer},
|
||||
models::ModLoader,
|
||||
};
|
||||
|
||||
pub async fn game_versions(loader: ModLoader) -> Result<Vec<GameVersion>, String> {
|
||||
let client = crate::net::HttpClient::new();
|
||||
let mut versions = get_installer(loader)
|
||||
.get_game_versions(&client)
|
||||
.await
|
||||
.map_err(|error| error.to_string())?;
|
||||
versions.sort_by(|a, b| super::compare_game_versions(&b.id, &a.id));
|
||||
Ok(versions)
|
||||
}
|
||||
|
||||
pub async fn loader_versions(loader: ModLoader, game_version: &str) -> Result<Vec<String>, String> {
|
||||
let client = crate::net::HttpClient::new();
|
||||
get_installer(loader)
|
||||
.get_versions(&client, game_version)
|
||||
.await
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
+44
-53
@@ -2,12 +2,9 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
// settings panel: manages config profiles and shows compact instance info.
|
||||
// also provides keybinds to open config files in $EDITOR.
|
||||
// detailed instance and launcher configuration opens in the TUI popups.
|
||||
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
process::Command,
|
||||
};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crossterm::event::{KeyCode, KeyEvent};
|
||||
use ratatui::{
|
||||
@@ -53,7 +50,6 @@ pub struct SettingsState {
|
||||
active_profile: Option<String>,
|
||||
instance_name: Option<String>,
|
||||
java_key: Option<String>,
|
||||
java_source: Option<String>,
|
||||
java_label: String,
|
||||
}
|
||||
|
||||
@@ -72,7 +68,6 @@ impl SettingsState {
|
||||
active_profile: None,
|
||||
instance_name: None,
|
||||
java_key: None,
|
||||
java_source: None,
|
||||
java_label: "unknown".to_string(),
|
||||
};
|
||||
state.select_active();
|
||||
@@ -132,7 +127,6 @@ impl SettingsState {
|
||||
.map(java_version_label)
|
||||
.unwrap_or_else(|| "unknown".to_string());
|
||||
self.java_key = java_key;
|
||||
self.java_source = java_source;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,39 +145,37 @@ fn java_path_key(instance: &InstanceConfig) -> String {
|
||||
.java_path
|
||||
.as_deref()
|
||||
.filter(|path| !path.is_empty())
|
||||
.or_else(|| SETTINGS.paths.effective_java_path())
|
||||
.unwrap_or("<auto>")
|
||||
.to_string()
|
||||
.map(str::to_owned)
|
||||
.or_else(|| {
|
||||
SETTINGS
|
||||
.read()
|
||||
.paths
|
||||
.effective_java_path()
|
||||
.map(str::to_owned)
|
||||
})
|
||||
.unwrap_or_else(|| "<auto>".to_owned())
|
||||
}
|
||||
|
||||
fn effective_java_path(instance: &InstanceConfig) -> String {
|
||||
instance
|
||||
.java_path
|
||||
.clone()
|
||||
.or_else(|| SETTINGS.paths.effective_java_path().map(str::to_string))
|
||||
.or_else(|| {
|
||||
SETTINGS
|
||||
.read()
|
||||
.paths
|
||||
.effective_java_path()
|
||||
.map(str::to_owned)
|
||||
})
|
||||
.unwrap_or_else(crate::instance::java::detect_java_path)
|
||||
}
|
||||
|
||||
fn java_version_label(java_path: &str) -> String {
|
||||
let output = Command::new(java_path).arg("-version").output();
|
||||
let Ok(output) = output else {
|
||||
let Some(version) = crate::instance::java::java_version(Path::new(java_path)) else {
|
||||
return "unknown".to_string();
|
||||
};
|
||||
let raw = String::from_utf8_lossy(if output.stderr.is_empty() {
|
||||
&output.stdout
|
||||
} else {
|
||||
&output.stderr
|
||||
});
|
||||
let first_line = raw.lines().next().unwrap_or_default();
|
||||
let Some(version) = first_line.split('"').nth(1) else {
|
||||
return "unknown".to_string();
|
||||
};
|
||||
let major = if let Some(stripped) = version.strip_prefix("1.") {
|
||||
stripped.split('.').next().unwrap_or(stripped)
|
||||
} else {
|
||||
version.split('.').next().unwrap_or(version)
|
||||
};
|
||||
if major.is_empty() {
|
||||
let major = crate::instance::java::java_major(Some(&version));
|
||||
if major == 0 {
|
||||
"unknown".to_string()
|
||||
} else {
|
||||
format!("jdk{major}")
|
||||
@@ -196,7 +188,6 @@ pub fn render(
|
||||
focused: FocusedArea,
|
||||
state: &mut SettingsState,
|
||||
instance: Option<&InstanceConfig>,
|
||||
_instances_dir: &Path,
|
||||
) {
|
||||
state.update_for_instance(instance);
|
||||
|
||||
@@ -224,14 +215,14 @@ pub fn render(
|
||||
("Esc", " back"),
|
||||
],
|
||||
SettingsPane::Info => &[
|
||||
("e", " inst"),
|
||||
("g", " global"),
|
||||
("d", " desk"),
|
||||
("e", " instance"),
|
||||
("g", " launcher"),
|
||||
("h/l", " tab"),
|
||||
("Esc", " back"),
|
||||
],
|
||||
};
|
||||
Some(super::popups::keybind_line_fitted(
|
||||
crate::config::settings::ShortcutHintScope::Settings,
|
||||
keybinds,
|
||||
area.width.saturating_sub(2),
|
||||
))
|
||||
@@ -245,7 +236,13 @@ pub fn render(
|
||||
let inner = block.inner(area);
|
||||
frame.render_widget(block, area);
|
||||
|
||||
if inner.width >= 42 {
|
||||
if instance.is_none() {
|
||||
frame.render_widget(
|
||||
Paragraph::new("No instance selected.")
|
||||
.style(Style::default().fg(THEME.as_ref().text_dim())),
|
||||
inner,
|
||||
);
|
||||
} else if inner.width >= 42 {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints([
|
||||
@@ -302,23 +299,24 @@ fn render_instance_info(
|
||||
return;
|
||||
};
|
||||
|
||||
let settings = SETTINGS.read();
|
||||
let memory_min = inst
|
||||
.memory_min
|
||||
.as_deref()
|
||||
.unwrap_or(&SETTINGS.defaults.memory_min);
|
||||
.unwrap_or(&settings.defaults.memory_min);
|
||||
let memory_max = inst
|
||||
.memory_max
|
||||
.as_deref()
|
||||
.unwrap_or(&SETTINGS.defaults.memory_max);
|
||||
.unwrap_or(&settings.defaults.memory_max);
|
||||
let active_style = if focused == FocusedArea::Settings && state.pane == SettingsPane::Info {
|
||||
value_style.fg(theme.accent())
|
||||
} else {
|
||||
value_style
|
||||
};
|
||||
let desktop = if crate::instance::desktop::exists(&inst.name) {
|
||||
"yes"
|
||||
let shortcut = if crate::instance::desktop::exists(&inst.name) {
|
||||
"enabled"
|
||||
} else {
|
||||
"no"
|
||||
"disabled"
|
||||
};
|
||||
let lines = vec![
|
||||
Line::from(vec![
|
||||
@@ -330,8 +328,8 @@ fn render_instance_info(
|
||||
Span::styled(state.java_label.as_str(), active_style),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("Desktop ", label_style),
|
||||
Span::styled(desktop, active_style),
|
||||
Span::styled("Shortcut ", label_style),
|
||||
Span::styled(shortcut, active_style),
|
||||
]),
|
||||
];
|
||||
|
||||
@@ -460,9 +458,8 @@ fn popup_area(frame: &Frame, width: u16, height: u16) -> Rect {
|
||||
|
||||
pub enum SettingsAction {
|
||||
None,
|
||||
EditInstance(PathBuf),
|
||||
EditGlobal(PathBuf),
|
||||
ToggleDesktop,
|
||||
OpenInstance,
|
||||
OpenGlobal,
|
||||
SelectProfile(Option<String>),
|
||||
ConfirmDeleteProfile(String),
|
||||
Error(String),
|
||||
@@ -472,7 +469,6 @@ pub fn handle_key(
|
||||
key_event: &KeyEvent,
|
||||
state: &mut SettingsState,
|
||||
instance: Option<&InstanceConfig>,
|
||||
instances_dir: &Path,
|
||||
) -> SettingsAction {
|
||||
if let AddMode::ProfileName(name) = &state.add_mode {
|
||||
match key_event.code {
|
||||
@@ -558,18 +554,13 @@ pub fn handle_key(
|
||||
SettingsAction::None
|
||||
}
|
||||
KeyCode::Char('e') if state.pane == SettingsPane::Info => {
|
||||
if let Some(inst) = instance {
|
||||
let path = instances_dir.join(&inst.name).join("instance.json");
|
||||
SettingsAction::EditInstance(path)
|
||||
if instance.is_some() {
|
||||
SettingsAction::OpenInstance
|
||||
} else {
|
||||
SettingsAction::None
|
||||
}
|
||||
}
|
||||
KeyCode::Char('g') if state.pane == SettingsPane::Info => {
|
||||
let path = crate::config::get_config_path().join("config.toml");
|
||||
SettingsAction::EditGlobal(path)
|
||||
}
|
||||
KeyCode::Char('d') if state.pane == SettingsPane::Info => SettingsAction::ToggleDesktop,
|
||||
KeyCode::Char('g') if state.pane == SettingsPane::Info => SettingsAction::OpenGlobal,
|
||||
_ => SettingsAction::None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,15 @@ fn make_config_with(
|
||||
memory_max: None,
|
||||
memory_min: None,
|
||||
jvm_args: Vec::new(),
|
||||
environment: Default::default(),
|
||||
window_mode: Default::default(),
|
||||
inherit_window_mode: false,
|
||||
resolution: None,
|
||||
inherit_resolution: false,
|
||||
preferred_account: None,
|
||||
pre_launch_command: Default::default(),
|
||||
post_exit_command: Default::default(),
|
||||
glfw_path: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
}
|
||||
@@ -663,6 +671,38 @@ async fn xms_xmx_use_config_memory() {
|
||||
assert!(inv.jvm_args.iter().any(|a| a == "-Xmx4G"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn instance_launch_options_are_injected() {
|
||||
let fx = Fixture::new("options", "1.20.1", modern_vanilla_meta("1.20.1"));
|
||||
let mut config = make_config("options", "1.20.1", ModLoader::Vanilla);
|
||||
config.window_mode = rmcl::instance::WindowMode::Fullscreen;
|
||||
config.glfw_path = Some("/usr/lib/libglfw.so.3".to_owned());
|
||||
config
|
||||
.environment
|
||||
.insert("MESA_LOADER_DRIVER_OVERRIDE".to_owned(), "zink".to_owned());
|
||||
|
||||
let inv = build_launch_invocation(&config, &fx.instances_dir, &fx.meta_dir, &test_auth(), None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(
|
||||
inv.game_args
|
||||
.iter()
|
||||
.any(|argument| argument == "--fullscreen")
|
||||
);
|
||||
assert!(
|
||||
inv.jvm_args
|
||||
.iter()
|
||||
.any(|argument| argument == "-Dorg.lwjgl.glfw.libname=/usr/lib/libglfw.so.3")
|
||||
);
|
||||
assert_eq!(
|
||||
inv.environment
|
||||
.get("MESA_LOADER_DRIVER_OVERRIDE")
|
||||
.map(String::as_str),
|
||||
Some("zink")
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn default_memory_used_when_unset() {
|
||||
let fx = Fixture::new("memdef", "1.20.1", modern_vanilla_meta("1.20.1"));
|
||||
|
||||
Reference in new issue
Block a user