Skip to content

Commit

Permalink
Merge pull request #420 from demirbc/main
Browse files Browse the repository at this point in the history
Navigation adjustments
  • Loading branch information
buresdv authored Oct 16, 2024
2 parents 535c88e + 4f1484e commit cac5161
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 90 deletions.
2 changes: 1 addition & 1 deletion Cork/App State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AppState: ObservableObject

// MARK: - Navigation

@Published var navigationTarget: NavigationTargetMainWindow?
@Published var navigationTargetId: UUID?

// MARK: - Notifications

Expand Down
136 changes: 67 additions & 69 deletions Cork/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,91 +122,89 @@ struct ContentView: View, Sendable

var body: some View
{
VStack
NavigationSplitView(columnVisibility: $columnVisibility)
{
NavigationSplitView(columnVisibility: $columnVisibility)
{
SidebarView()
} detail: {
if let navigationTarget = appState.navigationTarget
{
switch navigationTarget
{
case .package(let brewPackage):
PackageDetailView(package: brewPackage)
case .tap(let brewTap):
TapDetailView(tap: brewTap)
}
}
else
SidebarView()
.navigationDestination(for: NavigationTargetMainWindow.self)
{ navigationTarget in
switch navigationTarget
{
StartPage()
.frame(minWidth: 600, minHeight: 500)
case .package(let brewPackage):
PackageDetailView(package: brewPackage)
.id(brewPackage.id)
case .tap(let brewTap):
TapDetailView(tap: brewTap)
.id(brewTap.id)
}
}
.navigationTitle("app-name")
.navigationSubtitle("navigation.installed-packages.count-\((displayOnlyIntentionallyInstalledPackagesByDefault ? brewData.installedFormulae.filter(\.installedIntentionally).count : brewData.installedFormulae.count) + brewData.installedCasks.count)")
.toolbar(id: "PackageActions")
} detail: {
NavigationStack {
StartPage()
.frame(minWidth: 600, minHeight: 500)
}
}
.navigationTitle("app-name")
.navigationSubtitle("navigation.installed-packages.count-\((displayOnlyIntentionallyInstalledPackagesByDefault ? brewData.installedFormulae.filter(\.installedIntentionally).count : brewData.installedFormulae.count) + brewData.installedCasks.count)")
.toolbar(id: "PackageActions")
{
ToolbarItem(id: "upgradePackages", placement: .primaryAction)
{
ToolbarItem(id: "upgradePackages", placement: .primaryAction)
{
upgradePackagesButton
}
upgradePackagesButton
}

ToolbarItem(id: "addTap", placement: .primaryAction)
{
addTapButton
}
ToolbarItem(id: "addTap", placement: .primaryAction)
{
addTapButton
}

ToolbarItem(id: "installPackage", placement: .primaryAction)
{
installPackageButton
}
ToolbarItem(id: "installPackage", placement: .primaryAction)
{
installPackageButton
}

ToolbarItem(id: "maintenance", placement: .primaryAction)
{
performMaintenanceButton
}
.defaultCustomization(.hidden)
ToolbarItem(id: "maintenance", placement: .primaryAction)
{
performMaintenanceButton
}
.defaultCustomization(.hidden)

ToolbarItem(id: "manageServices", placement: .primaryAction)
{
manageServicesButton
}
.defaultCustomization(.hidden)
ToolbarItem(id: "manageServices", placement: .primaryAction)
{
manageServicesButton
}
.defaultCustomization(.hidden)

ToolbarItem(id: "spacer", placement: .primaryAction)
{
Spacer()
}
.defaultCustomization(.hidden)
ToolbarItem(id: "spacer", placement: .primaryAction)
{
Spacer()
}
.defaultCustomization(.hidden)

ToolbarItem(id: "divider", placement: .primaryAction)
{
Divider()
}
.defaultCustomization(.hidden)
ToolbarItem(id: "divider", placement: .primaryAction)
{
Divider()
}
.defaultCustomization(.hidden)

// TODO: Implement this button
/*
ToolbarItem(id: "installPackageDirectly", placement: .automatic)
// TODO: Implement this button
/*
ToolbarItem(id: "installPackageDirectly", placement: .automatic)
{
Button
{
Button
AppConstants.logger.info("Ahoj")
} label: {
Label
{
AppConstants.logger.info("Ahoj")
} label: {
Label
{
Text("navigation.install-package.direct")
} icon: {
Image(systemName: "plus.viewfinder")
}
Text("navigation.install-package.direct")
} icon: {
Image(systemName: "plus.viewfinder")
}
.help("navigation.install-package.direct.help")
}
.defaultCustomization(.hidden)
*/
}
.help("navigation.install-package.direct.help")
}
.defaultCustomization(.hidden)
*/
}
.onAppear
{
Expand Down
4 changes: 2 additions & 2 deletions Cork/CorkApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,11 @@ struct CorkApp: App
{
Button
{
appDelegate.appState.navigationTarget = nil
appDelegate.appState.navigationTargetId = nil
} label: {
Text("action.go-to-status-page.menu-bar")
}
.disabled(appDelegate.appState.navigationTarget == nil)
.disabled(appDelegate.appState.navigationTargetId == nil)
Divider()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension BrewDataStorage
) async throws
{
/// Store the old navigation selection to see if it got updated in the middle of switching
let oldNavigationSelectionID: NavigationTargetMainWindow? = appState.navigationTarget
let oldNavigationSelectionId: UUID? = appState.navigationTargetId

if shouldApplyUninstallSpinnerToRelevantItemInSidebar
{
Expand Down Expand Up @@ -120,12 +120,12 @@ extension BrewDataStorage
}
}

if appState.navigationTarget != nil
if appState.navigationTargetId != nil
{
/// Switch to the status page only if the user didn't open another details window in the middle of the uninstall process
if oldNavigationSelectionID == appState.navigationTarget
if oldNavigationSelectionId == appState.navigationTargetId
{
appState.navigationTarget = nil
appState.navigationTargetId = nil
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Cork/Logic/Taps/Remove Tap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func removeTap(name: String, availableTaps: AvailableTaps, appState: AppState, s
var indexToReplaceGlobal: Int?

/// Store the old navigation selection to see if it got updated in the middle of switching
let oldNavigationTarget: NavigationTargetMainWindow? = appState.navigationTarget
let oldNavigationTargetId: UUID? = appState.navigationTargetId

if shouldApplyUninstallSpinnerToRelevantItemInSidebar
{
Expand Down Expand Up @@ -64,12 +64,12 @@ func removeTap(name: String, availableTaps: AvailableTaps, appState: AppState, s
}
}

if appState.navigationTarget != nil
if appState.navigationTargetId != nil
{
/// Switch to the status page only if the user didn't open another details window in the middle of the tap removal process
if oldNavigationTarget == appState.navigationTarget
if oldNavigationTargetId == appState.navigationTargetId
{
appState.navigationTarget = nil
appState.navigationTargetId = nil
}
}
}
Expand Down
22 changes: 12 additions & 10 deletions Cork/Views/Sidebar/Sidebar View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct SidebarView: View
]
@State private var currentTokens: [PackageSearchToken] = .init()

@State private var localNavigationTraget: NavigationTargetMainWindow?
@State private var localNavigationTragetId: UUID?

var suggestedTokens: [PackageSearchToken]
{
Expand All @@ -37,7 +37,7 @@ struct SidebarView: View
var body: some View
{
/// Navigation selection enables "Home" button behaviour. [2023.09]
List(selection: $localNavigationTraget)
List(selection: $localNavigationTragetId)
{
if currentTokens.isEmpty || currentTokens.contains(.formula) || currentTokens.contains(.intentionallyInstalledPackage)
{
Expand All @@ -54,16 +54,16 @@ struct SidebarView: View
TapsSection(searchText: searchText)
}
}
.onChange(of: localNavigationTraget)
.onChange(of: localNavigationTragetId)
{ newValue in
if appState.navigationTarget != newValue {
appState.navigationTarget = newValue
if appState.navigationTargetId != newValue {
appState.navigationTargetId = newValue
}
}
.onReceive(appState.$navigationTarget.receive(on: DispatchQueue.main))
.onReceive(appState.$navigationTargetId.receive(on: DispatchQueue.main))
{ newValue in
if localNavigationTraget != newValue {
localNavigationTraget = newValue
if localNavigationTragetId != newValue {
localNavigationTragetId = newValue
}
}
.listStyle(.sidebar)
Expand Down Expand Up @@ -105,12 +105,14 @@ struct SidebarView: View
{
Button
{
appState.navigationTarget = nil
appState.navigationTargetId = nil
} label: {
Label("action.go-to-status-page", systemImage: "house")
}
.help("action.go-to-status-page")
.disabled(appState.navigationTarget == nil || !searchText.isEmpty || !currentTokens.isEmpty)
.disabled(
appState.navigationTargetId == nil || !searchText.isEmpty || !currentTokens.isEmpty
)
}
.defaultCustomization(.visible, options: .alwaysAvailable)
}
Expand Down

0 comments on commit cac5161

Please sign in to comment.