Experimental applescript support

This commit is contained in:
Damiano Galassi committed 2017-02-24 11:26:55 +01:00
1 parent d9a4f56fc4
commit 57f2fe2560
9 files changed
+237 -28

No files matched your search

+36 -4
View File
@@ -53,7 +53,7 @@
[MP42File setGlobalLogger:logger];
if ([[NSUserDefaults standardUserDefaults] valueForKey:@"SBShowQueueWindow"]) {
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"SBShowQueueWindow"]) {
[[SBQueueController sharedManager] showWindow:self];
}
}
@@ -63,10 +63,10 @@
[presetManager savePresets];
if ([SBQueueController sharedManager].window.visible) {
[[NSUserDefaults standardUserDefaults] setValue:@"YES" forKey:@"SBShowQueueWindow"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"SBShowQueueWindow"];
}
else {
[[NSUserDefaults standardUserDefaults] setValue:nil forKey:@"SBShowQueueWindow"];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"SBShowQueueWindow"];
}
if (![[SBQueueController sharedManager] saveQueueToDisk]) {
@@ -78,7 +78,7 @@
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app
{
SBQueueStatus status= [SBQueueController sharedManager].status;
SBQueueStatus status= SBQueueController.sharedManager.queue.status;
if (status == SBQueueStatusWorking) {
NSAlert *alert = [[NSAlert alloc] init];
@@ -201,6 +201,38 @@
@end
@implementation SBAppDelegate (QueueScripting)
- (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key
{
return [key isEqualToString:@"items"];
}
- (NSArray<SBQueueItem *> *)items
{
SBQueue *queue = SBQueueController.sharedManager.queue;
NSMutableArray<SBQueueItem *> *items = [NSMutableArray array];
for (NSUInteger i = 0; i < queue.count; i++) {
[items addObject:[queue itemAtIndex:i]];
}
return items;
}
- (void)insertObject:(SBQueueItem *)object inItemsAtIndex:(NSUInteger)index
{
[SBQueueController.sharedManager.queue insertItem:object atIndex:index];
}
- (void)removeObjectFromItemsAtIndex:(NSUInteger)index
{
[SBQueueController.sharedManager.queue removeItemsAtIndexes:[NSIndexSet indexSetWithIndex:index]];
}
@end
@implementation SBDocumentController
- (void)openDocumentWithContentsOfURL:(NSURL * _Nonnull)url
+6 -2
View File
@@ -15,15 +15,19 @@ NS_ASSUME_NONNULL_BEGIN
@interface SBQueueController : NSWindowController
@property(readonly) SBQueueStatus status;
@property (class, readonly) SBQueueController *sharedManager;
+ (SBQueueController *)sharedManager;
@property (nonatomic, readonly) SBQueue *queue;
- (IBAction)open:(id)sender;
- (void)addItemsFromURLs:(NSArray<NSURL *> *)URLs atIndex:(NSInteger)index;
- (void)addItem:(SBQueueItem *)item;
- (void)editItem:(SBQueueItem *)item;
- (IBAction)start:(id)sender;
- (IBAction)stop:(id)sender;
@property (nonatomic, readonly) BOOL saveQueueToDisk;
@end
+2 -3
View File
@@ -24,7 +24,6 @@ static void *SBQueueContex = &SBQueueContex;
@interface SBQueueController () <NSPopoverDelegate, NSWindowDelegate, NSTableViewDelegate, NSTableViewDataSource, SBTableViewDelegate, SBItemViewDelegate>
@property (nonatomic, readonly) SBQueue *queue;
@property (nonatomic, readonly) SBQueuePreferences *prefs;
@property (nonatomic, readonly) NSMutableDictionary<NSString *, id> *options;
@@ -503,7 +502,7 @@ static void *SBQueueContex = &SBQueueContex;
[self updateDockTile];
}
- (void)start:(id)sender {
- (IBAction)start:(id)sender {
if (self.queue.status == SBQueueStatusWorking) {
return;
}
@@ -516,7 +515,7 @@ static void *SBQueueContex = &SBQueueContex;
[self.queue start];
}
- (void)stop:(id)sender {
- (IBAction)stop:(id)sender {
[self.queue stop];
}
+32 -3
View File
@@ -17,6 +17,8 @@
@interface SBQueueItem ()
@property (nonatomic, readonly) NSString *uniqueID;
@property (nonatomic, readonly) NSMutableArray<id<SBQueueActionProtocol>> *actionsInternal;
@property (nonatomic, readwrite) NSString *localizedWorkingDescription;
@@ -32,6 +34,7 @@
- (instancetype)init {
self = [super init];
if (self) {
_uniqueID = [[NSUUID UUID] UUIDString];
_actionsInternal = [[NSMutableArray alloc] init];
_status = SBQueueItemStatusReady;
}
@@ -383,15 +386,16 @@ bail:
[self.delegate progressStatus:progress];
}
#pragma mark NSSecyreCoding
#pragma mark NSSecureCoding
+ (BOOL)supportsSecureCoding {
return YES;
}
- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeInt:2 forKey:@"SBQueueItemTagEncodeVersion"];
[coder encodeInt:3 forKey:@"SBQueueItemTagEncodeVersion"];
[coder encodeObject:_uniqueID forKey:@"SBQueueItemID"];
[coder encodeObject:_mp4File forKey:@"SBQueueItemMp4File"];
[coder encodeObject:_fileURL forKey:@"SBQueueItemFileURL"];
[coder encodeObject:_destURL forKey:@"SBQueueItemDestURL"];
@@ -404,6 +408,7 @@ bail:
- (instancetype)initWithCoder:(NSCoder *)decoder {
self = [super init];
_uniqueID = [decoder decodeObjectOfClass:[NSString class] forKey:@"SBQueueItemID"];
_mp4File = [decoder decodeObjectOfClass:[MP42File class] forKey:@"SBQueueItemMp4File"];
_fileURL = [decoder decodeObjectOfClass:[NSURL class] forKey:@"SBQueueItemFileURL"];
@@ -417,9 +422,33 @@ bail:
forKey:@"SBQueueItemActions"];
_status = [decoder decodeIntForKey:@"SBQueueItemStatus"];
return self;
}
#pragma mark AppleScript
- (NSString *)name
{
return self.destURL.lastPathComponent;
}
- (NSString *)sourcePath
{
return self.fileURL.path;
}
- (NSString *)destinationPath
{
return self.destURL.path;
}
- (NSUniqueIDSpecifier *)objectSpecifier {
NSScriptClassDescription *appDescription = (NSScriptClassDescription *)[NSApp classDescription];
return [[NSUniqueIDSpecifier alloc] initWithContainerClassDescription:appDescription
containerSpecifier:nil
key:@"items"
uniqueID:self.uniqueID];
}
@end
+18
View File
@@ -0,0 +1,18 @@
//
// SBQueueScriptCommand.h
// Subler
//
// Created by Damiano Galassi on 02/02/17.
//
//
#import <Foundation/Foundation.h>
@interface SBQueueScriptCommand : NSScriptCommand
@end
@interface SBQueueStartScriptCommand : NSScriptCommand
@end
@interface SBQueueStopScriptCommand : NSScriptCommand
@end
+44
View File
@@ -0,0 +1,44 @@
//
// SBQueueScriptCommand.m
// Subler
//
// Created by Damiano Galassi on 02/02/17.
//
//
#import "SBQueueScriptCommand.h"
#import "SBQueueController.h"
@implementation SBQueueScriptCommand
- (id)performDefaultImplementation
{
NSArray<NSURL *> *args = [self directParameter];
[SBQueueController.sharedManager addItemsFromURLs:args atIndex:0];
return nil;
}
@end
@implementation SBQueueStartScriptCommand
- (id)performDefaultImplementation
{
[SBQueueController.sharedManager start:self];
[self suspendExecution];
return nil;
}
@end
@implementation SBQueueStopScriptCommand
- (id)performDefaultImplementation
{
[SBQueueController.sharedManager stop:self];
return nil;
}
@end