Files
BrewUI/Brew/Features/MainWindow/Views/MainWindowView.swift
T
Graeme ArthurandClaude Opus 4.7 e638aba02c Extract BrewAppEnvironment package for the SwiftUI env keys
Move the @Entry repository environment keys + their Unimplemented trap
defaults out of BrewRepositoryInterfaces into a new MainActor + SwiftUI
BrewAppEnvironment package (deps: BrewCore, BrewRepositoryInterfaces).
This frees BrewRepositoryInterfaces of any SwiftUI dependency so it can
flip to a nonisolated default next; the env keys must stay in a
MainActor-default package because @Entry's generated EnvironmentKey
defaultValue constructs MainActor trap defaults. Pure relocation +
rewiring — no behaviour change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-29 16:27:55 +10:00

75 lines
2.7 KiB
Swift

import AppKit
import BrewAppEnvironment
import BrewFeatureConsole
import BrewFeatureDiscover
import BrewFeatureInstalled
import BrewUIComponents
import SwiftUI
struct MainWindowView: View {
@State var selectedSidebarItem: SidebarItem = .installed
@SceneStorage("consoleExpanded") private var consoleExpanded: Bool = false
@SceneStorage("consoleHeight") private var consoleHeight: Double = BrewLayout.consoleDefaultExpandedHeight
var body: some View {
AnimatedSplit(
collapsed: !consoleExpanded,
collapsedHeight: BrewLayout.consoleCollapsedHeight,
expandedHeight: consoleHeight,
minExpandedHeight: BrewLayout.consoleMinExpandedHeight,
maxExpandedHeight: BrewLayout.consoleMaxExpandedHeight,
animation: .brewFast,
) {
NavigationSplitView {
sidebarColumn
} detail: {
featureColumn
}
.background(.bar)
} bottom: {
ConsolePanelRoot(expanded: $consoleExpanded)
}
.focusedSceneValue(\.consoleExpanded, $consoleExpanded)
}
/// Approximate catalogue size for the Discover subtitle. Hardcoded for now; should eventually be
/// sourced from the catalogue once a package-count property is exposed.
private static let approximateCatalogueSize = "9,000+"
private var sidebarColumn: some View {
MainSidebarView(selection: $selectedSidebarItem)
.navigationSplitViewColumnWidth(
min: BrewLayout.sidebarWidth,
ideal: BrewLayout.sidebarWidth,
max: BrewLayout.sidebarWidth + 40,
)
}
@ViewBuilder
private var featureColumn: some View {
switch selectedSidebarItem {
case .installed:
InstalledColumnsRoot()
.navigationTitle("Installed")
.navigationSubtitle("Browse or search your installed packages")
case .discover:
DiscoverColumnsRoot()
.navigationTitle("Discover")
.navigationSubtitle("Browse and search \(Self.approximateCatalogueSize) packages")
}
}
}
#if DEBUG
import BrewRepositoryInterfaces
#Preview {
MainWindowView()
.environment(\.brewCommandCenter, PreviewSupport.commandCenter)
.environment(\.installedPackagesRepository, PreviewSupport.makeInstalledPackagesRepository())
.environment(\.discoverPackagesRepository, PreviewSupport.makeDiscoverPackagesRepository())
.environment(\.catalogueRepository, PreviewSupport.makeDiscoverCatalogueRepository())
.environment(\.installedDependentsRepository, PreviewSupport.makeInstalledDependentsRepository())
}
#endif