2021-12-01 16:52:19 +05:30
|
|
|
import Defaults
|
2021-07-12 02:22:49 +05:30
|
|
|
import SwiftUI
|
|
|
|
#if os(iOS)
|
2023-09-26 21:05:08 +05:30
|
|
|
import SwiftUIIntrospect
|
2021-07-12 02:22:49 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
struct AppSidebarNavigation: View {
|
2022-11-25 02:06:05 +05:30
|
|
|
private var navigation: NavigationModel { .shared }
|
2021-12-01 16:52:19 +05:30
|
|
|
|
2021-09-29 19:59:17 +05:30
|
|
|
#if os(iOS)
|
|
|
|
@State private var didApplyPrimaryViewWorkAround = false
|
|
|
|
#endif
|
2021-07-12 02:22:49 +05:30
|
|
|
|
2022-11-13 04:37:23 +05:30
|
|
|
@Default(.showOpenActionsToolbarItem) private var showOpenActionsToolbarItem
|
|
|
|
|
2021-07-12 02:22:49 +05:30
|
|
|
var body: some View {
|
|
|
|
#if os(iOS)
|
2024-09-11 23:54:03 +05:30
|
|
|
content.introspect(.viewController, on: .iOS(.v15, .v16, .v17, .v18)) { viewController in
|
2021-07-12 02:22:49 +05:30
|
|
|
// 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 13:48:22 +05:30
|
|
|
// We work around that by showing the primary view
|
2021-07-12 02:22:49 +05:30
|
|
|
if !didApplyPrimaryViewWorkAround, let splitVC = viewController.children.first as? UISplitViewController {
|
|
|
|
UIView.performWithoutAnimation {
|
|
|
|
splitVC.show(.primary)
|
|
|
|
}
|
|
|
|
didApplyPrimaryViewWorkAround = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
content
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-09-25 13:48:22 +05:30
|
|
|
let sidebarMinWidth: Double = 280
|
|
|
|
|
2021-07-12 02:22:49 +05:30
|
|
|
var content: some View {
|
|
|
|
NavigationView {
|
2021-09-29 04:31:49 +05:30
|
|
|
Sidebar()
|
2021-09-25 13:48:22 +05:30
|
|
|
.toolbar { toolbarContent }
|
|
|
|
.frame(minWidth: sidebarMinWidth)
|
2021-09-01 02:47:50 +05:30
|
|
|
|
2021-10-18 04:36:00 +05:30
|
|
|
VStack {
|
2022-12-11 03:07:14 +05:30
|
|
|
HStack {
|
|
|
|
Spacer()
|
|
|
|
Image(systemName: "4k.tv")
|
|
|
|
.renderingMode(.original)
|
|
|
|
.font(.system(size: 60))
|
|
|
|
.foregroundColor(.accentColor)
|
|
|
|
Spacer()
|
2021-12-05 01:05:41 +05:30
|
|
|
}
|
2021-10-18 04:36:00 +05:30
|
|
|
}
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|
2022-12-18 00:05:07 +05:30
|
|
|
.modifier(PlayerOverlayModifier())
|
2021-12-19 22:47:04 +05:30
|
|
|
.environment(\.navigationStyle, .sidebar)
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|
|
|
|
|
2021-09-25 13:48:22 +05:30
|
|
|
var toolbarContent: some ToolbarContent {
|
|
|
|
Group {
|
|
|
|
#if os(iOS)
|
|
|
|
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
|
|
|
Button(action: { navigation.presentingSettings = true }) {
|
|
|
|
Image(systemName: "gearshape.2")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-11-10 22:41:28 +05:30
|
|
|
ToolbarItemGroup(placement: openVideosToolbarItemPlacement) {
|
2022-11-12 01:58:40 +05:30
|
|
|
if showOpenActionsToolbarItem {
|
|
|
|
Button {
|
|
|
|
navigation.presentingOpenVideos = true
|
|
|
|
} label: {
|
|
|
|
Label("Open Videos", systemImage: "play.circle.fill")
|
|
|
|
}
|
2022-11-10 22:41:28 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-19 18:15:41 +05:30
|
|
|
ToolbarItemGroup(placement: accountsMenuToolbarItemPlacement) {
|
2022-12-12 05:48:29 +05:30
|
|
|
AccountViewButton()
|
2021-09-25 13:48:22 +05:30
|
|
|
}
|
2022-01-03 01:02:42 +05:30
|
|
|
|
|
|
|
#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 13:48:22 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-10 22:41:28 +05:30
|
|
|
var openVideosToolbarItemPlacement: ToolbarItemPlacement {
|
|
|
|
#if os(iOS)
|
|
|
|
return .navigationBarLeading
|
|
|
|
#else
|
|
|
|
return .automatic
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-09-25 13:48:22 +05:30
|
|
|
var accountsMenuToolbarItemPlacement: ToolbarItemPlacement {
|
|
|
|
#if os(iOS)
|
|
|
|
return .bottomBar
|
|
|
|
#else
|
|
|
|
return .automatic
|
|
|
|
#endif
|
|
|
|
}
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|
2022-11-11 23:20:13 +05:30
|
|
|
|
|
|
|
struct AppSidebarNavigation_Preview: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
AppSidebarNavigation()
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|