yattee/Shared/MenuCommands.swift

91 lines
2.5 KiB
Swift
Raw Permalink Normal View History

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