fix: route the URL shortcut to the inline input

This commit is contained in:
2026-10-19 19:09:11 +02:00
parent f6485bf221
commit d068c52e04
5 changed files with 32 additions and 26 deletions
+17 -23
View File
@@ -29,6 +29,7 @@ final class PlayerModel: ObservableObject {
@Published private(set) var state = PlayerState()
@Published private(set) var fileName: String?
@Published var showsYouTubeInput = false
@Published private(set) var fileIcon: NSImage?
@Published private(set) var commandError: String?
@Published private(set) var queue = PlaybackQueue()
@@ -292,23 +293,6 @@ final class PlayerModel: ObservableObject {
if append { addToQueue(panel.urls) } else { openFiles(panel.urls) }
}
func openYouTubePanel() {
guard canOpen else { return }
defer { window?.makeFirstResponder(nil) }
revealControls()
let alert = NSAlert()
alert.messageText = "Open YouTube Video"
alert.informativeText = "Paste a YouTube video URL."
alert.addButton(withTitle: "Open")
alert.addButton(withTitle: "Cancel")
let field = NSTextField(frame: NSRect(x: 0, y: 0, width: 360, height: 24))
field.placeholderString = "https://www.youtube.com/watch?v=…"
field.setAccessibilityLabel("YouTube video URL")
alert.accessoryView = field
alert.window.initialFirstResponder = field
guard alert.runModal() == .alertFirstButtonReturn else { return }
openYouTube(field.stringValue)
}
func openYouTube(_ text: String) {
guard canOpen else { return }
@@ -320,6 +304,7 @@ final class PlayerModel: ObservableObject {
revealControls()
return
}
showsYouTubeInput = false
clearQueue()
resolveYouTube(url, height: nil)
}
@@ -963,7 +948,7 @@ final class PlayerModel: ObservableObject {
window?.level = isOnTop ? .floating : .normal
revealControls()
case .openFile: openPanel()
case .openYoutube: openYouTubePanel()
case .openYoutube: showsYouTubeInput.toggle()
case .closeFile: closeFile()
case .quit: NSApp.terminate(nil)
case .showBufferInfo: setShowsBufferInfo(true)
@@ -2094,7 +2079,7 @@ private struct PlayerContent: View {
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@ViewState private var showsRemainingTime = false
@ViewState private var dropTargeted = false
@ViewState private var showsYouTubeInput = false
private var showsYouTubeInput: Bool { model.showsYouTubeInput }
@ViewState private var youTubeURL = ""
@FocusState private var youTubeInputFocused: Bool
@ViewState private var controlSize = CGSize(width: 440, height: 68)
@@ -2133,9 +2118,7 @@ private struct PlayerContent: View {
}
private func toggleYouTubeInput() {
if showsYouTubeInput { youTubeInputFocused = false }
showsYouTubeInput.toggle()
if showsYouTubeInput { youTubeInputFocused = true }
model.perform(.openYoutube)
}
private func startScreen(in size: CGSize) -> some View {
@@ -2227,7 +2210,7 @@ private struct PlayerContent: View {
.padding(.top, 20)
}
}
.animation(reduceMotion ? nil : .easeInOut(duration: 0.25), value: showsYouTubeInput)
.animation(reduceMotion ? nil : .easeInOut(duration: 0.2), value: showsYouTubeInput)
.font(.system(size: 14, weight: .medium))
.disabled(!model.canOpen)
.padding(.horizontal, size.width < 600 ? 14 : 30)
@@ -2808,6 +2791,17 @@ private struct PlayerContent: View {
.tint(Color(SunsetPalette.accent))
.background(WindowChrome(model: model))
.onChange(of: windowDragging) { _, active in model.setControlsDragging(active) }
.onChange(of: showsYouTubeInput) { _, shown in youTubeInputFocused = shown }
.overlay(alignment: .top) {
if model.fileName != nil && showsYouTubeInput {
startURLInput
.padding(12)
.background(PlayerGlass().allowsHitTesting(false))
.frame(maxWidth: 420)
.padding(.top, 44)
.transition(.opacity)
}
}
}
private var windowDragBackground: some View {