Improve AppleScript support.
This commit is contained in:
5 files changed
+49
-42
No files matched your search
@@ -229,14 +229,14 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
extension AppDelegate {
|
||||
|
||||
func application(_ sender: NSApplication, delegateHandlesKey key: String) -> Bool {
|
||||
if key == "items" {
|
||||
if key == "queueItems" {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@objc(items) func items() -> [QueueItem] {
|
||||
@objc(queueItems) func queueItems() -> [QueueItem] {
|
||||
let queue = QueueController.shared
|
||||
let indexes = IndexSet(integersIn: 0..<Int(queue.count))
|
||||
return queue.items(at: indexes)
|
||||
|
||||
@@ -106,6 +106,10 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
|
||||
notification.soundName = NSUserNotificationDefaultSoundName
|
||||
NSUserNotificationCenter.default.deliver(notification)
|
||||
}
|
||||
|
||||
for script in self.scripts {
|
||||
script.resumeExecution(withResult: "Completed")
|
||||
}
|
||||
}
|
||||
|
||||
nc.addObserver(forName: Queue.Failed, object: queue, queue: main) { (note) in
|
||||
@@ -282,6 +286,12 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
|
||||
|
||||
//MARK: Queue management
|
||||
|
||||
private var scripts: [NSScriptCommand] = []
|
||||
|
||||
func add(script: NSScriptCommand) {
|
||||
scripts.append(script)
|
||||
}
|
||||
|
||||
var status: Queue.Status {
|
||||
get {
|
||||
return queue.status
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import Cocoa
|
||||
import MP42Foundation
|
||||
|
||||
final class QueueItem: NSObject, NSSecureCoding {
|
||||
@objc(SBQueueItem) final class QueueItem: NSObject, NSSecureCoding {
|
||||
|
||||
@objc enum Status: Int {
|
||||
case ready
|
||||
@@ -50,7 +50,7 @@ final class QueueItem: NSObject, NSSecureCoding {
|
||||
weak var delegate: Queue?
|
||||
|
||||
private var statusInternal: Status
|
||||
private let uniqueID: String
|
||||
@objc private let uniqueID: String
|
||||
private var attributes: [String : Any]
|
||||
private var actionsInternal: [QueueActionProtocol]
|
||||
|
||||
|
||||
@@ -11,7 +11,18 @@ import Foundation
|
||||
|
||||
override func performDefaultImplementation() -> Any? {
|
||||
guard let args = directParameter as? [URL] else { return nil }
|
||||
QueueController.shared.insert(contentOf: args, at: 0)
|
||||
QueueController.shared.insert(contentOf: args, at: QueueController.shared.count)
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@objc(SBQueueStartAndWaitScriptCommand) class QueueStartAndWaitScriptCommand: NSScriptCommand {
|
||||
|
||||
override func performDefaultImplementation() -> Any? {
|
||||
QueueController.shared.add(script: self)
|
||||
QueueController.shared.start(self)
|
||||
self.suspendExecution()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -21,7 +32,6 @@ import Foundation
|
||||
|
||||
override func performDefaultImplementation() -> Any? {
|
||||
QueueController.shared.start(self)
|
||||
self.suspendExecution()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user