From 6cb618a631280574ef205c0db77ec9eb10b5f201 Mon Sep 17 00:00:00 2001 From: Avery Felts Date: Fri, 20 Nov 2026 08:26:17 -0700 Subject: [PATCH] fix(settings): offer Uninstall FEX / x86_64 for a runtime that is only downloaded Settings > Advanced offered "Uninstall FEX" and "Uninstall x86_64" only when both runtimes were fully installed. A runtime that was downloaded but whose setup never finished (FEX's, in #811) left no way to remove its download but "Uninstall MetalSharp", so it looked as if the per-build uninstall did not exist (#813). /runtime/state now reports "present" for each runtime: installed, or its app, download or kept-aside files on disk. Settings offers the inactive runtime's uninstall whenever it is present, and the active one's when the other is installed to switch to, as before. The backend already removed an inactive runtime in any state. --- app-gpui/backend-route-inventory.json | 54 +++++++++---------- app-gpui/src/settings_preview.rs | 36 +++++++++++-- .../include/metalsharp_backend/wine_runtime.h | 2 + app/src-c/runtime/wine_runtime.c | 23 +++++++- app/src-c/tests/runtime_routes_test.c | 30 +++++++++++ 5 files changed, 112 insertions(+), 33 deletions(-) diff --git a/app-gpui/backend-route-inventory.json b/app-gpui/backend-route-inventory.json index 9ff2ec2a..47c7c69b 100644 --- a/app-gpui/backend-route-inventory.json +++ b/app-gpui/backend-route-inventory.json @@ -187,7 +187,7 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 1296, + "line": 1315, "kind": "literal-candidate" }, { @@ -246,22 +246,22 @@ }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1088, + "line": 1107, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1122, + "line": 1141, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1159, + "line": 1178, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1193, + "line": 1212, "kind": "literal-candidate" }, { @@ -343,22 +343,22 @@ }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1088, + "line": 1107, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1122, + "line": 1141, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1159, + "line": 1178, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1193, + "line": 1212, "kind": "literal-candidate" }, { @@ -1994,12 +1994,12 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 1034, + "line": 1053, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1390, + "line": 1409, "kind": "literal-candidate" } ], @@ -2189,7 +2189,7 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 646, + "line": 665, "kind": "literal-candidate" } ], @@ -2270,7 +2270,7 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 760, + "line": 779, "kind": "literal-candidate" }, { @@ -2395,7 +2395,7 @@ }, { "file": "app-gpui/src/settings_preview.rs", - "line": 777, + "line": 796, "kind": "literal-candidate" }, { @@ -2785,7 +2785,7 @@ }, { "file": "app-gpui/src/settings_preview.rs", - "line": 734, + "line": 753, "kind": "literal-candidate" }, { @@ -2817,7 +2817,7 @@ }, { "file": "app-gpui/src/settings_preview.rs", - "line": 734, + "line": 753, "kind": "literal-candidate" }, { @@ -3323,7 +3323,7 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 1384, + "line": 1403, "kind": "literal-candidate" }, { @@ -3585,12 +3585,12 @@ }, { "file": "app-gpui/src/settings_preview.rs", - "line": 820, + "line": 839, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 871, + "line": 890, "kind": "literal-candidate" }, { @@ -3692,7 +3692,7 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 894, + "line": 913, "kind": "literal-candidate" } ], @@ -3709,7 +3709,7 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 959, + "line": 978, "kind": "literal-candidate" } ], @@ -3758,7 +3758,7 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 925, + "line": 944, "kind": "literal-candidate" } ], @@ -3791,7 +3791,7 @@ }, { "file": "app-gpui/src/settings_preview.rs", - "line": 685, + "line": 704, "kind": "literal-candidate" }, { @@ -3862,17 +3862,17 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 805, + "line": 824, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 845, + "line": 864, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 975, + "line": 994, "kind": "literal-candidate" }, { @@ -4408,7 +4408,7 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 1331, + "line": 1350, "kind": "literal-candidate" }, { diff --git a/app-gpui/src/settings_preview.rs b/app-gpui/src/settings_preview.rs index cc177387..38a56859 100644 --- a/app-gpui/src/settings_preview.rs +++ b/app-gpui/src/settings_preview.rs @@ -631,6 +631,25 @@ impl SettingsPreview { == Some(true) } + /// Whether anything of `variant`'s runtime is on disk to uninstall (installed, or only downloaded or partly set + /// up), per the last /runtime/state. A backend without "present" reports only "installed". + fn runtime_present(&self, variant: &str) -> bool { + self.runtime_state + .as_ref() + .and_then(|s| s.get(variant)) + .and_then(|v| v.get("present").or_else(|| v.get("installed"))) + .and_then(Value::as_bool) + == Some(true) + } + + /// The runtime the backend runs on ("fex" or "regular"), per the last /runtime/state. + fn active_runtime(&self) -> Option<&str> { + self.runtime_state + .as_ref() + .and_then(|s| s.get("active")) + .and_then(Value::as_str) + } + /// Settings' "Uninstall FEX" / "Uninstall x86_64": that runtime only (the backend refuses the last one). fn uninstall_runtime(&mut self, variant: &'static str, cx: &mut Context) { if self.uninstalling_runtime { @@ -2532,15 +2551,24 @@ impl Render for SettingsPreview { .child(self.text_control(format!("{}%", app.update_progress.round() as u32))), ) }); - // One runtime only, for a user who wants just one of the two: offered when both are installed (the last - // one goes with "Uninstall MetalSharp"). - let both_installed = self.runtime_installed("fex") && self.runtime_installed("regular"); + // One runtime only, for a user who wants just one of the two. The inactive one is offered whenever anything + // of it is on disk, including a download whose setup never finished (#813); the active one only when the + // other is installed to switch to (the last one goes with "Uninstall MetalSharp"). + let active = self.active_runtime().map(str::to_owned); + let offered = |variant: &str| { + let other = if variant == "fex" { "regular" } else { "fex" }; + match active.as_deref() { + Some(a) if a == variant => self.runtime_installed(other), + Some(_) => self.runtime_present(variant), + None => self.runtime_installed("fex") && self.runtime_installed("regular"), + } + }; let runtime_uninstalls: Vec<_> = [ ("fex", "uninstall-fex", "Uninstall FEX", "Delete the FEX Wine runtime (Arm64 with FEX) and its shader caches, keeping the x86_64 one, your prefixes and settings"), ("regular", "uninstall-x86_64", "Uninstall x86_64", "Delete the x86_64 Wine runtime (Rosetta 2) and its shader caches, keeping the FEX one, your prefixes and settings"), ] .into_iter() - .filter(|_| both_installed) + .filter(|(variant, ..)| offered(variant)) .map(|(variant, id, label, desc)| { self.row( label, diff --git a/app/src-c/include/metalsharp_backend/wine_runtime.h b/app/src-c/include/metalsharp_backend/wine_runtime.h index 26a32005..aeee563b 100644 --- a/app/src-c/include/metalsharp_backend/wine_runtime.h +++ b/app/src-c/include/metalsharp_backend/wine_runtime.h @@ -177,6 +177,8 @@ void ms_wine_reload_active_runtime(void); /* The backend (main) follows config/active-runtime; other programs (the tests) keep the build's runtime */ void ms_wine_use_active_runtime_setting(void); bool ms_wine_runtime_installed(const char* home, const char* variant); +/* Anything of the runtime's on disk to uninstall: installed, or only downloaded / partly set up */ +bool ms_wine_runtime_present(const char* home, const char* variant); /* Removes what an update leaves behind: an app set aside by an interrupted swap, and a download from another * MetalSharp Wine release. */ void ms_wine_remove_superseded(const char* home); diff --git a/app/src-c/runtime/wine_runtime.c b/app/src-c/runtime/wine_runtime.c index 30c82f21..d558b2e6 100644 --- a/app/src-c/runtime/wine_runtime.c +++ b/app/src-c/runtime/wine_runtime.c @@ -1580,6 +1580,22 @@ bool ms_wine_runtime_installed(const char* home, const char* variant) { format_path(wine, sizeof(wine), "%s/%s", path, "wine") && runtime_wine_ready(wine, variant); } +/* Anything of `variant`'s on disk that "Uninstall FEX" / "Uninstall x86_64" would remove: it installed, its app in + * runtime/, its download, or its files kept aside. A runtime downloaded but never set up (or whose setup failed) has + * only some of these, and is still worth removing. */ +bool ms_wine_runtime_present(const char* home, const char* variant) { + char path[PATH_MAX]; + bool fex = variant && !strcmp(variant, "fex"); + const char* app = fex ? "MetalSharp-Wine.app" : WINE_X86_64_APP; + if (!home || !variant || (!fex && strcmp(variant, "regular"))) + return false; + if (ms_wine_runtime_installed(home, variant)) + return true; + return (format_path(path, sizeof(path), "%s/runtime/%s", home, app) && access(path, F_OK) == 0) || + (format_path(path, sizeof(path), "%s/downloads/%s", home, app) && access(path, F_OK) == 0) || + (runtime_stash(home, variant, path, sizeof(path)) && access(path, F_OK) == 0); +} + /* Where the runtime installs from: MetalSharp.app's own, or one downloaded into /downloads */ static bool runtime_source_available(const char* variant) { char* source = !strcmp(variant, "fex") ? ms_wine_fex_app_source() : ms_wine_x86_64_app_source(); @@ -1593,6 +1609,8 @@ static void write_runtime_state(ms_json_writer* writer, const char* home, const ms_json_writer_object_begin(writer); ms_json_writer_key(writer, "installed"); ms_json_writer_bool(writer, ms_wine_runtime_installed(home, variant)); + ms_json_writer_key(writer, "present"); + ms_json_writer_bool(writer, ms_wine_runtime_present(home, variant)); ms_json_writer_key(writer, "source"); ms_json_writer_bool(writer, runtime_source_available(variant)); /* installed from another MetalSharp Wine release, with nothing of this one to install from: switching to it @@ -1793,8 +1811,9 @@ char* ms_wine_switch_runtime_json(const char* home, const char* body, size_t bod * Settings' "Uninstall FEX" / "Uninstall x86_64": that runtime's Wine app, its laid-out files (active in runtime/ or * kept aside), its download and its lanes' caches go; prefixes, which both runtimes share, stay. The active runtime * goes only when the other is installed: the switch to it comes first (and the backend restarts on it). The last - * runtime stays: removing it is "Uninstall MetalSharp". MetalSharp.app still carries the apps, so either runtime can - * be set up again from the FEX | x86_64 toggle. */ + * runtime stays: removing it is "Uninstall MetalSharp". The inactive one goes whatever state it is in, including a + * download whose setup never finished. MetalSharp.app still carries the apps, so either runtime can be set up again + * from the FEX | x86_64 toggle. */ bool ms_wine_uninstall_runtime(const char* home, const char* variant, bool* switched, char* error, size_t error_size) { static const char* const fex_caches[] = {"shader-cache/fex-dxmt", "shader-cache/fex-dxmt_32", "shader-cache/fex-vkd3d", "shader-cache/fex-dxvk", diff --git a/app/src-c/tests/runtime_routes_test.c b/app/src-c/tests/runtime_routes_test.c index 65442e7d..3950f5a3 100644 --- a/app/src-c/tests/runtime_routes_test.c +++ b/app/src-c/tests/runtime_routes_test.c @@ -1036,6 +1036,35 @@ static void test_bottle_action_keeps_child_waits(const char* root) { unsetenv("METALSHARP_APP_RESOURCES"); } +/* The inactive runtime downloaded but never set up (FEX's setup failing, issue 811) is still something on disk to + * remove: /runtime/state reports it present though not installed, so Settings offers "Uninstall FEX" / + * "Uninstall x86_64" for it, and uninstalling it removes the download (issue 813). */ +static void test_uninstall_downloaded_runtime(const char* root) { + char home[PATH_MAX], path[PATH_MAX], downloaded[PATH_MAX], error[PATH_MAX + 128] = ""; + const char* inactive = ms_wine_is_fex() ? "regular" : "fex"; + const char* app = ms_wine_is_fex() ? "MetalSharp-Wine-x86_64.app" : "MetalSharp-Wine.app"; + char *state, key[64]; + bool switched = true; + snprintf(home, sizeof(home), "%s/uninstall-downloaded-runtime", root); + snprintf(downloaded, sizeof(downloaded), "%s/downloads/%s", home, app); + snprintf(path, sizeof(path), "mkdir -p '%s/Contents/MacOS' '%s/runtime'", downloaded, home); + assert(system(path) == 0); + + assert(!ms_wine_runtime_installed(home, inactive)); + assert(ms_wine_runtime_present(home, inactive)); + state = ms_wine_runtimes_json(home); + snprintf(key, sizeof(key), "\"%s\":{\"installed\":false,\"present\":true", inactive); + assert(state && strstr(state, key)); + free(state); + + assert(ms_wine_uninstall_runtime(home, inactive, &switched, error, sizeof(error))); + assert(!switched); + assert(access(downloaded, F_OK) != 0); + assert(!ms_wine_runtime_present(home, inactive)); + /* nothing of it at all */ + assert(!ms_wine_runtime_present(home, "bogus") && !ms_wine_runtime_present(NULL, inactive)); +} + int main(int argc, char** argv) { if (argc >= 2 && !strcmp(argv[1], "--wine-exe-probe")) { for (;;) @@ -2958,6 +2987,7 @@ int main(int argc, char** argv) { free(dosdevices); legacy_ntdll_hook_refresh_test(home); test_bottle_action_keeps_child_waits(home); + test_uninstall_downloaded_runtime(home); puts("runtime routing regressions passed"); return 0; }