Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion MacUtilGUI.Tests/InstallTabTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,51 @@ module InstallTabTests =

vm.SearchText <- "brave"
Assert.Equal(1, vm.Apps.Count)
Assert.Equal("brave-browser", Seq.exactlyOne vm.Apps |> fun row -> row.Id)
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)

[<Fact>]
let InstallGroupsByCategory () =
let brew = BrewClientTests.FakeBrew([], [])
let vm = makeVm brew

let names = vm.AppGroups |> Seq.map (fun group -> group.Name) |> Seq.toList

Assert.Equal<string list>(
[ "Communication Apps"
"Developer Tools"
"Web Browsers"
"Terminal"
"Shell"
"Utilities" ],
names
)

Assert.Equal(26, vm.AppGroups |> Seq.sumBy (fun group -> group.Apps.Count))
Assert.Equal(26, vm.Apps.Count)

vm.SearchText <- "brave"
Assert.Equal(1, vm.AppGroups.Count)
let browsers = Seq.exactlyOne vm.AppGroups
Assert.Equal("Web Browsers", browsers.Name)
Assert.Equal("brave-browser", (Seq.exactlyOne browsers.Apps).Id)
Assert.Equal(1, vm.Apps.Count)

vm.SearchText <- "no-such-app"
Assert.Empty(vm.AppGroups)
Assert.Equal(0, vm.Apps.Count)

vm.SearchText <- ""
uncheckAll vm
let comm = vm.AppGroups |> Seq.find (fun group -> group.Name = "Communication Apps")

comm.AllSelected <- true
Assert.True(comm.Apps |> Seq.forall (fun row -> row.IsChecked))
Assert.True(comm.AllSelected)

comm.AllSelected <- false
Assert.True(comm.Apps |> Seq.forall (fun row -> not row.IsChecked))
Assert.False(comm.AllSelected)
6 changes: 6 additions & 0 deletions MacUtilGUI/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,11 @@
<Setter Property="CaretBrush" Value="#FFFFFF"/>
<Setter Property="Padding" Value="10,8"/>
</Style>

<Style Selector="Expander">
<Setter Property="Foreground" Value="#FFFFFF"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
</Style>
</Application.Styles>
</Application>
1 change: 1 addition & 0 deletions MacUtilGUI/MacUtilGUI.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<Compile Include="ViewModels\ViewModelBase.fs" />
<Compile Include="ViewModels\TweakRowViewModel.fs" />
<Compile Include="ViewModels\AppRowViewModel.fs" />
<Compile Include="ViewModels\AppGroupViewModel.fs" />
<Compile Include="ViewModels\UpdateRowViewModel.fs" />
<Compile Include="ViewModels\MainWindowViewModel.fs" />
<Compile Include="Views\MainWindow.axaml.fs" />
Expand Down
20 changes: 20 additions & 0 deletions MacUtilGUI/ViewModels/AppGroupViewModel.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace MacUtilGUI.ViewModels

open System.Collections.ObjectModel

type AppGroupViewModel(name: string, rows: AppRowViewModel seq) =
inherit ViewModelBase()

let apps = ObservableCollection<AppRowViewModel>(rows)

member _.Name = name

member _.Apps = apps

member this.AllSelected
with get () = apps.Count > 0 && Seq.forall (fun (row: AppRowViewModel) -> row.IsChecked) apps
and set v =
for row in apps do
row.IsChecked <- v

this.OnPropertyChanged("AllSelected")
37 changes: 24 additions & 13 deletions MacUtilGUI/ViewModels/MainWindowViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type MainWindowViewModel
let cautionTweaks = ObservableCollection<TweakRowViewModel>()
let allApps = ResizeArray<AppRowViewModel>()
let apps = ObservableCollection<AppRowViewModel>()
let appGroups = ObservableCollection<AppGroupViewModel>()
let appleUpdates = ObservableCollection<AppleUpdateRowViewModel>()
let brewOutdated = ObservableCollection<BrewOutdatedRowViewModel>()

Expand Down Expand Up @@ -92,12 +93,30 @@ type MainWindowViewModel

hit row.Content || hit row.Id || hit row.Category || hit row.Description

let appCategoryRank category =
match category with
| "Communication Apps" -> 0
| "Developer Tools" -> 1
| "Web Browsers" -> 2
| "Terminal" -> 3
| "Shell" -> 4
| "Utilities" -> 5
| _ -> 6

let applyFilter () =
apps.Clear()
appGroups.Clear()

for row in allApps do
if matches row searchText then
apps.Add(row)
let visible =
allApps |> Seq.filter (fun row -> matches row searchText) |> Seq.toList

for row in visible do
apps.Add(row)

visible
|> List.groupBy (fun row -> row.Category)
|> List.sortBy (fun (category, _) -> appCategoryRank category, category)
|> List.iter (fun (category, rows) -> appGroups.Add(AppGroupViewModel(category, rows)))

let installSelected () =
let selected = selectedAppRows ()
Expand Down Expand Up @@ -213,16 +232,6 @@ type MainWindowViewModel
| "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
Expand Down Expand Up @@ -270,6 +279,8 @@ type MainWindowViewModel

member _.Apps = apps

member _.AppGroups = appGroups

member _.AllApps = allApps :> seq<AppRowViewModel>

member _.StatusText = statusText
Expand Down
47 changes: 35 additions & 12 deletions MacUtilGUI/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,43 @@
Classes="macos-search"
Margin="24,16,24,8"/>
<ScrollViewer Grid.Row="1" Margin="24,0,24,8">
<ItemsControl ItemsSource="{Binding Apps}">
<ItemsControl ItemsSource="{Binding AppGroups}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:AppRowViewModel">
<CheckBox Classes="macos-tweak"
IsChecked="{Binding IsChecked, Mode=TwoWay}"
<DataTemplate x:DataType="vm:AppGroupViewModel">
<Expander IsExpanded="True"
HorizontalAlignment="Stretch"
Margin="0,0,0,8">
<StackPanel>
<TextBlock Text="{Binding Content}" Classes="macos-body"/>
<TextBlock Text="{Binding Description}"
Classes="macos-secondary"
FontSize="11"
TextWrapping="Wrap"/>
</StackPanel>
</CheckBox>
<Expander.Header>
<DockPanel>
<CheckBox DockPanel.Dock="Left"
Classes="macos-tweak"
IsChecked="{Binding AllSelected, Mode=TwoWay}"
VerticalAlignment="Center"/>
<TextBlock Text="{Binding Name}"
Classes="macos-title"
FontSize="16"
VerticalAlignment="Center"
Margin="8,0,0,0"/>
</DockPanel>
</Expander.Header>
<ItemsControl ItemsSource="{Binding Apps}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:AppRowViewModel">
<CheckBox Classes="macos-tweak"
IsChecked="{Binding IsChecked, Mode=TwoWay}"
Margin="0,0,0,8">
<StackPanel>
<TextBlock Text="{Binding Content}" Classes="macos-body"/>
<TextBlock Text="{Binding Description}"
Classes="macos-secondary"
FontSize="11"
TextWrapping="Wrap"/>
</StackPanel>
</CheckBox>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Expander>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Expand Down
Loading