2021-12-01 11:22:19 +00:00
|
|
|
import Defaults
|
2021-07-11 20:52:49 +00:00
|
|
|
import SwiftUI
|
|
|
|
#if os(iOS)
|
|
|
|
import Introspect
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct AppSidebarNavigation: View {
|
2022-11-24 20:36:05 +00:00
|
|
|
@ObservedObject private var accounts = AccountsModel.shared
|
|
|
|
private var navigation: NavigationModel { .shared }
|
2021-12-01 11:22:19 +00:00
|
|
|
|
2021-09-29 14:29:17 +00:00
|
|
|
#if os(iOS)
|
|
|
|
@State private var didApplyPrimaryViewWorkAround = false
|
|
|
|
#endif
|
2021-07-11 20:52:49 +00:00
|
|
|
|
2022-11-12 23:07:23 +00:00
|
|
|
@Default(.showOpenActionsToolbarItem) private var showOpenActionsToolbarItem
|
|
|
|
|
2021-07-11 20:52:49 +00:00
|
|
|
var body: some View {
|
|
|
|
#if os(iOS)
|
|
|
|
content.introspectViewController { viewController in
|
|
|
|
// workaround for an empty supplementary view on launch
|
|
|
|
// the supplementary view is determined by the default selection inside the
|
|
|
|
// primary view, but the primary view is not loaded so its selection is not read
|
2021-09-25 08:18:22 +00:00
|
|
|
// We work around that by showing the primary view
|
2021-07-11 20:52:49 +00:00
|
|
|
if !didApplyPrimaryViewWorkAround, let splitVC = viewController.children.first as? UISplitViewController {
|
|
|
|
UIView.performWithoutAnimation {
|
|
|
|
splitVC.show(.primary)
|
|
|
|
}
|
|
|
|
didApplyPrimaryViewWorkAround = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
content
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-09-25 08:18:22 +00:00
|
|
|
let sidebarMinWidth: Double = 280
|
|
|
|
|
2021-07-11 20:52:49 +00:00
|
|
|
var content: some View {
|
|
|
|
NavigationView {
|
2021-09-28 23:01:49 +00:00
|
|
|
Sidebar()
|
2021-09-25 08:18:22 +00:00
|
|
|
.toolbar { toolbarContent }
|
|
|
|
.frame(minWidth: sidebarMinWidth)
|
2021-08-31 21:17:50 +00:00
|
|
|
|
2021-10-17 23:06:00 +00:00
|
|
|
VStack {
|
2022-12-10 21:37:14 +00:00
|
|
|
HStack {
|
|
|
|
Spacer()
|
|
|
|
Image(systemName: "4k.tv")
|
|
|
|
.renderingMode(.original)
|
|
|
|
.font(.system(size: 60))
|
|
|
|
.foregroundColor(.accentColor)
|
|
|
|
Spacer()
|
2021-12-04 19:35:41 +00:00
|
|
|
}
|
2021-10-17 23:06:00 +00:00
|
|
|
}
|
2021-07-11 20:52:49 +00:00
|
|
|
}
|
2022-12-17 18:35:07 +00:00
|
|
|
.modifier(PlayerOverlayModifier())
|
2021-12-19 17:17:04 +00:00
|
|
|
.environment(\.navigationStyle, .sidebar)
|
2021-07-11 20:52:49 +00:00
|
|
|
}
|
|
|
|
|
2021-09-25 08:18:22 +00:00
|
|
|
var toolbarContent: some ToolbarContent {
|
|
|
|
Group {
|
|
|
|
#if os(iOS)
|
|
|
|
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
|
|
|
Button(action: { navigation.presentingSettings = true }) {
|
|
|
|
Image(systemName: "gearshape.2")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-11-10 17:11:28 +00:00
|
|
|
ToolbarItemGroup(placement: openVideosToolbarItemPlacement) {
|
2022-11-11 20:28:40 +00:00
|
|
|
if showOpenActionsToolbarItem {
|
|
|
|
Button {
|
|
|
|
navigation.presentingOpenVideos = true
|
|
|
|
} label: {
|
|
|
|
Label("Open Videos", systemImage: "play.circle.fill")
|
|
|
|
}
|
2022-11-10 17:11:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-19 12:45:41 +00:00
|
|
|
ToolbarItemGroup(placement: accountsMenuToolbarItemPlacement) {
|
2022-12-12 00:18:29 +00:00
|
|
|
AccountViewButton()
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
2022-01-02 19:32:42 +00:00
|
|
|
|
|
|
|
#if os(macOS)
|
|
|
|
ToolbarItem(placement: .navigation) {
|
|
|
|
Button {
|
|
|
|
NSApp.keyWindow?.firstResponder?.tryToPerform(#selector(NSSplitViewController.toggleSidebar(_:)), with: nil)
|
|
|
|
} label: {
|
|
|
|
Label("Toggle Sidebar", systemImage: "sidebar.left")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-10 17:11:28 +00:00
|
|
|
var openVideosToolbarItemPlacement: ToolbarItemPlacement {
|
|
|
|
#if os(iOS)
|
|
|
|
return .navigationBarLeading
|
|
|
|
#else
|
|
|
|
return .automatic
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-09-25 08:18:22 +00:00
|
|
|
var accountsMenuToolbarItemPlacement: ToolbarItemPlacement {
|
|
|
|
#if os(iOS)
|
|
|
|
return .bottomBar
|
|
|
|
#else
|
|
|
|
return .automatic
|
|
|
|
#endif
|
|
|
|
}
|
2021-07-11 20:52:49 +00:00
|
|
|
}
|
2022-11-11 17:50:13 +00:00
|
|
|
|
|
|
|
struct AppSidebarNavigation_Preview: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
AppSidebarNavigation()
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|