feat: add expandable file and link controls to playlist
This commit is contained in:
@@ -185,10 +185,12 @@ private enum WindowDragCheck {
|
||||
static func run(result: URL) {
|
||||
resultURL = result
|
||||
_ = NSApplication.shared
|
||||
if CommandLine.arguments.contains("--queue-add-only") { probe = 12 }
|
||||
timer = Timer.scheduledTimer(withTimeInterval: 0.05, repeats: true) { _ in
|
||||
MainActor.assumeIsolated { advance() }
|
||||
}
|
||||
RunLoop.main.add(timer!, forMode: .common)
|
||||
RunLoop.main.add(timer!, forMode: .modalPanel)
|
||||
terebiAppMain()
|
||||
}
|
||||
|
||||
@@ -230,6 +232,18 @@ private enum WindowDragCheck {
|
||||
}
|
||||
}
|
||||
|
||||
static func clickQueueAdd(in window: NSWindow, link: Bool) {
|
||||
for type in [NSEvent.EventType.leftMouseDown, .leftMouseUp] {
|
||||
let event = NSEvent.mouseEvent(with: type,
|
||||
location: NSPoint(x: window.contentView!.bounds.width - (link ? 163 : 183), y: 18),
|
||||
modifierFlags: [], timestamp: ProcessInfo.processInfo.systemUptime,
|
||||
windowNumber: window.windowNumber, context: nil,
|
||||
eventNumber: 1000 + phase * 2 + (type == .leftMouseDown ? 0 : 1),
|
||||
clickCount: 1, pressure: type == .leftMouseDown ? 1 : 0)!
|
||||
NSApp.postEvent(NSEvent(cgEvent: event.cgEvent!)!, atStart: false)
|
||||
}
|
||||
}
|
||||
|
||||
static func point(in window: NSWindow) -> NSPoint? {
|
||||
let content = window.contentView!
|
||||
let w = content.bounds.width
|
||||
@@ -303,6 +317,7 @@ private enum WindowDragCheck {
|
||||
interceptDrags(in: window)
|
||||
model.setVolume(0)
|
||||
model.setPlayback(playing: false)
|
||||
if CommandLine.arguments.contains("--queue-add-only") { model.showsQueue = true }
|
||||
window.makeKeyAndOrderFront(nil)
|
||||
window.makeMain()
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
@@ -365,6 +380,12 @@ private enum WindowDragCheck {
|
||||
phase = 7
|
||||
return
|
||||
}
|
||||
if probe == 12 {
|
||||
urlWindowFrame = window.frame
|
||||
clickQueueAdd(in: window, link: false)
|
||||
phase = 7
|
||||
return
|
||||
}
|
||||
probe += 1
|
||||
if probe == names.count { finish(); return }
|
||||
phase = 0
|
||||
@@ -387,6 +408,48 @@ private enum WindowDragCheck {
|
||||
probe += 1
|
||||
phase = 0
|
||||
return
|
||||
} else if probe == 12 && phase == 7 {
|
||||
guard NSApp.modalWindow == nil else { finish("Queue + opened the file picker instead of expanding"); return }
|
||||
clickQueueAdd(in: window, link: true)
|
||||
} else if probe == 12 && phase == 8 {
|
||||
guard let editor = window.firstResponder as? NSTextView, editor.isFieldEditor else { return }
|
||||
editor.insertText(urlDraft, replacementRange: NSRange(location: NSNotFound, length: 0))
|
||||
clickQueueAdd(in: window, link: true)
|
||||
} else if probe == 12 && phase == 9 {
|
||||
guard nativeView(in: window.contentView!, matching: { ($0 as? NSTextField)?.isEditable == true }) == nil else { return }
|
||||
guard (window.firstResponder as? NSTextView)?.isFieldEditor != true else {
|
||||
finish("Collapsing the queue URL field retained keyboard focus"); return
|
||||
}
|
||||
clickQueueAdd(in: window, link: true)
|
||||
} else if probe == 12 && phase == 10 {
|
||||
guard let editor = window.firstResponder as? NSTextView, editor.isFieldEditor else { return }
|
||||
guard editor.string == urlDraft else { finish("Reopening queue URL input lost its draft"); return }
|
||||
let escape = NSEvent.keyEvent(with: .keyDown, location: .zero, modifierFlags: [],
|
||||
timestamp: ProcessInfo.processInfo.systemUptime, windowNumber: window.windowNumber,
|
||||
context: nil, characters: "\u{1b}", charactersIgnoringModifiers: "\u{1b}", isARepeat: false, keyCode: 53)!
|
||||
NSApp.postEvent(escape, atStart: false)
|
||||
} else if probe == 12 && phase == 11 {
|
||||
guard nativeView(in: window.contentView!, matching: { ($0 as? NSTextField)?.isEditable == true }) == nil else { return }
|
||||
guard (window.firstResponder as? NSTextView)?.isFieldEditor != true,
|
||||
window.frame == urlWindowFrame, drags == previousDrags else {
|
||||
finish("Queue URL transitions retained focus, resized or dragged the window"); return
|
||||
}
|
||||
clickQueueAdd(in: window, link: false)
|
||||
} else if probe == 12 && phase == 12 {
|
||||
clickQueueAdd(in: window, link: false)
|
||||
} else if probe == 12 && phase == 13 {
|
||||
guard let panel = NSApp.modalWindow as? NSOpenPanel else { return }
|
||||
guard panel.allowsMultipleSelection && panel.prompt == "Add to Queue" else {
|
||||
panel.cancel(nil)
|
||||
finish("Queue file icon did not open the multi-file queue picker"); return
|
||||
}
|
||||
panel.cancel(nil)
|
||||
} else if probe == 12 && phase == 14 {
|
||||
guard NSApp.modalWindow == nil else { return }
|
||||
probe += 1
|
||||
if CommandLine.arguments.contains("--queue-add-only") { finish(); return }
|
||||
phase = 0
|
||||
return
|
||||
}
|
||||
phase += 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user