Skip to content

Commit

Permalink
Add extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Apr 6, 2021
1 parent 7387302 commit 21e64f9
Show file tree
Hide file tree
Showing 10 changed files with 647 additions and 4 deletions.
279 changes: 279 additions & 0 deletions Brightroom.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions Import LUT/Action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Action.js
// Import LUT
//
// Created by Muukii on 2021/04/06.
// Copyright © 2021 muukii. All rights reserved.
//

var Action = function() {};

Action.prototype = {

run: function(arguments) {
// Here, you can run code that modifies the document and/or prepares
// things to pass to your action's native code.

// We will not modify anything, but will pass the body's background
// style to the native code.

arguments.completionFunction({ "currentBackgroundColor" : document.body.style.backgroundColor })
},

finalize: function(arguments) {
// This method is run after the native code completes.

// We'll see if the native code has passed us a new background style,
// and set it on the body.

var newBackgroundColor = arguments["newBackgroundColor"]
if (newBackgroundColor) {
// We'll set document.body.style.background, to override any
// existing background.
document.body.style.background = newBackgroundColor
} else {
// If nothing's been returned to us, we'll set the background to
// blue.
document.body.style.background= "blue"
}
}

};

var ExtensionPreprocessingJS = new Action
90 changes: 90 additions & 0 deletions Import LUT/ActionRequestHandler.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// ActionRequestHandler.swift
// Import LUT
//
// Created by Muukii on 2021/04/06.
// Copyright © 2021 muukii. All rights reserved.
//

import UIKit
import MobileCoreServices

class ActionRequestHandler: NSObject, NSExtensionRequestHandling {

var extensionContext: NSExtensionContext?

func beginRequest(with context: NSExtensionContext) {
// Do not call super in an Action extension with no user interface
// self.extensionContext = context

var found = false

// Find the item containing the results from the JavaScript preprocessing.
outer:
for item in context.inputItems as! [NSExtensionItem] {
if let attachments = item.attachments {
for itemProvider in attachments {
if itemProvider.hasItemConformingToTypeIdentifier(String(kUTTypePropertyList)) {
itemProvider.loadItem(forTypeIdentifier: String(kUTTypePropertyList), options: nil, completionHandler: { (item, error) in
let dictionary = item as! [String: Any]
OperationQueue.main.addOperation {
self.itemLoadCompletedWithPreprocessingResults(dictionary[NSExtensionJavaScriptPreprocessingResultsKey] as! [String: Any]? ?? [:])
}
})
found = true
break outer
}
}
}
}

if !found {
self.doneWithResults(nil)
}
}

func itemLoadCompletedWithPreprocessingResults(_ javaScriptPreprocessingResults: [String: Any]) {
// Here, do something, potentially asynchronously, with the preprocessing
// results.

// In this very simple example, the JavaScript will have passed us the
// current background color style, if there is one. We will construct a
// dictionary to send back with a desired new background color style.
let bgColor: Any? = javaScriptPreprocessingResults["currentBackgroundColor"]
if bgColor == nil || bgColor! as! String == "" {
// No specific background color? Request setting the background to red.
self.doneWithResults(["newBackgroundColor": "red"])
} else {
// Specific background color is set? Request replacing it with green.
self.doneWithResults(["newBackgroundColor": "green"])
}
}

func doneWithResults(_ resultsForJavaScriptFinalizeArg: [String: Any]?) {
if let resultsForJavaScriptFinalize = resultsForJavaScriptFinalizeArg {
// Construct an NSExtensionItem of the appropriate type to return our
// results dictionary in.

// These will be used as the arguments to the JavaScript finalize()
// method.

let resultsDictionary = [NSExtensionJavaScriptFinalizeArgumentKey: resultsForJavaScriptFinalize]

let resultsProvider = NSItemProvider(item: resultsDictionary as NSDictionary, typeIdentifier: String(kUTTypePropertyList))

let resultsItem = NSExtensionItem()
resultsItem.attachments = [resultsProvider]

// Signal that we're complete, returning our results.
self.extensionContext!.completeRequest(returningItems: [resultsItem], completionHandler: nil)
} else {
// We still need to signal that we're done even if we have nothing to
// pass back.
self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
}

// Don't hold on to this after we finished with it.
self.extensionContext = nil
}

}
59 changes: 59 additions & 0 deletions Import LUT/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Import LUT</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
<integer>0</integer>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>10</integer>
<key>NSExtensionActivationSupportsMovieWithMaxCount</key>
<integer>0</integer>
<key>NSExtensionActivationSupportsText</key>
<false/>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
</dict>
<key>NSExtensionJavaScriptPreprocessingFile</key>
<string>Action</string>
<key>NSExtensionServiceAllowsFinderPreviewItem</key>
<true/>
<key>NSExtensionServiceAllowsTouchBarItem</key>
<true/>
<key>NSExtensionServiceFinderPreviewIconName</key>
<string>NSActionTemplate</string>
<key>NSExtensionServiceTouchBarBezelColorName</key>
<string>TouchBarBezel</string>
<key>NSExtensionServiceTouchBarIconName</key>
<string>NSActionTemplate</string>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.services</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).ActionRequestHandler</string>
</dict>
</dict>
</plist>
6 changes: 6 additions & 0 deletions Import LUT/Media.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
14 changes: 14 additions & 0 deletions Import LUT/Media.xcassets/TouchBarBezel.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "mac",
"color" : {
"reference" : "systemPurpleColor"
}
}
]
}
24 changes: 24 additions & 0 deletions ShareLUT/Base.lproj/MainInterface.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="j1y-V4-xli">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Share View Controller-->
<scene sceneID="ceB-am-kn3">
<objects>
<viewController id="j1y-V4-xli" customClass="ShareViewController" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" opaque="NO" contentMode="scaleToFill" id="wbc-yd-nQP">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="1Xd-am-t49"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="CEy-Cv-SGf" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
</document>
36 changes: 36 additions & 0 deletions ShareLUT/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>ShareLUT</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<string>TRUEPREDICATE</string>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>
</dict>
</plist>
31 changes: 31 additions & 0 deletions ShareLUT/ShareViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// ShareViewController.swift
// ShareLUT
//
// Created by Muukii on 2021/04/06.
// Copyright © 2021 muukii. All rights reserved.
//

import UIKit
import Social

class ShareViewController: SLComposeServiceViewController {

override func isContentValid() -> Bool {
// Do validation of contentText and/or NSExtensionContext attachments here
return true
}

override func didSelectPost() {
// This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.

// Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.
self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
}

override func configurationItems() -> [Any]! {
// To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here.
return []
}

}
Loading

0 comments on commit 21e64f9

Please sign in to comment.