-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.5.0 Action extension to create class diagrams directly from Finder (#…
…23)
- Loading branch information
1 parent
113503b
commit 44837a7
Showing
16 changed files
with
530 additions
and
24 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,10 @@ | ||
<?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>com.apple.security.app-sandbox</key> | ||
<true/> | ||
<key>com.apple.security.files.user-selected.read-only</key> | ||
<true/> | ||
</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,58 @@ | ||
import Foundation | ||
import XPCService | ||
|
||
class ActionRequestHandler: NSObject, NSExtensionRequestHandling { | ||
lazy var connection: NSXPCConnection = { | ||
let connection = NSXPCConnection(serviceName: "us.eidinger.SwiftPlantUMLXPCService") | ||
connection.remoteObjectInterface = NSXPCInterface(with: XPCServiceProtocol.self) | ||
connection.resume() | ||
return connection | ||
}() | ||
|
||
deinit { | ||
connection.invalidate() | ||
} | ||
|
||
func beginRequest(with context: NSExtensionContext) { | ||
// For an Action Extension there will only ever be one extension item. | ||
precondition(context.inputItems.count == 1) | ||
guard let inputItem = context.inputItems[0] as? NSExtensionItem | ||
else { preconditionFailure("Expected an extension item") } | ||
|
||
// The extension item's attachments hold the set of files to process. | ||
guard let inputAttachments = inputItem.attachments | ||
else { preconditionFailure("Expected a valid array of attachments") } | ||
precondition(inputAttachments.isEmpty == false, "Expected at least one attachment") | ||
|
||
// The output of this extension is the existing swift files | ||
guard let inputAttachments = inputItem.attachments | ||
else { preconditionFailure("Expected a valid array of attachments") } | ||
|
||
let handler: (Error) -> Void = { error in | ||
print("remote proxy error: \(error)") | ||
} | ||
let service = connection.remoteObjectProxyWithErrorHandler(handler) as! XPCServiceProtocol | ||
var paths: [String] = [] | ||
|
||
// Use a dispatch group to synchronise asynchronous calls to loadInPlaceFileRepresentation. | ||
let dispatchGroup = DispatchGroup() | ||
|
||
for attachment in inputAttachments { | ||
dispatchGroup.enter() | ||
|
||
attachment.loadInPlaceFileRepresentation(forTypeIdentifier: "public.swift-source") { url, _, _ in | ||
if let url = url { | ||
paths.append(url.path) | ||
} | ||
|
||
dispatchGroup.leave() | ||
} | ||
} | ||
|
||
dispatchGroup.notify(queue: DispatchQueue.main) { | ||
service.generateDiagram(for: paths) { | ||
context.completeRequest(returningItems: [inputItem], completionHandler: nil) | ||
} | ||
} | ||
} | ||
} |
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,40 @@ | ||
<?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>CFBundleIconFile</key> | ||
<string></string> | ||
<key>NSExtension</key> | ||
<dict> | ||
<key>NSExtensionAttributes</key> | ||
<dict> | ||
<key>NSExtensionActivationRule</key> | ||
<string>SUBQUERY ( | ||
extensionItems, | ||
$extensionItem, | ||
SUBQUERY ( | ||
$extensionItem.attachments, | ||
$attachment, | ||
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.swift-source" | ||
).@count == $extensionItem.attachments.@count | ||
).@count == 1</string> | ||
<key>NSExtensionServiceAllowsFinderPreviewItem</key> | ||
<true/> | ||
<key>NSExtensionServiceAllowsTouchBarItem</key> | ||
<false/> | ||
<key>NSExtensionServiceFinderPreviewIconName</key> | ||
<string>Symbol</string> | ||
<key>NSExtensionServiceRoleType</key> | ||
<string>NSExtensionServiceRoleTypeEditor</string> | ||
<key>NSExtensionServiceTouchBarBezelColorName</key> | ||
<string>TouchBarBezel</string> | ||
<key>NSExtensionServiceTouchBarIconName</key> | ||
<string>Symbol</string> | ||
</dict> | ||
<key>NSExtensionPointIdentifier</key> | ||
<string>com.apple.services</string> | ||
<key>NSExtensionPrincipalClass</key> | ||
<string>$(PRODUCT_MODULE_NAME).ActionRequestHandler</string> | ||
</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,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
ActionExtension/Media.xcassets/Symbol.symbolset/Contents.json
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,30 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"symbols" : [ | ||
{ | ||
"filename" : "doc.badge.gearshape.svg", | ||
"idiom" : "universal" | ||
}, | ||
{ | ||
"appearances" : [ | ||
{ | ||
"appearance" : "luminosity", | ||
"value" : "light" | ||
} | ||
], | ||
"idiom" : "universal" | ||
}, | ||
{ | ||
"appearances" : [ | ||
{ | ||
"appearance" : "luminosity", | ||
"value" : "dark" | ||
} | ||
], | ||
"idiom" : "universal" | ||
} | ||
] | ||
} |
Oops, something went wrong.