mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Initial work fetching URL, title, and selected text from webpage
This commit is contained in:
parent
849a4fa44f
commit
2dccaf7196
19
ActionExtension-iOS/Action.js
Normal file
19
ActionExtension-iOS/Action.js
Normal file
@ -0,0 +1,19 @@
|
||||
var Action = function() {};
|
||||
|
||||
Action.prototype = {
|
||||
|
||||
run: function(parameters) {
|
||||
parameters.completionFunction({
|
||||
"URL": document.URL,
|
||||
"title": document.title,
|
||||
"selection": document.getSelection().toString()
|
||||
});
|
||||
},
|
||||
|
||||
finalize: function(parameters) {
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var ExtensionPreprocessingJS = new Action
|
@ -1,10 +1,3 @@
|
||||
//
|
||||
// ActionViewController.swift
|
||||
// ActionExtension-iOS
|
||||
//
|
||||
// Created by Angelo Stavrow on 2021-11-05.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import MobileCoreServices
|
||||
import UniformTypeIdentifiers
|
||||
@ -15,36 +8,16 @@ class ActionViewController: UIViewController {
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
|
||||
// Get the item[s] we're handling from the extension context.
|
||||
|
||||
// For example, look for an image and place it into an image view.
|
||||
// Replace this with something appropriate for the type[s] your extension supports.
|
||||
var imageFound = false
|
||||
for item in self.extensionContext!.inputItems as! [NSExtensionItem] {
|
||||
for provider in item.attachments! {
|
||||
if provider.hasItemConformingToTypeIdentifier(UTType.image.identifier) {
|
||||
// This is an image. We'll load it, then place it in our image view.
|
||||
weak var weakImageView = self.imageView
|
||||
provider.loadItem(forTypeIdentifier: UTType.image.identifier, options: nil, completionHandler: { (imageURL, error) in
|
||||
OperationQueue.main.addOperation {
|
||||
if let strongImageView = weakImageView {
|
||||
if let imageURL = imageURL as? URL {
|
||||
strongImageView.image = UIImage(data: try! Data(contentsOf: imageURL))
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
imageFound = true
|
||||
break
|
||||
if let inputItem = extensionContext?.inputItems.first as? NSExtensionItem {
|
||||
if let itemProvider = inputItem.attachments?.first {
|
||||
itemProvider.loadItem(forTypeIdentifier: kUTTypePropertyList as String) { [weak self] dict, error in
|
||||
guard let itemDictionary = dict as? NSDictionary else { return }
|
||||
guard let javaScriptValues = itemDictionary[NSExtensionJavaScriptPreprocessingResultsKey] as? NSDictionary else { return }
|
||||
print(javaScriptValues)
|
||||
}
|
||||
}
|
||||
|
||||
if (imageFound) {
|
||||
// We only handle one image, so stop looking for more.
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,13 @@
|
||||
<dict>
|
||||
<key>NSExtensionAttributes</key>
|
||||
<dict>
|
||||
<key>NSExtensionJavaScriptPreprocessingFile</key>
|
||||
<string>Action</string>
|
||||
<key>NSExtensionActivationRule</key>
|
||||
<string>TRUEPREDICATE</string>
|
||||
<dict>
|
||||
<key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
<key>NSExtensionServiceAllowsFinderPreviewItem</key>
|
||||
<true/>
|
||||
<key>NSExtensionServiceAllowsTouchBarItem</key>
|
||||
|
@ -32,6 +32,7 @@
|
||||
172E10062735B83E00061372 /* ActionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172E10052735B83E00061372 /* ActionViewController.swift */; };
|
||||
172E10092735B83E00061372 /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 172E10072735B83E00061372 /* MainInterface.storyboard */; };
|
||||
172E100D2735B83E00061372 /* ActionExtension-iOS.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 172E0FFF2735B83E00061372 /* ActionExtension-iOS.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
|
||||
172E10132735BB6200061372 /* Action.js in Resources */ = {isa = PBXBuildFile; fileRef = 172E10122735BB6200061372 /* Action.js */; };
|
||||
173E19D1254318F600440F0F /* RemoteChangePromptView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 173E19D0254318F600440F0F /* RemoteChangePromptView.swift */; };
|
||||
173E19E3254329CC00440F0F /* PostTextEditingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 173E19E2254329CC00440F0F /* PostTextEditingView.swift */; };
|
||||
17466626256C0D0600629997 /* MacEditorTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17466625256C0D0600629997 /* MacEditorTextView.swift */; };
|
||||
@ -171,6 +172,7 @@
|
||||
172E10052735B83E00061372 /* ActionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionViewController.swift; sourceTree = "<group>"; };
|
||||
172E10082735B83E00061372 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = "<group>"; };
|
||||
172E100A2735B83E00061372 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
172E10122735BB6200061372 /* Action.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = Action.js; sourceTree = "<group>"; };
|
||||
173E19D0254318F600440F0F /* RemoteChangePromptView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteChangePromptView.swift; sourceTree = "<group>"; };
|
||||
173E19E2254329CC00440F0F /* PostTextEditingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostTextEditingView.swift; sourceTree = "<group>"; };
|
||||
17466625256C0D0600629997 /* MacEditorTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacEditorTextView.swift; sourceTree = "<group>"; };
|
||||
@ -310,6 +312,7 @@
|
||||
172E10052735B83E00061372 /* ActionViewController.swift */,
|
||||
172E10072735B83E00061372 /* MainInterface.storyboard */,
|
||||
172E100A2735B83E00061372 /* Info.plist */,
|
||||
172E10122735BB6200061372 /* Action.js */,
|
||||
);
|
||||
path = "ActionExtension-iOS";
|
||||
sourceTree = "<group>";
|
||||
@ -736,6 +739,7 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
172E10132735BB6200061372 /* Action.js in Resources */,
|
||||
172E10042735B83E00061372 /* Media.xcassets in Resources */,
|
||||
172E10092735B83E00061372 /* MainInterface.storyboard in Resources */,
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user