2021-12-01 16:52:19 +05:30
|
|
|
import Defaults
|
2021-07-12 02:22:49 +05:30
|
|
|
import SwiftUI
|
|
|
|
#if os(iOS)
|
|
|
|
import Introspect
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct AppSidebarNavigation: View {
|
2021-10-17 04:18:58 +05:30
|
|
|
@EnvironmentObject<AccountsModel> private var accounts
|
2021-12-01 16:52:19 +05:30
|
|
|
|
2021-09-29 19:59:17 +05:30
|
|
|
#if os(iOS)
|
|
|
|
@State private var didApplyPrimaryViewWorkAround = false
|
2021-12-20 05:06:12 +05:30
|
|
|
|
|
|
|
@EnvironmentObject<CommentsModel> private var comments
|
|
|
|
@EnvironmentObject<InstancesModel> private var instances
|
|
|
|
@EnvironmentObject<NavigationModel> private var navigation
|
|
|
|
@EnvironmentObject<PlayerModel> private var player
|
|
|
|
@EnvironmentObject<PlaylistsModel> private var playlists
|
|
|
|
@EnvironmentObject<RecentsModel> private var recents
|
|
|
|
@EnvironmentObject<SearchModel> private var search
|
|
|
|
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
|
|
|
@EnvironmentObject<ThumbnailsModel> private var thumbnailsModel
|
2021-09-29 19:59:17 +05:30
|
|
|
#endif
|
2021-07-12 02:22:49 +05:30
|
|
|
|
|
|
|
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 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 {
|
2021-12-05 01:05:41 +05:30
|
|
|
PlayerControlsView {
|
|
|
|
HStack(alignment: .center) {
|
|
|
|
Spacer()
|
|
|
|
Image(systemName: "play.tv")
|
|
|
|
.renderingMode(.original)
|
|
|
|
.font(.system(size: 60))
|
|
|
|
.foregroundColor(.accentColor)
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
}
|
2021-10-18 04:36:00 +05:30
|
|
|
}
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|
2021-12-19 22:47:04 +05:30
|
|
|
.environment(\.navigationStyle, .sidebar)
|
2021-12-05 01:05:41 +05:30
|
|
|
#if os(iOS)
|
2021-12-19 22:47:04 +05:30
|
|
|
.background(
|
|
|
|
EmptyView().fullScreenCover(isPresented: $player.presentingPlayer) {
|
2021-12-20 05:06:12 +05:30
|
|
|
VideoPlayerView()
|
|
|
|
.environmentObject(accounts)
|
|
|
|
.environmentObject(comments)
|
|
|
|
.environmentObject(instances)
|
|
|
|
.environmentObject(navigation)
|
|
|
|
.environmentObject(player)
|
|
|
|
.environmentObject(playlists)
|
|
|
|
.environmentObject(recents)
|
|
|
|
.environmentObject(subscriptions)
|
|
|
|
.environmentObject(thumbnailsModel)
|
2021-12-19 22:47:04 +05:30
|
|
|
.environment(\.navigationStyle, .sidebar)
|
|
|
|
}
|
|
|
|
)
|
2021-12-05 01:05:41 +05:30
|
|
|
#endif
|
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
|
|
|
|
|
|
|
|
ToolbarItem(placement: accountsMenuToolbarItemPlacement) {
|
|
|
|
AccountsMenuView()
|
|
|
|
.help(
|
|
|
|
"Switch Instances and Accounts\n" +
|
|
|
|
"Current Instance: \n" +
|
2021-10-20 02:57:04 +05:30
|
|
|
"\(accounts.current?.url ?? "Not Set")\n" +
|
|
|
|
"Current User: \(accounts.current?.description ?? "Not set")"
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var accountsMenuToolbarItemPlacement: ToolbarItemPlacement {
|
|
|
|
#if os(iOS)
|
|
|
|
return .bottomBar
|
|
|
|
#else
|
|
|
|
return .automatic
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-08-30 03:06:18 +05:30
|
|
|
static func symbolSystemImage(_ name: String) -> String {
|
|
|
|
let firstLetter = name.first?.lowercased()
|
|
|
|
let regex = #"^[a-z0-9]$"#
|
|
|
|
|
|
|
|
let symbolName = firstLetter?.range(of: regex, options: .regularExpression) != nil ? firstLetter! : "questionmark"
|
|
|
|
|
2021-09-25 13:48:22 +05:30
|
|
|
return "\(symbolName).circle"
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|
|
|
|
}
|