Play Windows games on Apple Silicon Macs. Free, open-source app that installs the official Battle.net, Steam, Epic and GOG launchers and lists your games in one library.
HTML apple-siliconbattle-netcrossover-alternatived3dmetaldiablo-ii-resurrecteddxmtea-appepic-gamesgame-porting-toolkitgogmac-gamingmacosmacos-gamingrockstar-gamessteamubisoft-connectwhisky-alternativewindows-gameswinewine-wrapper
App: remove a launcher, or all of Soju, from Platforms (#132)
Mikekd35cf48a2874
diff --git a/app/Soju.swift b/app/Soju.swiftindex b904b644bc4..2b100187d15 100644--- a/app/Soju.swift+++ b/app/Soju.swift@@ -245,6 +245,57 @@ struct SojuLogo: View {}}+ /// Platforms → a launcher's Remove…: its bottle with the games in it, and its app shortcut.+ func confirmRemove(_ launcher: Launcher) {+ let alert = NSAlert()+ alert.messageText = "Remove " + launcher.title + "?"+ alert.informativeText = "This deletes " + launcher.title + " from Soju together with the games installed in it and their local saves. "+ + "Games you moved to another drive stay on that drive. Your account and purchases stay with the store, "+ + "and you can install it again from Platforms. Other launchers are not touched."+ alert.alertStyle = .warning+ alert.addButton(withTitle: "Remove " + launcher.title)+ alert.addButton(withTitle: "Cancel")+ alert.buttons.first?.hasDestructiveAction = true+ guard alert.runModal() == .alertFirstButtonReturn else { return }+ run(["uninstall", "launcher", launcher.rawValue], title: "Removing " + launcher.title + "…")+ }++ /// Platforms → Uninstall Soju…: everything soju uninstall --yes removes, then the app goes to the Trash.+ func confirmUninstallAll() {+ let alert = NSAlert()+ alert.messageText = "Uninstall Soju?"+ alert.informativeText = "This deletes every launcher Soju installed, all games inside them and their local saves, "+ + "Soju's engines and downloads (in ~/.battlenet-macos), and then moves Soju to the Trash. "+ + "Games you moved to another drive stay on that drive. Accounts and purchases stay with each store."+ alert.alertStyle = .critical+ alert.addButton(withTitle: "Uninstall Soju")+ alert.addButton(withTitle: "Cancel")+ alert.buttons.first?.hasDestructiveAction = true+ guard alert.runModal() == .alertFirstButtonReturn, !busy else { return }+ busy = true; failed = false; activity = "Uninstalling Soju…"; log = ""+ do {+ let (p, url) = try task(["uninstall", "all"], logName: "uninstall")+ p.terminationHandler = { [weak self] process in+ DispatchQueue.main.async {+ guard let self else { return }+ self.busy = false+ guard process.terminationStatus == 0 else {+ self.failed = true; self.activity = "Uninstall stopped. See the details below."+ self.log = (try? String(contentsOf: url, encoding: .utf8)) ?? ""+ return+ }+ UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier ?? "app.soju.desktop")+ NSWorkspace.shared.recycle([Bundle.main.bundleURL]) { _, _ in+ DispatchQueue.main.async { NSApp.terminate(nil) }+ }+ }+ }+ try p.run()+ } catch {+ busy = false; failed = true; activity = "Could not start the uninstall."; log = error.localizedDescription+ }+ }+private func readLog() {guard let reader = logReader else { return }let data = reader.readDataToEndOfFile()@@ -387,6 +438,8 @@ struct PlatformsView: View {HStack {Text("Accounts, purchases and updates stay with each official store.")Spacer()+ Button("Uninstall Soju…") { model.confirmUninstallAll() }+ .buttonStyle(.link).disabled(model.busy)}.font(.system(size: 10)).foregroundStyle(.secondary)}.padding(28).frame(minWidth: 730, idealWidth: 850, minHeight: 610, idealHeight: 680).background(Color(nsColor: .windowBackgroundColor))@@ -432,6 +485,14 @@ struct PlatformsView: View {.disabled(model.busy).accessibilityLabel("Install " + launcher.title)}}+ if installed {+ HStack {+ Spacer()+ Button("Remove…") { model.confirmRemove(launcher) }+ .buttonStyle(.link).font(.system(size: 10)).disabled(model.busy)+ .accessibilityLabel("Remove " + launcher.title)+ }+ }}.padding(18).background(Color(nsColor: .controlBackgroundColor), in: RoundedRectangle(cornerRadius: 16)).overlay(RoundedRectangle(cornerRadius: 16).stroke(green.opacity(0.12), lineWidth: 1))}diff --git a/docs/DESKTOP.md b/docs/DESKTOP.mdindex 4fb6f89bcdd..1467670be1c 100644--- a/docs/DESKTOP.md+++ b/docs/DESKTOP.md@@ -21,6 +21,9 @@ before 1.10.11 were ad-hoc signed; if macOS blocks one of those, update, or usePrivacy & Security's Open Anyway.A local source build is also available: `bash scripts/install-app.sh`.Soju does not collect telemetry or upload diagnostic logs. Copy log is manual.+To remove one launcher and the games in it, press **Remove…** on its card in Platforms. **Uninstall Soju…**+at the bottom of Platforms removes every launcher, engine and download, then moves the app to the Trash+(the same as `soju uninstall --yes`). Games moved to another drive stay on that drive.## Requirementsdiff --git a/scripts/desktop-action.sh b/scripts/desktop-action.shindex 4356e8d9416..4593d48904b 100755--- a/scripts/desktop-action.sh+++ b/scripts/desktop-action.sh@@ -15,6 +15,11 @@ case "$ACTION" ingame-storage) exec python3 "$ROOT/scripts/game-storage.py" "$@" ;;doctor) exec bash "$ROOT/scripts/doctor.sh" "$@" ;;steam-gptk) exec bash "$ROOT/scripts/steam-gptk.sh" "${1:?on or off}" ;;+ uninstall)+ case "${1:-}" in+ launcher) exec bash "$ROOT/scripts/uninstall.sh" launcher "${2:?Choose a launcher}" ;;+ all) exec bash "$ROOT/scripts/uninstall.sh" --yes ;;+ *) echo "Unknown uninstall action."; exit 64 ;; esac ;;report) exec python3 "$ROOT/scripts/report.py" "${1:-}" ;;self-update)# Detached, so it outlives the app it is about to replace.diff --git a/scripts/uninstall.sh b/scripts/uninstall.shindex ce928342a0a..427d6a436fb 100755--- a/scripts/uninstall.sh+++ b/scripts/uninstall.sh@@ -2,6 +2,8 @@# soju uninstall: remove what soju created, asking per category.# soju uninstall interactive# soju uninstall --yes remove everything without asking+# soju uninstall launcher <battlenet|steam|epic|gog|ea|rockstar|ubisoft|xbox>+# remove one launcher, its games and its app; nothing elseset -euo pipefailBASE="${SOJU_BASE:-$HOME/.battlenet-macos}"@@ -18,7 +20,7 @@ ask(){case "$a" in y|Y|yes) return 0;; *) return 1;; esac}-echo "soju uninstall: this removes things soju created. Nothing is touched without a yes."+[ "${1:-}" = launcher ] || echo "soju uninstall: this removes things soju created. Nothing is touched without a yes."# Stop only after this bottle's removal (or engine removal) was accepted.stop_bottle() {@@ -37,6 +39,44 @@ stop_bottle() {WINEPREFIX="$BASE/$b" DYLD_FALLBACK_LIBRARY_PATH="$ENGINE/lib:/usr/lib" "$ws" -w 2>/dev/null || true}+# One launcher (the app's Remove button): its bottle(s), with the games inside, and its+# ~/Applications shortcut. Engines, runtimes and the other launchers stay.+if [ "${1:-}" = launcher ]; then+ case "${2:-}" in+ battlenet) bottles=(bottle); app="Battle.net" ;;+ steam) bottles=(steam-bottle steam-gptk-bottle); app="Steam (Windows)" ;;+ epic) bottles=(epic-bottle); app="Epic Games Launcher" ;;+ gog) bottles=(gog-bottle); app="GOG GALAXY" ;;+ ea) bottles=(ea-bottle); app="EA app" ;;+ rockstar) bottles=(rockstar-bottle); app="Rockstar Games Launcher" ;;+ ubisoft) bottles=(ubisoft-bottle); app="Ubisoft Connect" ;;+ xbox) bottles=(xbox-bottle); app="" ;;+ *) echo "Choose one of the launchers."; exit 64 ;;+ esac+ found=0+ for b in "${bottles[@]}"; do+ d="$BASE/$b"+ [ -d "$d" ] || continue+ found=1+ echo "Removing $b ($(du -sh "$d" 2>/dev/null | cut -f1), with the games installed in it)…"+ if [ "$b" = xbox-bottle ]; then+ bash "$ROOT/scripts/xbox.sh" kill >/dev/null 2>&1 || true+ sh "$ROOT/scripts/xbox-wine.sh" --soju-stop-prefix 2>/dev/null || true+ fi+ stop_bottle "$b"+ # Games moved to another drive are links here: rm removes the link, not the files on the drive.+ rm -rf "$d"+ done+ [ "${2}" != steam ] || rm -f "$BASE/steam-gptk"+ l="$HOME/Applications/$app.app/Contents/MacOS/launcher"+ if [ -n "$app" ] && [ -f "$l" ] && grep -q "scripts/play.sh" "$l" && grep -qF "ENGINE=\"$ENGINE\"" "$l"; then+ rm -rf "$HOME/Applications/$app.app"; found=1+ fi+ [ "$found" = 1 ] || { echo "Nothing to remove for ${2}."; exit 0; }+ echo "Removed. Your account and purchases stay with the store; install it again from Platforms any time."+ exit 0+fi+# 2. App bundles.# Only bundles install.sh wrote for this install (their launcher script names# this engine), so a custom SOJU_BASE never removes another install's apps.diff --git a/tests/test_uninstall_launcher.py b/tests/test_uninstall_launcher.pynew file mode 100644index 00000000000..307fdd72fa7--- /dev/null+++ b/tests/test_uninstall_launcher.py@@ -0,0 +1,45 @@+import os+import subprocess+import tempfile+import unittest+from pathlib import Path++ROOT = Path(__file__).resolve().parents[1]+++class UninstallLauncher(unittest.TestCase):+ def run_action(self, base, *args):+ env = {k: v for k, v in os.environ.items() if k not in ("ENGINE", "WINEPREFIX", "SOJU_STEAM_WINE")}+ env.update(SOJU_BASE=str(base), HOME=str(base / "home"))+ return subprocess.run(["/bin/bash", str(ROOT / "scripts/desktop-action.sh"), "uninstall", *args],+ env=env, capture_output=True, text=True, timeout=30)++ def test_removes_only_that_launcher_and_keeps_moved_games(self):+ with tempfile.TemporaryDirectory() as t:+ base = Path(t)+ for b in ("gog-bottle/drive_c", "epic-bottle/drive_c", "bottle/drive_c"):+ (base / b).mkdir(parents=True)+ drive = base / "external"; drive.mkdir(); (drive / "game.bin").write_text("game")+ (base / "gog-bottle/drive_c/moved").symlink_to(drive)+ app = base / "home/Applications/GOG GALAXY.app/Contents/MacOS"; app.mkdir(parents=True)+ (app / "launcher").write_text('ENGINE="%s/cx26-engine"\nexec scripts/play.sh gog\n' % base)+ r = self.run_action(base, "launcher", "gog")+ self.assertEqual(r.returncode, 0, r.stdout + r.stderr)+ self.assertFalse((base / "gog-bottle").exists())+ self.assertFalse((base / "home/Applications/GOG GALAXY.app").exists())+ self.assertTrue((base / "epic-bottle").is_dir() and (base / "bottle").is_dir())+ self.assertEqual((drive / "game.bin").read_text(), "game")+ again = self.run_action(base, "launcher", "gog")+ self.assertEqual(again.returncode, 0)+ self.assertIn("Nothing to remove", again.stdout)++ def test_unknown_launcher_is_refused(self):+ with tempfile.TemporaryDirectory() as t:+ base = Path(t); (base / "bottle").mkdir()+ r = self.run_action(base, "launcher", "../bottle")+ self.assertEqual(r.returncode, 64)+ self.assertTrue((base / "bottle").is_dir())+++if __name__ == "__main__":+ unittest.main()