This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Brandon Walkin
committed
Mar 15, 2016
1 parent
6566c55
commit 26ef245
Showing
137 changed files
with
12,608 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.