1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Shared/MenuCommands.swift

97 lines
2.6 KiB
Swift
Raw Normal View History

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) {
Button("Open Videos...") { model.navigation?.presentingOpenVideos = true }
.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-01-09 20:17:24 +05:30
.disabled(!(model.accounts?.app.supportsPopular ?? false))
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) {
guard let navigation = model.navigation else {
return
}
navigation.sidebarSectionChanged.toggle()
navigation.tabSelection = tabSelection
}
2021-11-28 20:07:55 +05:30
private var subscriptionsDisabled: Bool {
!(
(model.accounts?.app.supportsSubscriptions ?? false) && model.accounts?.signedIn ?? false
)
}
2021-11-09 04:44:28 +05:30
private var playbackMenu: some Commands {
CommandMenu("Playback") {
Button((model.player?.isPlaying ?? true) ? "Pause" : "Play") {
model.player?.togglePlay()
}
.disabled(model.player?.currentItem.isNil ?? true)
.keyboardShortcut("p")
Button("Play Next") {
model.player?.advanceToNextItem()
}
.disabled(model.player?.queue.isEmpty ?? true)
.keyboardShortcut("s")
Button(togglePlayerLabel) {
2021-11-09 04:44:28 +05:30
model.player?.togglePlayer()
}
.keyboardShortcut("o")
}
}
private var togglePlayerLabel: String {
#if os(macOS)
"Show Player"
#else
(model.player?.presentingPlayer ?? true) ? "Hide Player" : "Show Player"
#endif
}
2021-11-09 04:44:28 +05:30
}