From b702b584d891d3e454b5d25a0da021c97b4b2794 Mon Sep 17 00:00:00 2001 From: Cryptokid92 <114345066+Cryptokid92@users.noreply.github.com> Date: Sun, 30 Aug 2026 01:24:20 +0200 Subject: [PATCH 1/3] feat(macutil): uninstall selected Homebrew apps Catalog casks and formulas only. A missing package is success. --- MacUtilGUI.Tests/BrewClientTests.fs | 35 +++++++++++++++++++++++++++++ MacUtilGUI.Tests/InstallTabTests.fs | 31 +++++++++++++++++++++++++ MacUtilGUI/Services/BrewClient.fs | 23 +++++++++++++++++++ 3 files changed, 89 insertions(+) diff --git a/MacUtilGUI.Tests/BrewClientTests.fs b/MacUtilGUI.Tests/BrewClientTests.fs index 4573d41..4a3e722 100644 --- a/MacUtilGUI.Tests/BrewClientTests.fs +++ b/MacUtilGUI.Tests/BrewClientTests.fs @@ -7,11 +7,17 @@ open MacUtilGUI.Services module BrewClientTests = type FakeBrew(casks: string list, formulas: string list, ?outdated: string list) = + let mutable casks = casks + let mutable formulas = formulas let outdated = defaultArg outdated [] let calls = ResizeArray() member _.Calls = List.ofSeq calls + member _.SetCasks xs = casks <- xs + + member _.SetFormulas xs = formulas <- xs + member _.InstallCalls = calls |> Seq.filter (fun args -> @@ -20,6 +26,14 @@ module BrewClientTests = | _ -> false) |> Seq.toList + member _.UninstallCalls = + calls + |> Seq.filter (fun args -> + match args with + | "uninstall" :: _ -> true + | _ -> false) + |> Seq.toList + member _.UpgradeCalls = calls |> Seq.filter (fun args -> @@ -37,6 +51,7 @@ module BrewClientTests = | [ "outdated" ] | [ "outdated"; "--verbose" ] -> 0, String.concat "\n" outdated, "" | "install" :: _ -> 0, "", "" + | "uninstall" :: _ -> 0, "", "" | "upgrade" :: _ -> 0, "", "" | _ -> 1, "", "unexpected brew args" @@ -67,3 +82,23 @@ module BrewClientTests = | Error msg -> Assert.Fail msg Assert.Empty(brew.InstallCalls) + + [] + let UninstallMissingIsOk () = + let brew = FakeBrew([], []) + + match BrewClient.uninstall brew.Exec vscode with + | Ok() -> () + | Error msg -> Assert.Fail msg + + Assert.Empty(brew.UninstallCalls) + + [] + let UninstallUsesCaskToken () = + let brew = FakeBrew([ "visual-studio-code" ], []) + + match BrewClient.uninstall brew.Exec vscode with + | Ok() -> () + | Error msg -> Assert.Fail msg + + Assert.Contains([ "uninstall"; "--cask"; "visual-studio-code" ], brew.UninstallCalls) diff --git a/MacUtilGUI.Tests/InstallTabTests.fs b/MacUtilGUI.Tests/InstallTabTests.fs index f8c92ce..150a1c2 100644 --- a/MacUtilGUI.Tests/InstallTabTests.fs +++ b/MacUtilGUI.Tests/InstallTabTests.fs @@ -52,6 +52,37 @@ module InstallTabTests = Assert.Equal("Nothing is selected.", vm.StatusText) Assert.Empty(vm.SelectedAppIds) + [] + let EmptyUninstallWritesNothing () = + let brew = BrewClientTests.FakeBrew([ "visual-studio-code" ], []) + let vm = makeVm brew + uncheckAll vm + + vm.UninstallSelected() + Assert.Empty(brew.UninstallCalls) + Assert.Equal("Nothing is selected.", vm.StatusText) + Assert.Empty(vm.SelectedAppIds) + + [] + let RefreshDetectChecksBox () = + let brew = BrewClientTests.FakeBrew([ "visual-studio-code" ], [ "neovim" ]) + let vm = makeVm brew + let vscode = findApp vm.AllApps "visual-studio-code" + let neovim = findApp vm.AllApps "neovim" + let discord = findApp vm.AllApps "discord" + + Assert.True(vscode.IsChecked) + Assert.True(neovim.IsChecked) + Assert.False(discord.IsChecked) + + brew.SetCasks [] + brew.SetFormulas [ "neovim" ] + vm.RefreshInstalled() + + Assert.False(vscode.IsChecked) + Assert.True(neovim.IsChecked) + Assert.False(discord.IsChecked) + [] let SearchFiltersList () = let brew = BrewClientTests.FakeBrew([], []) diff --git a/MacUtilGUI/Services/BrewClient.fs b/MacUtilGUI/Services/BrewClient.fs index 5e44d49..163f444 100644 --- a/MacUtilGUI/Services/BrewClient.fs +++ b/MacUtilGUI/Services/BrewClient.fs @@ -55,6 +55,29 @@ module BrewClient = Ok() | _, _, stderr -> Error(stderr.Trim()) + let uninstall (exec: BrewExec) (app: AppEntry) = + if not (installed exec app) then + Ok() + else + match pkg app with + | None -> Error $"App '{app.Id}' has no cask or formula" + | Some token -> + let args = + match token with + | Cask name -> [ "uninstall"; "--cask"; name ] + | Formula name -> [ "uninstall"; "--formula"; name ] + + match exec args with + | 0, _, _ -> Ok() + | _, _, stderr when + stderr.IndexOf("not installed", StringComparison.OrdinalIgnoreCase) + >= 0 + || stderr.IndexOf("No such keg", StringComparison.OrdinalIgnoreCase) + >= 0 + -> + Ok() + | _, _, stderr -> Error(stderr.Trim()) + let private brewPath () = [ "/opt/homebrew/bin/brew"; "/usr/local/bin/brew" ] |> List.tryFind File.Exists From 92edeb72105b168f8f6935465987530ef1b92b69 Mon Sep 17 00:00:00 2001 From: Cryptokid92 <114345066+Cryptokid92@users.noreply.github.com> Date: Sun, 30 Aug 2026 01:25:13 +0200 Subject: [PATCH 2/3] feat(macutil): add Uninstall and Refresh on Install --- MacUtilGUI/ViewModels/MainWindowViewModel.fs | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/MacUtilGUI/ViewModels/MainWindowViewModel.fs b/MacUtilGUI/ViewModels/MainWindowViewModel.fs index 4dbb78b..4e43d30 100644 --- a/MacUtilGUI/ViewModels/MainWindowViewModel.fs +++ b/MacUtilGUI/ViewModels/MainWindowViewModel.fs @@ -140,6 +140,30 @@ type MainWindowViewModel else setStatus (String.concat "\n" (List.rev errors)) + let uninstallSelected () = + let selected = selectedAppRows () + + if selected.IsEmpty then + setStatus "Nothing is selected." + else + let mutable errors = [] + + for row in selected do + match BrewClient.uninstall brew row.App with + | Ok() -> () + | Error msg -> errors <- msg :: errors + + refreshAppDetect () + + if errors.IsEmpty then + setStatus (sprintf "Uninstalled %d app(s)." selected.Length) + else + setStatus (String.concat "\n" (List.rev errors)) + + let refreshInstalled () = + refreshAppDetect () + setStatus "Refreshed installed apps." + let selectIds (ids: string list) = let wanted = Set.ofList ids @@ -216,6 +240,8 @@ type MainWindowViewModel let applyCommand = RelayCommand(fun _ -> applySelected ()) let undoCommand = RelayCommand(fun _ -> undoSelected ()) let installCommand = RelayCommand(fun _ -> installSelected ()) + let uninstallCommand = RelayCommand(fun _ -> uninstallSelected ()) + let refreshInstalledCommand = RelayCommand(fun _ -> refreshInstalled ()) let selectStandardCommand = RelayCommand(fun _ -> selectPreset "Standard") let selectMinimalCommand = RelayCommand(fun _ -> selectPreset "Minimal") let brewUpdateCommand = RelayCommand(fun _ -> runMaintenance BrewUpdate) @@ -320,6 +346,10 @@ type MainWindowViewModel member _.InstallSelected() = installSelected () + member _.UninstallSelected() = uninstallSelected () + + member _.RefreshInstalled() = refreshInstalled () + member _.RunBrewUpdate() = runMaintenance BrewUpdate member _.RunBrewCleanup() = runMaintenance BrewCleanup @@ -342,6 +372,10 @@ type MainWindowViewModel member _.InstallCommand = installCommand + member _.UninstallCommand = uninstallCommand + + member _.RefreshInstalledCommand = refreshInstalledCommand + member _.SelectStandardCommand = selectStandardCommand member _.SelectMinimalCommand = selectMinimalCommand From 5a5a24d142e38a75bbc2fb0b3bb5081990d3d475 Mon Sep 17 00:00:00 2001 From: Cryptokid92 <114345066+Cryptokid92@users.noreply.github.com> Date: Sun, 30 Aug 2026 01:26:14 +0200 Subject: [PATCH 3/3] feat(macutil): show Uninstall and Refresh on Install --- MacUtilGUI/Views/MainWindow.axaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MacUtilGUI/Views/MainWindow.axaml b/MacUtilGUI/Views/MainWindow.axaml index 52684f3..024b084 100644 --- a/MacUtilGUI/Views/MainWindow.axaml +++ b/MacUtilGUI/Views/MainWindow.axaml @@ -223,6 +223,14 @@ Command="{Binding InstallCommand}" Classes="macos-accent" Padding="20,10"/> +