2021-11-09 04:44:28 +05:30
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct MenuCommands: Commands {
|
|
|
|
@Binding var model: MenuModel
|
|
|
|
|
|
|
|
var body: some Commands {
|
2022-11-10 22:41:28 +05:30
|
|
|
openVideosMenu
|
2021-11-09 04:44:28 +05:30
|
|
|
navigationMenu
|
|
|
|
playbackMenu
|
|
|
|
}
|
|
|
|
|
2022-11-10 22:41:28 +05:30
|
|
|
private var openVideosMenu: some Commands {
|
|
|
|
CommandGroup(after: .newItem) {
|
2022-11-25 02:06:05 +05:30
|
|
|
Button("Open Videos...") { NavigationModel.shared.presentingOpenVideos = true }
|
2022-11-10 22:41:28 +05:30
|
|
|
.keyboardShortcut("t")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-09 04:44:28 +05:30
|
|
|
private var navigationMenu: some Commands {
|
2021-11-28 20:07:55 +05:30
|
|
|
CommandGroup(before: .windowSize) {
|
2022-11-09 19:04:04 +05:30
|
|
|
Button("Home") {
|
|
|
|
setTabSelection(.home)
|
2021-11-09 04:44:28 +05:30
|
|
|
}
|
|
|
|
.keyboardShortcut("1")
|
|
|
|
|
|
|
|
Button("Subscriptions") {
|
2022-03-28 00:08:59 +05:30
|
|
|
setTabSelection(.subscriptions)
|
2021-11-09 04:44:28 +05:30
|
|
|
}
|
2021-11-28 20:07:55 +05:30
|
|
|
.disabled(subscriptionsDisabled)
|
2021-11-09 04:44:28 +05:30
|
|
|
.keyboardShortcut("2")
|
|
|
|
|
|
|
|
Button("Popular") {
|
2022-03-28 00:08:59 +05:30
|
|
|
setTabSelection(.popular)
|
2021-11-09 04:44:28 +05:30
|
|
|
}
|
2022-11-25 02:06:05 +05:30
|
|
|
.disabled(!AccountsModel.shared.app.supportsPopular)
|
2021-11-09 04:44:28 +05:30
|
|
|
.keyboardShortcut("3")
|
|
|
|
|
|
|
|
Button("Trending") {
|
2022-03-28 00:08:59 +05:30
|
|
|
setTabSelection(.trending)
|
2021-11-09 04:44:28 +05:30
|
|
|
}
|
|
|
|
.keyboardShortcut("4")
|
|
|
|
|
|
|
|
Button("Search") {
|
2022-03-28 00:08:59 +05:30
|
|
|
setTabSelection(.search)
|
2021-11-09 04:44:28 +05:30
|
|
|
}
|
|
|
|
.keyboardShortcut("f")
|
2021-11-28 20:07:55 +05:30
|
|
|
|
|
|
|
Divider()
|
2021-11-09 04:44:28 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-28 00:08:59 +05:30
|
|
|
private func setTabSelection(_ tabSelection: NavigationModel.TabSelection) {
|
2022-11-25 02:06:05 +05:30
|
|
|
NavigationModel.shared.sidebarSectionChanged.toggle()
|
|
|
|
NavigationModel.shared.tabSelection = tabSelection
|
2022-03-28 00:08:59 +05:30
|
|
|
}
|
|
|
|
|
2021-11-28 20:07:55 +05:30
|
|
|
private var subscriptionsDisabled: Bool {
|
2022-11-25 02:06:05 +05:30
|
|
|
!(AccountsModel.shared.app.supportsSubscriptions && AccountsModel.shared.signedIn)
|
2021-11-28 20:07:55 +05:30
|
|
|
}
|
|
|
|
|
2021-11-09 04:44:28 +05:30
|
|
|
private var playbackMenu: some Commands {
|
|
|
|
CommandMenu("Playback") {
|
2022-11-25 02:06:05 +05:30
|
|
|
Button((PlayerModel.shared.isPlaying) ? "Pause" : "Play") {
|
|
|
|
PlayerModel.shared.togglePlay()
|
2021-11-09 04:44:28 +05:30
|
|
|
}
|
2022-11-25 02:06:05 +05:30
|
|
|
.disabled(PlayerModel.shared.currentItem.isNil)
|
2021-11-09 04:44:28 +05:30
|
|
|
.keyboardShortcut("p")
|
|
|
|
|
|
|
|
Button("Play Next") {
|
2022-11-25 02:06:05 +05:30
|
|
|
PlayerModel.shared.advanceToNextItem()
|
2021-11-09 04:44:28 +05:30
|
|
|
}
|
2022-11-25 02:06:05 +05:30
|
|
|
.disabled(PlayerModel.shared.queue.isEmpty)
|
2021-11-09 04:44:28 +05:30
|
|
|
.keyboardShortcut("s")
|
|
|
|
|
2021-12-19 22:47:04 +05:30
|
|
|
Button(togglePlayerLabel) {
|
2022-11-25 02:06:05 +05:30
|
|
|
PlayerModel.shared.togglePlayer()
|
2021-11-09 04:44:28 +05:30
|
|
|
}
|
|
|
|
.keyboardShortcut("o")
|
|
|
|
}
|
|
|
|
}
|
2021-12-19 22:47:04 +05:30
|
|
|
|
|
|
|
private var togglePlayerLabel: String {
|
|
|
|
#if os(macOS)
|
|
|
|
"Show Player"
|
|
|
|
#else
|
2022-11-25 02:06:05 +05:30
|
|
|
PlayerModel.shared.presentingPlayer ? "Hide Player" : "Show Player"
|
2021-12-19 22:47:04 +05:30
|
|
|
#endif
|
|
|
|
}
|
2021-11-09 04:44:28 +05:30
|
|
|
}
|