Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Origami 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Walkin committed Mar 15, 2016
1 parent 6566c55 commit 26ef245
Show file tree
Hide file tree
Showing 137 changed files with 12,608 additions and 46 deletions.
19 changes: 19 additions & 0 deletions Origami Plugin/DHAppleScriptPatch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*
*/

#import <SkankySDK/SkankySDK.h>

@interface DHAppleScriptPatch : QCPatch
{
QCStringPort *inputScript;
QCBooleanPort *inputUpdateSignal;
QCVirtualPort *outputResult;
}

@end
56 changes: 56 additions & 0 deletions Origami Plugin/DHAppleScriptPatch.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*
*/

#import "DHAppleScriptPatch.h"
#import "NSAppleScript+FBAdditions.h"

@implementation DHAppleScriptPatch

- (id)initWithIdentifier:(id)identifier {
if (self = [super initWithIdentifier:identifier]) {

}

return self;
}

+ (QCPatchExecutionMode)executionModeWithIdentifier:(id)identifier {
return kQCPatchExecutionModeProvider;
}

+ (BOOL)allowsSubpatchesWithIdentifier:(id)identifier {
return NO;
}

+ (QCPatchTimeMode)timeModeWithIdentifier:(id)identifier {
return kQCPatchTimeModeNone;
}

- (BOOL)execute:(QCOpenGLContext *)context time:(double)time arguments:(NSDictionary *)arguments {
if (!(inputScript.wasUpdated || inputUpdateSignal.wasUpdated)) {
return YES;
}

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
NSString *error = nil;
id result = [NSAppleScript runScript:inputScript.stringValue error:&error];

if ([result isKindOfClass:[NSArray class]]) {
result = [[QCStructure alloc] initWithArray:result];
} else if ([result isKindOfClass:[NSDictionary class]]) {
result = [[QCStructure alloc] initWithDictionary:result];
}

outputResult.rawValue = (error) ? error : result;
});

return YES;
}

@end
56 changes: 56 additions & 0 deletions Origami Plugin/DHAppleScriptPatch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>nodeAttributes</key>
<dict>
<key>category</key>
<string>Origami</string>
<key>categories</key>
<array>
<string>Origami</string>
</array>
<key>description</key>
<string>Executes an AppleScript.


Origami
http://origami.facebook.com/

Use of this patch is subject to the license found at http://origami.facebook.com/license/

Copyright: (c) 2016, Facebook, Inc. All rights reserved.

Created by: Drew Hamlin</string>
<key>name</key>
<string>AppleScript</string>
</dict>
<key>inputAttributes</key>
<dict>
<key>inputScript</key>
<dict>
<key>description</key>
<string></string>
<key>name</key>
<string>Location</string>
</dict>
<key>inputUpdateSignal</key>
<dict>
<key>description</key>
<string></string>
<key>name</key>
<string>Update Signal</string>
</dict>
</dict>
<key>outputAttributes</key>
<dict>
<key>outputResult</key>
<dict>
<key>description</key>
<string></string>
<key>name</key>
<string>Result</string>
</dict>
</dict>
</dict>
</plist>
24 changes: 24 additions & 0 deletions Origami Plugin/DHImageAtURLPatch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*
*/

#import <Foundation/Foundation.h>
#import <SkankySDK/SkankySDK.h>

@interface DHImageAtURLPatch : QCPatch
{
QCVirtualPort *inputURLOrURLs;
QCBooleanPort *inputUseCache;
QCVirtualPort *outputImageOrStructure;
QCBooleanPort *outputDone;

NSDictionary *_URLs;
NSMutableSet *_stillDownloading;
}

@end
137 changes: 137 additions & 0 deletions Origami Plugin/DHImageAtURLPatch.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*
*/

#import "DHImageAtURLPatch.h"
#import "NSArray+FBAdditions.h"
#import "NSURL+FBAdditions.h"
#import "QCPatch+FBAdditions.h"
#import "NSDocument+FBAdditions.h"

@interface DHImageAtURLPatch (Private)
- (void)_downloadImageAtURL:(NSString *)URL;
- (void)_updateOutputPorts;
@end

@implementation DHImageAtURLPatch

static NSMutableDictionary *_downloadedImages;

- (id)initWithIdentifier:(id)identifier {
if (self = [super initWithIdentifier:identifier]) {
inputUseCache.booleanValue = YES;
_stillDownloading = [[NSMutableSet alloc] init];
if (!_downloadedImages) {
_downloadedImages = [[NSMutableDictionary alloc] init];
}
}

return self;
}

+ (QCPatchExecutionMode)executionModeWithIdentifier:(id)identifier {
return kQCPatchExecutionModeProcessor;
}

+ (BOOL)allowsSubpatchesWithIdentifier:(id)identifier {
return NO;
}

+ (QCPatchTimeMode)timeModeWithIdentifier:(id)identifier {
return kQCPatchTimeModeNone;
}

