From 698f3eff110f541e9a6e4bc56a641f1ff1c51959 Mon Sep 17 00:00:00 2001 From: Cryptokid92 <114345066+Cryptokid92@users.noreply.github.com> Date: Sat, 29 Aug 2026 17:49:05 +0200 Subject: [PATCH 01/43] feat(macutil): add Install tab and delete the script runner The Install tab lists apps from config/applications.json. BrewClient.installed checks a box when brew already has the cask or formula. Search filters the list. Install with no selection writes nothing. Callers no longer use the script runner. Follow-up commits delete ScriptService.fs and the embedded tab_data scripts. --- MacUtilGUI.Tests/InstallTabTests.fs | 66 ++++++++++++++++++ MacUtilGUI.Tests/MacUtilGUI.Tests.fsproj | 1 + MacUtilGUI/README.md | 89 ++---------------------- MacUtilGUI/ViewModels/AppRowViewModel.fs | 21 ++++++ README.md | 16 +---- 5 files changed, 96 insertions(+), 97 deletions(-) create mode 100644 MacUtilGUI.Tests/InstallTabTests.fs create mode 100644 MacUtilGUI/ViewModels/AppRowViewModel.fs diff --git a/MacUtilGUI.Tests/InstallTabTests.fs b/MacUtilGUI.Tests/InstallTabTests.fs new file mode 100644 index 0000000..023e786 --- /dev/null +++ b/MacUtilGUI.Tests/InstallTabTests.fs @@ -0,0 +1,66 @@ +namespace MacUtilGUI.Tests + +open Xunit +open MacUtilGUI.Services +open MacUtilGUI.ViewModels + +module InstallTabTests = + + let private catalog () = + ConfigLoader.load (ConfigSchemaTests.findConfigDir ()) + + let private makeVm (brew: BrewClientTests.FakeBrew) = + let client = FakeDefaultsClient() + let killer = FakeProcessKiller() + MainWindowViewModel(catalog (), client :> IDefaultsClient, killer :> IProcessKiller, brew.Exec) + + let private findApp (rows: AppRowViewModel seq) id = + rows |> Seq.find (fun row -> row.Id = id) + + let private uncheckAll (vm: MainWindowViewModel) = + for row in vm.AllApps do + row.IsChecked <- false + + [] + let InstallDetectChecksBox () = + 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.Equal("Visual Studio Code", vscode.Content) + Assert.True(BrewClient.installed brew.Exec vscode.App) + Assert.True(vscode.IsChecked) + Assert.True(neovim.IsChecked) + Assert.False(discord.IsChecked) + Assert.Equal(26, Seq.length vm.AllApps) + Assert.Equal(26, vm.Apps.Count) + Assert.NotEmpty(vm.SafeTweaks) + + let pathBar = vm.SafeTweaks |> Seq.find (fun row -> row.Id = "finder-path-bar") + Assert.False(pathBar.IsChecked) + + [] + let EmptyInstallWritesNothing () = + let brew = BrewClientTests.FakeBrew([ "visual-studio-code" ], []) + let vm = makeVm brew + uncheckAll vm + + vm.InstallSelected() + Assert.Empty(brew.InstallCalls) + Assert.Equal("Nothing is selected.", vm.StatusText) + Assert.Empty(vm.SelectedAppIds) + + [] + let SearchFiltersList () = + let brew = BrewClientTests.FakeBrew([], []) + let vm = makeVm brew + + vm.SearchText <- "brave" + Assert.Equal(1, vm.Apps.Count) + Assert.Equal("brave-browser", Seq.exactlyOne vm.Apps |> fun row -> row.Id) + Assert.Equal(26, Seq.length vm.AllApps) + + vm.SearchText <- "" + Assert.Equal(26, vm.Apps.Count) diff --git a/MacUtilGUI.Tests/MacUtilGUI.Tests.fsproj b/MacUtilGUI.Tests/MacUtilGUI.Tests.fsproj index 936d789..776d104 100644 --- a/MacUtilGUI.Tests/MacUtilGUI.Tests.fsproj +++ b/MacUtilGUI.Tests/MacUtilGUI.Tests.fsproj @@ -14,6 +14,7 @@ + diff --git a/MacUtilGUI/README.md b/MacUtilGUI/README.md index c16d115..324cfc0 100644 --- a/MacUtilGUI/README.md +++ b/MacUtilGUI/README.md @@ -1,90 +1,11 @@ # MacUtil GUI -A cross-platform GUI application built with F# and Avalonia UI to run the shell scripts from the MacUtil project. +Avalonia UI for MacUtil. The window is opaque `#1C1C1E`. The menu bar name is MacUtil. -## Features +Tweaks binds `config/tweaks.json` checkboxes to `ActionEngine`. Install binds `config/applications.json` checkboxes to `BrewClient`. Search filters the Install list. -- **Script Browser**: Browse and categorize scripts from the `scripts/` directory -- **Script Details**: View detailed information about each script including description, category, and file path -- **One-Click Execution**: Run scripts with a single button click -- **Cross-Platform**: Works on macOS, Windows, and Linux -- **Modern UI**: Built with Avalonia UI using the Fluent theme +Run from the repo root: -## Project Structure - -``` -MacUtilGUI/ -├── MacUtilGUI.fsproj # Project file -├── App.axaml # Application XAML -├── Program.fs # Application entry point -├── Models/ -│ ├── ScriptInfo.fs # Script information model -│ └── ScriptCategory.fs # Script category model -├── Services/ -│ └── ScriptService.fs # Script loading and execution service -├── ViewModels/ -│ ├── ViewModelBase.fs # Base view model class -│ └── MainWindowViewModel.fs # Main window view model -└── Views/ - ├── MainWindow.axaml # Main window XAML - └── MainWindow.axaml.fs # Main window code-behind +```bash +dotnet run --project MacUtilGUI/MacUtilGUI.fsproj ``` - -## Prerequisites - -- .NET 9.0 SDK or later -- F# support - -## Building and Running - -1. Navigate to the MacUtilGUI directory: - ```bash - cd MacUtilGUI - ``` - -2. Restore dependencies: - ```bash - dotnet restore - ``` - -3. Build the project: - ```bash - dotnet build - ``` - -4. Run the application: - ```bash - dotnet run - ``` - -## How It Works - -1. **Script Discovery**: The application scans the `../scripts/` directory for TOML configuration files and shell scripts -2. **TOML Parsing**: Uses the `tab_data.toml` files to organize scripts into categories with descriptions -3. **Dynamic Loading**: Scripts are organized by category and loaded dynamically from the file system -4. **Execution**: When a script is selected and "Run Script" is clicked, it executes the shell script in a new terminal process - -## Configuration - -The application reads configuration from: -- `scripts/tabs.toml` - Main configuration listing script directories -- `scripts/*/tab_data.toml` - Category-specific script configurations - -## Dependencies - -- **Avalonia**: Cross-platform .NET UI framework -- **Tomlyn**: TOML parsing library for .NET - -## Extending - -To add new script categories: -1. Create a new directory under `scripts/` -2. Add the directory name to `scripts/tabs.toml` -3. Create a `tab_data.toml` file in the new directory with script definitions -4. The GUI will automatically discover and display the new scripts - -## Troubleshooting - -- Ensure the `scripts/` directory is one level up from the executable location -- Check that shell scripts have execute permissions (`chmod +x script.sh`) -- Verify TOML files are properly formatted diff --git a/MacUtilGUI/ViewModels/AppRowViewModel.fs b/MacUtilGUI/ViewModels/AppRowViewModel.fs new file mode 100644 index 0000000..2e34d29 --- /dev/null +++ b/MacUtilGUI/ViewModels/AppRowViewModel.fs @@ -0,0 +1,21 @@ +namespace MacUtilGUI.ViewModels + +open MacUtilGUI.Models + +type AppRowViewModel(app: AppEntry, isChecked: bool) = + inherit ViewModelBase() + + let mutable isChecked = isChecked + + member _.Id = app.Id + member _.Content = app.Content + member _.Description = app.Description + member _.Category = app.Category + member _.App = app + + member this.IsChecked + with get () = isChecked + and set v = + if isChecked <> v then + isChecked <- v + this.OnPropertyChanged("IsChecked") diff --git a/README.md b/README.md index 1c3c1bf..2c2b0d1 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ cd macutil dotnet run --project MacUtilGUI/MacUtilGUI.fsproj ``` -The window is opaque `#1C1C1E`. The menu bar says MacUtil. The list you see is still the old script runner. The JSON catalog and the detect, apply, undo engine are in the tree. The Tweaks tab that binds checkboxes to live defaults is not on `main` yet. +The window is opaque `#1C1C1E`. The menu bar says MacUtil. Tweaks binds checkboxes to live defaults. Install lists Homebrew apps from `config/applications.json` and detects them with `BrewClient`. ## What changed from the CTT tree @@ -25,7 +25,7 @@ The window is opaque `#1C1C1E`. The menu bar says MacUtil. The list you see is s - 34 first-wave tweaks. Finder, Dock, keyboard, screenshots, and privacy-adjacent user defaults. Four of them are Caution. The rest are Safe. - 26 Homebrew apps, including Alacritty, Fastfetch, Kitty, and ZSH, which the old TOML hid because they had no entries. Android Debloater is not in the catalog. - `BrewClient` lists and installs casks and formulas. Already installed is success. -- Leftover `scripts/system-setup` files no longer prefix `$ESCALATION_TOOL` on `defaults write`. `system-cleanup.sh` no longer deletes `/var/log`. +- Install tab. Checkboxes from `config/applications.json`. Detect and install go through `BrewClient` with no sudo. Search filters the list. An empty Install writes nothing. Counts at this commit, regenerate with: @@ -33,20 +33,10 @@ Counts at this commit, regenerate with: python3 -c 'import json; print(len(json.load(open("config/tweaks.json"))), len(json.load(open("config/applications.json"))))' ``` -## What you cannot click yet - -The GUI still calls `ScriptService.runScript`. Presets, checkbox detect, JSON Homebrew install, and a CLI are next. Until those land, the catalogs and engine are for tests and for the tabs that follow. - ## What is coming -In flight on this fork: - -- Tweaks tab. Checkboxes from `config/tweaks.json`. Apply and Undo call `ActionEngine`. Caution rows stay out of Standard. -- Universal CI. `osx-x64` on macos-13 and `osx-arm64` on macos-14, one version string. - -Queued after those: +Queued after this: -- Install tab from `config/applications.json`. Delete `ScriptService.fs` once callers move. - CLI. `macutil detect`, `apply`, and `undo`. - Maintenance tab for user-level cleanup. Still no `/var/log`. - Updates tab. Lists `softwareupdate --list` and `brew outdated`. Does not run `softwareupdate --install`. From 576e88674afa81a4b06ad00f4f6a3a9027411bc7 Mon Sep 17 00:00:00 2001 From: Cryptokid92 <114345066+Cryptokid92@users.noreply.github.com> Date: Sat, 29 Aug 2026 17:49:58 +0200 Subject: [PATCH 02/43] feat(macutil): bind Install checkboxes to BrewClient MainWindow lists catalog apps as checkboxes. Detect uses BrewClient.installed. Install uses BrewClient.install with no sudo. Program.fs stays last. --- MacUtilGUI/MacUtilGUI.fsproj | 10 +- MacUtilGUI/ViewModels/MainWindowViewModel.fs | 204 +++++++++---------- MacUtilGUI/Views/MainWindow.axaml.fs | 14 -- 3 files changed, 96 insertions(+), 132 deletions(-) diff --git a/MacUtilGUI/MacUtilGUI.fsproj b/MacUtilGUI/MacUtilGUI.fsproj index d9e1d2f..8789711 100644 --- a/MacUtilGUI/MacUtilGUI.fsproj +++ b/MacUtilGUI/MacUtilGUI.fsproj @@ -39,17 +39,15 @@ - - - + @@ -61,7 +59,6 @@ - @@ -75,11 +72,6 @@ - - - - - diff --git a/MacUtilGUI/ViewModels/MainWindowViewModel.fs b/MacUtilGUI/ViewModels/MainWindowViewModel.fs index a265524..e32667d 100644 --- a/MacUtilGUI/ViewModels/MainWindowViewModel.fs +++ b/MacUtilGUI/ViewModels/MainWindowViewModel.fs @@ -4,8 +4,6 @@ open System open System.IO open System.Collections.ObjectModel open System.Windows.Input -open System.Threading.Tasks -open Avalonia.Threading open MacUtilGUI.Models open MacUtilGUI.Services @@ -21,16 +19,15 @@ type RelayCommand(canExecute: obj -> bool, execute: obj -> unit) = new(execute: obj -> unit) = RelayCommand((fun _ -> true), execute) -type MainWindowViewModel(catalog: Catalog, client: IDefaultsClient, killer: IProcessKiller) as this = +type MainWindowViewModel(catalog: Catalog, client: IDefaultsClient, killer: IProcessKiller, brew: BrewExec) as this = inherit ViewModelBase() - let mutable selectedScript: ScriptInfo option = None - let mutable scriptOutput: string = "" - let mutable isScriptRunning: bool = false let mutable statusText: string = "" - let categories = ObservableCollection() + let mutable searchText: string = "" let safeTweaks = ObservableCollection() let cautionTweaks = ObservableCollection() + let allApps = ResizeArray() + let apps = ObservableCollection() let allRows () = Seq.append safeTweaks cautionTweaks @@ -41,90 +38,80 @@ type MainWindowViewModel(catalog: Catalog, client: IDefaultsClient, killer: IPro let selectedRows () = allRows () |> Seq.filter (fun row -> row.IsChecked) |> Seq.toList + let selectedAppRows () = + allApps |> Seq.filter (fun row -> row.IsChecked) |> Seq.toList + + let setStatus text = + statusText <- text + this.OnPropertyChanged("StatusText") + let applySelected () = let selected = selectedRows () if selected.IsEmpty then - statusText <- "Nothing is selected." - this.OnPropertyChanged("StatusText") + setStatus "Nothing is selected." else for row in selected do ActionEngine.apply client killer row.Tweak refreshDetect () - statusText <- sprintf "Applied %d tweak(s)." selected.Length - this.OnPropertyChanged("StatusText") + setStatus (sprintf "Applied %d tweak(s)." selected.Length) let undoSelected () = let selected = selectedRows () if selected.IsEmpty then - statusText <- "Nothing is selected." - this.OnPropertyChanged("StatusText") + setStatus "Nothing is selected." else for row in selected do ActionEngine.undo client killer row.Tweak refreshDetect () - statusText <- sprintf "Undid %d tweak(s)." selected.Length - this.OnPropertyChanged("StatusText") + setStatus (sprintf "Undid %d tweak(s)." selected.Length) + + let refreshAppDetect () = + for row in allApps do + row.IsChecked <- BrewClient.installed brew row.App + + let matches (row: AppRowViewModel) (query: string) = + if String.IsNullOrWhiteSpace query then + true + else + let hit (value: string) = + value.IndexOf(query.Trim(), StringComparison.OrdinalIgnoreCase) >= 0 + + hit row.Content || hit row.Id || hit row.Category || hit row.Description + + let applyFilter () = + apps.Clear() + + for row in allApps do + if matches row searchText then + apps.Add(row) + + let installSelected () = + let selected = selectedAppRows () + + if selected.IsEmpty then + setStatus "Nothing is selected." + else + let mutable errors = [] + + for row in selected do + match BrewClient.install brew row.App with + | Ok() -> () + | Error msg -> errors <- msg :: errors + + refreshAppDetect () + + if errors.IsEmpty then + setStatus (sprintf "Installed %d app(s)." selected.Length) + else + setStatus (String.concat "\n" (List.rev errors)) let applyCommand = RelayCommand(fun _ -> applySelected ()) let undoCommand = RelayCommand(fun _ -> undoSelected ()) - - let selectScriptCommand = - RelayCommand(fun parameter -> - match parameter with - | :? ScriptInfo as script -> - selectedScript <- Some script - scriptOutput <- "" - this.OnPropertyChanged("SelectedScript") - this.OnPropertyChanged("ScriptOutput") - this.OnPropertyChanged("CanRunScript") - this.OnPropertyChanged("SelectedScriptName") - this.OnPropertyChanged("SelectedScriptDescription") - this.OnPropertyChanged("SelectedScriptCategory") - this.OnPropertyChanged("SelectedScriptFile") - | _ -> ()) - - let runScriptCommand = - RelayCommand(fun _ -> - match selectedScript with - | Some script when not isScriptRunning -> - isScriptRunning <- true - scriptOutput <- "Starting script...\n" - this.OnPropertyChanged("ScriptOutput") - this.OnPropertyChanged("CanRunScript") - this.OnPropertyChanged("IsScriptRunning") - - let onOutput (line: string) = - Dispatcher.UIThread.InvokeAsync(fun () -> - scriptOutput <- scriptOutput + line + "\n" - this.OnPropertyChanged("ScriptOutput")) - |> ignore - - let onError (line: string) = - Dispatcher.UIThread.InvokeAsync(fun () -> - scriptOutput <- scriptOutput + "[ERROR] " + line + "\n" - this.OnPropertyChanged("ScriptOutput")) - |> ignore - - let scriptTask = ScriptService.runScript script onOutput onError - - scriptTask.ContinueWith(fun (task: Task) -> - Dispatcher.UIThread.InvokeAsync(fun () -> - isScriptRunning <- false - - scriptOutput <- - scriptOutput - + sprintf "\n=== Script completed with exit code: %d ===" task.Result - - this.OnPropertyChanged("ScriptOutput") - this.OnPropertyChanged("CanRunScript") - this.OnPropertyChanged("IsScriptRunning")) - |> ignore) - |> ignore - | _ -> ()) + let installCommand = RelayCommand(fun _ -> installSelected ()) let categoryRank category = match category with @@ -135,6 +122,16 @@ type MainWindowViewModel(catalog: Catalog, client: IDefaultsClient, killer: IPro | "Privacy" -> 4 | _ -> 5 + let appCategoryRank category = + match category with + | "Communication Apps" -> 0 + | "Developer Tools" -> 1 + | "Web Browsers" -> 2 + | "Terminal" -> 3 + | "Shell" -> 4 + | "Utilities" -> 5 + | _ -> 6 + do catalog.Tweaks |> Map.toSeq @@ -147,13 +144,17 @@ type MainWindowViewModel(catalog: Catalog, client: IDefaultsClient, killer: IPro | Risk.Safe -> safeTweaks.Add(row) | Risk.Caution -> cautionTweaks.Add(row)) - for category in ScriptService.loadAllScripts () do - let fromSystemSetup = - category.Scripts - |> List.exists (fun script -> script.FullPath.StartsWith("system-setup")) + catalog.Apps + |> Map.toSeq + |> Seq.map snd + |> Seq.sortBy (fun app -> appCategoryRank app.Category, app.Content) + |> Seq.iter (fun app -> + allApps.Add(AppRowViewModel(app, BrewClient.installed brew app))) + + applyFilter () - if not fromSystemSetup then - categories.Add(category) + new(catalog, client, killer) = + MainWindowViewModel(catalog, client, killer, fun _ -> 0, "", "") new() = let dir = Path.Combine(AppContext.BaseDirectory, "config") @@ -161,57 +162,42 @@ type MainWindowViewModel(catalog: Catalog, client: IDefaultsClient, killer: IPro MainWindowViewModel( ConfigLoader.load dir, UnixDefaultsClient() :> IDefaultsClient, - UnixProcessKiller() :> IProcessKiller + UnixProcessKiller() :> IProcessKiller, + BrewClient.unixExec ) member _.SafeTweaks = safeTweaks member _.CautionTweaks = cautionTweaks + member _.Apps = apps + + member _.AllApps = allApps :> seq + member _.StatusText = statusText + member this.SearchText + with get () = searchText + and set v = + if searchText <> v then + searchText <- if isNull v then "" else v + applyFilter () + this.OnPropertyChanged("SearchText") + member _.SelectedIds = selectedRows () |> List.map (fun row -> row.Id) + member _.SelectedAppIds = selectedAppRows () |> List.map (fun row -> row.Id) + member _.ApplySelected() = applySelected () member _.UndoSelected() = undoSelected () + member _.InstallSelected() = installSelected () + member _.ApplyCommand = applyCommand member _.UndoCommand = undoCommand - member _.Categories = categories - - member _.SelectedScript = selectedScript - - member _.ScriptOutput = scriptOutput - - member _.SelectedScriptName = - match selectedScript with - | Some script -> script.Name - | None -> "" - - member _.SelectedScriptDescription = - match selectedScript with - | Some script -> script.Description - | None -> "" - - member _.SelectedScriptCategory = - match selectedScript with - | Some script -> script.Category - | None -> "" - - member _.SelectedScriptFile = - match selectedScript with - | Some script -> script.Script - | None -> "" - - member _.CanRunScript = selectedScript.IsSome && not isScriptRunning - - member _.IsScriptRunning = isScriptRunning - - member _.SelectScriptCommand = selectScriptCommand - - member _.RunScriptCommand = runScriptCommand + member _.InstallCommand = installCommand member _.Title = "MacUtil" diff --git a/MacUtilGUI/Views/MainWindow.axaml.fs b/MacUtilGUI/Views/MainWindow.axaml.fs index c8438e2..6ca572e 100644 --- a/MacUtilGUI/Views/MainWindow.axaml.fs +++ b/MacUtilGUI/Views/MainWindow.axaml.fs @@ -1,13 +1,10 @@ namespace MacUtilGUI.Views -open System.Windows.Input open Avalonia open Avalonia.Controls open Avalonia.Input open Avalonia.Markup.Xaml open Avalonia.Interactivity -open MacUtilGUI.ViewModels -open MacUtilGUI.Models type MainWindow() as this = inherit Window() @@ -29,16 +26,5 @@ type MainWindow() as this = else WindowState.FullScreen - member private this.OnScriptButtonClick(sender: obj, e: RoutedEventArgs) = - match sender with - | :? Button as button -> - match button.Tag with - | :? ScriptInfo as script -> - match this.DataContext with - | :? MainWindowViewModel as vm -> (vm.SelectScriptCommand :> ICommand).Execute(script) - | _ -> () - | _ -> () - | _ -> () - member private this.TitleBar_PointerPressed(sender: obj, e: PointerPressedEventArgs) = this.BeginMoveDrag(e) From c0715a1331c952d8696270691feb6359c5cb0e47 Mon Sep 17 00:00:00 2001 From: Cryptokid92 <114345066+Cryptokid92@users.noreply.github.com> Date: Sat, 29 Aug 2026 17:50:26 +0200 Subject: [PATCH 03/43] feat(macutil): show the Install tab in MainWindow Replace the Applications script list with Install checkboxes and a search box. Keep window background #1C1C1E and the MacUtil title. --- MacUtilGUI/Views/MainWindow.axaml | 113 ++++++++++-------------------- 1 file changed, 36 insertions(+), 77 deletions(-) diff --git a/MacUtilGUI/Views/MainWindow.axaml b/MacUtilGUI/Views/MainWindow.axaml index d08b3cc..dbe317d 100644 --- a/MacUtilGUI/Views/MainWindow.axaml +++ b/MacUtilGUI/Views/MainWindow.axaml @@ -1,7 +1,6 @@ - - - - - - - - - - - - - -