- (BOOL)execute:(QCOpenGLContext *)context time:(double)time arguments:(NSDictionary *)arguments {
if (!(inputURLOrURLs.wasUpdated || inputUseCache.wasUpdated)) {
return YES;
}

id inputValue = inputURLOrURLs.rawValue;
if ([inputValue isKindOfClass:[NSString class]]) {
_URLs = @{@(0): inputValue};
} else if ([inputValue isKindOfClass:[QCStructure class]]) {
_URLs = [inputValue dictionaryRepresentation];
} else {
_URLs = @{};
}

[_stillDownloading removeAllObjects];
[self _updateOutputPorts];

for (id key in _URLs) {
NSString *URL = _URLs[key];
if (URL && (inputUseCache.booleanValue == NO || _downloadedImages[URL] == nil)) {
[_stillDownloading addObject:URL];
[NSThread detachNewThreadSelector:@selector(_downloadImageAtURL:) toTarget:self withObject:URL];
}
}

return YES;
}

@end

@implementation DHImageAtURLPatch (Private)

- (void)_downloadImageAtURL:(NSString *)URL {
if (!(URL && [URL isKindOfClass:[NSString class]])) {
return;
}

NSImage *image = [[NSImage alloc] initWithContentsOfURL:[NSURL URLWithQuartzComposerLocation:URL relativeToDocument:self.fb_document]];
_downloadedImages[URL] = image ? image : [NSNull null];
[_stillDownloading removeObject:URL];

[self performSelectorOnMainThread:@selector(_updateOutputPorts) withObject:nil waitUntilDone:NO];
}

- (void)_updateOutputPorts {
if (_URLs.count == 1) {
id result = _downloadedImages[[_URLs allValues][0]];
outputImageOrStructure.rawValue = (result && result != [NSNull null]) ? result : nil;
outputDone.booleanValue = YES;
return;
}

NSMutableDictionary *images = [[NSMutableDictionary alloc] initWithCapacity:_URLs.count];
if (_downloadedImages.count) {
for (id key in _URLs) {
NSString *URL = _URLs[key];
if (![_stillDownloading containsObject:URL]) {
NSImage *image = _downloadedImages[URL];
if (image) {
images[key] = image;
}
}
}
}

BOOL allKeysAreNumbers = YES;
for (id key in images) {
allKeysAreNumbers &= [key isKindOfClass:[NSNumber class]];
}

QCStructure *outputStructure = nil;
if (images.count) {
if (!allKeysAreNumbers) {
outputStructure = [[QCStructure alloc] initWithDictionary:images];
} else {
NSMutableArray *sortedImages = [[NSMutableArray alloc] initWithCapacity:images.count];
id keysArray = [[images allKeys] sortedArrayUsingAlphabeticalSort];
for (NSNumber *key in keysArray) {
[sortedImages addObject:images[key]];
}
outputStructure = [[QCStructure alloc] initWithArray:sortedImages];
}
}

outputImageOrStructure.rawValue = outputStructure;
outputDone.booleanValue = images.count ? (images.count == _URLs.count) : NO;
}

@end
65 changes: 65 additions & 0 deletions Origami Plugin/DHImageAtURLPatch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>nodeAttributes</key>
<dict>
<key>category</key>
<string>Origami</string>
<key>categories</key>
<array>
<string>Origami</string>
</array>
<key>description</key>
<string>Asynchronously downloads and caches requested images.

If you specify a single URL (a string), the image at that URL will be returned. If you specify multiple URLs (a structure of strings), a structure of images will be returned.


Origami
http://origami.facebook.com/

Use of this patch is subject to the license found at http://origami.facebook.com/license/

Copyright: (c) 2016, Facebook, Inc. All rights reserved.

Created by: Drew Hamlin</string>
<key>name</key>
<string>Image at URL</string>
</dict>
<key>inputAttributes</key>
<dict>
<key>inputURLOrURLs</key>
<dict>
<key>description</key>
<string></string>
<key>name</key>
<string>URL(s)</string>
</dict>
<key>inputUseCache</key>
<dict>
<key>description</key>
<string></string>
<key>name</key>
<string>Use Cache</string>
</dict>
</dict>
<key>outputAttributes</key>
<dict>
<key>outputImageOrStructure</key>
<dict>
<key>description</key>
<string></string>
<key>name</key>
<string>Image(s)</string>
</dict>
<key>outputDone</key>
<dict>
<key>description</key>
<string></string>
<key>name</key>
<string>Done</string>
</dict>
</dict>
</dict>
</plist>
20 changes: 20 additions & 0 deletions Origami Plugin/DHImageWithFormattedStrings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*
*/

#import <Foundation/Foundation.h>
#import <SkankySDK/SkankySDK.h>

@interface DHImageWithFormattedStrings : QCPatch
{
QCStringPort *inputString;
QCImagePort *outputImage;
QCStringPort *outputUnformattedString;
}

@end
Loading

0 comments on commit 26ef245

Please sign in to comment.