file provider does not connect
This commit is contained in:
@@ -11,86 +11,70 @@ import FileProvider
|
||||
import SimpleX_Service
|
||||
|
||||
let SIMPLEX_SERVICE_NAME = NSFileProviderServiceName("group.chat.simplex.app.service")
|
||||
//let SERVICE_PROXY_ITEM = "chat.simplex.service:/123"
|
||||
let SERVICE_PROXY_ITEM = "chat.simplex.service:/123"
|
||||
//let SERVICE_PROXY_ITEM_URL = URL(string: SERVICE_PROXY_ITEM)!
|
||||
//let SERVICE_PROXY_ITEM_ID = NSFileProviderItemIdentifier(SERVICE_PROXY_ITEM)
|
||||
let SERVICE_PROXY_ITEM_ID = NSFileProviderItemIdentifier(SERVICE_PROXY_ITEM)
|
||||
|
||||
@objc public protocol SimpleXFPServiceProtocol {
|
||||
func upperCaseString(_ string: String, withReply reply: @escaping (String) -> Void)
|
||||
}
|
||||
|
||||
class EnumObserver: NSObject, NSFileProviderEnumerationObserver {
|
||||
func didEnumerate(_ updatedItems: [NSFileProviderItemProtocol]) {
|
||||
|
||||
}
|
||||
|
||||
func finishEnumerating(upTo nextPage: NSFileProviderPage?) {
|
||||
|
||||
}
|
||||
|
||||
func finishEnumeratingWithError(_ error: Error) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func testFPService() {
|
||||
logger.debug("testFPService get services")
|
||||
let manager = NSFileProviderManager.default
|
||||
// TODO try access file
|
||||
logger.debug("testFPService NSFileProviderManager.documentStorageURL \(manager.documentStorageURL, privacy: .public)")
|
||||
// manager.getUserVisibleURL(for: SERVICE_PROXY_ITEM_ID) { url, error in
|
||||
// logger.debug("testFPService NSFileProviderManager.getUserVisibleURL \(url, privacy: .public)")
|
||||
// return
|
||||
FileManager.default.getFileProviderServicesForItem(at: URL(string: "\(manager.documentStorageURL)123")!) { (services, error) in
|
||||
|
||||
// Check to see if an error occurred.
|
||||
guard error == nil else {
|
||||
logger.debug("testFPService error getting service")
|
||||
print(error!)
|
||||
// Handle the error here...
|
||||
return
|
||||
}
|
||||
FileManager.default.getFileProviderServicesForItem(at: URL(string: "\(manager.documentStorageURL)123")!) { (services, error) in
|
||||
|
||||
if let desiredService = services?[SIMPLEX_SERVICE_NAME] {
|
||||
logger.debug("testFPService has desiredService")
|
||||
|
||||
// The named service is available for the item at the provided URL.
|
||||
// To use the service, get the connection object.
|
||||
desiredService.getFileProviderConnection(completionHandler: { (connectionOrNil, connectionError) in
|
||||
|
||||
guard connectionError == nil else {
|
||||
// Handle the error here...
|
||||
return
|
||||
}
|
||||
|
||||
guard let connection = connectionOrNil else {
|
||||
// No connection object found.
|
||||
return
|
||||
}
|
||||
|
||||
// Set the remote interface.
|
||||
connection.remoteObjectInterface = NSXPCInterface(with: SimpleXFPServiceProtocol.self)
|
||||
|
||||
// Start the connection.
|
||||
connection.resume()
|
||||
|
||||
// Get the proxy object.
|
||||
let rawProxy = connection.remoteObjectProxyWithErrorHandler({ (errorAccessingRemoteObject) in
|
||||
// Handle the error here...
|
||||
})
|
||||
|
||||
// Cast the proxy object to the interface's protocol.
|
||||
guard let proxy = rawProxy as? SimpleXFPServiceProtocol else {
|
||||
// If the interface is set up properly, this should never fail.
|
||||
fatalError("*** Unable to cast \(rawProxy) to a DesiredProtocol instance ***")
|
||||
}
|
||||
|
||||
logger.debug("testFPService calling service")
|
||||
proxy.upperCaseString("hello to service", withReply: { reply in
|
||||
logger.debug("testFPService reply from service \(reply)")
|
||||
})
|
||||
})
|
||||
}
|
||||
// Check to see if an error occurred.
|
||||
guard error == nil else {
|
||||
logger.debug("testFPService error getting service")
|
||||
print(error!) // <-- this prints the error I posted
|
||||
// Handle the error here...
|
||||
return
|
||||
}
|
||||
// }
|
||||
|
||||
if let desiredService = services?[SIMPLEX_SERVICE_NAME] {
|
||||
logger.debug("testFPService has desiredService")
|
||||
|
||||
// The named service is available for the item at the provided URL.
|
||||
// To use the service, get the connection object.
|
||||
desiredService.getFileProviderConnection(completionHandler: { (connectionOrNil, connectionError) in
|
||||
|
||||
guard connectionError == nil else {
|
||||
// Handle the error here...
|
||||
return
|
||||
}
|
||||
|
||||
guard let connection = connectionOrNil else {
|
||||
// No connection object found.
|
||||
return
|
||||
}
|
||||
|
||||
// Set the remote interface.
|
||||
connection.remoteObjectInterface = NSXPCInterface(with: SimpleXFPServiceProtocol.self)
|
||||
|
||||
// Start the connection.
|
||||
connection.resume()
|
||||
|
||||
// Get the proxy object.
|
||||
let rawProxy = connection.remoteObjectProxyWithErrorHandler({ (errorAccessingRemoteObject) in
|
||||
// Handle the error here...
|
||||
})
|
||||
|
||||
// Cast the proxy object to the interface's protocol.
|
||||
guard let proxy = rawProxy as? SimpleXFPServiceProtocol else {
|
||||
// If the interface is set up properly, this should never fail.
|
||||
fatalError("*** Unable to cast \(rawProxy) to a DesiredProtocol instance ***")
|
||||
}
|
||||
|
||||
logger.debug("testFPService calling service")
|
||||
proxy.upperCaseString("hello to service", withReply: { reply in
|
||||
logger.debug("testFPService reply from service \(reply)")
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,23 @@ class FileProviderExtension: NSFileProviderExtension {
|
||||
let manager = NSFileProviderManager.default
|
||||
logger.debug("FileProviderExtension.init NSFileProviderManager \(manager.documentStorageURL, privacy: .public)")
|
||||
|
||||
// FileManager.default.createFile(atPath: "\(manager.documentStorageURL)123", contents: "hello".data(using: .utf8))
|
||||
|
||||
self.providePlaceholder(at: URL(string: "\(manager.documentStorageURL)123")!) { err in
|
||||
if let err = err {
|
||||
logger.debug("FileProviderExtension.providePlaceholder error \(String(describing: err), privacy: .public)")
|
||||
} else {
|
||||
logger.debug("FileProviderExtension.providePlaceholder ok") // <-- this returns ok
|
||||
// self.startProvidingItem(at: URL(string: "\(manager.documentStorageURL)123")!) { err in
|
||||
// if let err = err {
|
||||
// logger.debug("FileProviderExtension.startProvidingItem error \(String(describing: err), privacy: .public)")
|
||||
// } else {
|
||||
// logger.debug("FileProviderExtension.startProvidingItem ok")
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
serviceListener.delegate = listenerDelegate
|
||||
Task { serviceListener.resume() }
|
||||
}
|
||||
@@ -50,7 +67,11 @@ class FileProviderExtension: NSFileProviderExtension {
|
||||
|
||||
return perItemDirectory.appendingPathComponent(item.filename, isDirectory:false)
|
||||
}
|
||||
|
||||
|
||||
func identifierForItemAtURL(_ url: URL, completionHandler: @escaping (NSFileProviderItemIdentifier?) -> Void) {
|
||||
completionHandler(SERVICE_PROXY_ITEM_ID)
|
||||
}
|
||||
|
||||
override func persistentIdentifierForItem(at url: URL) -> NSFileProviderItemIdentifier? {
|
||||
logger.debug("FileProviderExtension.persistentIdentifierForItem")
|
||||
// if url == SERVICE_PROXY_ITEM_URL { return SERVICE_PROXY_ITEM_ID }
|
||||
@@ -76,7 +97,7 @@ class FileProviderExtension: NSFileProviderExtension {
|
||||
do {
|
||||
let fileProviderItem = try item(for: identifier)
|
||||
let placeholderURL = NSFileProviderManager.placeholderURL(for: url)
|
||||
try NSFileProviderManager.writePlaceholder(at: placeholderURL,withMetadata: fileProviderItem)
|
||||
try NSFileProviderManager.writePlaceholder(at: placeholderURL, withMetadata: fileProviderItem)
|
||||
completionHandler(nil)
|
||||
} catch let error {
|
||||
completionHandler(error)
|
||||
|
||||
@@ -14,24 +14,19 @@ class FileProviderItem: NSObject, NSFileProviderItem {
|
||||
// TODO: implement an initializer to create an item from your extension's backing model
|
||||
// TODO: implement the accessors to return the values from your extension's backing model
|
||||
|
||||
var itemIdentifier: NSFileProviderItemIdentifier {
|
||||
return NSFileProviderItemIdentifier("")
|
||||
}
|
||||
var itemIdentifier: NSFileProviderItemIdentifier { SERVICE_PROXY_ITEM_ID }
|
||||
|
||||
var parentItemIdentifier: NSFileProviderItemIdentifier {
|
||||
return NSFileProviderItemIdentifier("")
|
||||
}
|
||||
var parentItemIdentifier: NSFileProviderItemIdentifier { NSFileProviderItemIdentifier("1") }
|
||||
|
||||
var capabilities: NSFileProviderItemCapabilities {
|
||||
return [.allowsReading, .allowsWriting, .allowsRenaming, .allowsReparenting, .allowsTrashing, .allowsDeleting]
|
||||
[.allowsReading, .allowsWriting, .allowsRenaming, .allowsReparenting, .allowsTrashing, .allowsDeleting]
|
||||
}
|
||||
|
||||
var filename: String {
|
||||
return ""
|
||||
}
|
||||
var filename: String { "123" }
|
||||
|
||||
var contentType: UTType {
|
||||
return itemIdentifier == NSFileProviderItemIdentifier.rootContainer ? .folder : .plainText
|
||||
itemIdentifier == NSFileProviderItemIdentifier.rootContainer ? .folder : .plainText
|
||||
}
|
||||
|
||||
|
||||
var documentSize: NSNumber? { 1 }
|
||||
}
|
||||
|
||||
@@ -15,13 +15,6 @@ let SIMPLEX_SERVICE_NAME = NSFileProviderServiceName("group.chat.simplex.app.ser
|
||||
let SERVICE_PROXY_ITEM_ID = NSFileProviderItemIdentifier("123")
|
||||
|
||||
class SimpleXFPService: SimpleXFPServiceProtocol {
|
||||
// override var name: NSFileProviderServiceName { SIMPLEX_SERVICE_NAME }
|
||||
//
|
||||
// override func getFileProviderConnection(completionHandler: @escaping (NSXPCConnection?, Error?) -> Void) {
|
||||
// logger.debug("FileProviderExtension SimpleXFPService.getFileProviderConnection")
|
||||
// completionHandler(NSXPCConnection(listenerEndpoint: serviceListener.endpoint), nil)
|
||||
// }
|
||||
|
||||
func upperCaseString(_ string: String, withReply reply: @escaping (String) -> Void) {
|
||||
logger.debug("FileProviderExtension SimpleXFPService.upperCaseString")
|
||||
let response = string.uppercased()
|
||||
|
||||
@@ -1201,7 +1201,7 @@
|
||||
buildSettings = {
|
||||
CODE_SIGN_ENTITLEMENTS = "SimpleX Service/SimpleX_Service.entitlements";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 49;
|
||||
CURRENT_PROJECT_VERSION = 51;
|
||||
DEVELOPMENT_TEAM = 5NN7GUYB6T;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_FILE = "SimpleX Service/Info.plist";
|
||||
@@ -1229,7 +1229,7 @@
|
||||
buildSettings = {
|
||||
CODE_SIGN_ENTITLEMENTS = "SimpleX Service/SimpleX_Service.entitlements";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 49;
|
||||
CURRENT_PROJECT_VERSION = 51;
|
||||
DEVELOPMENT_TEAM = 5NN7GUYB6T;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_FILE = "SimpleX Service/Info.plist";
|
||||
|
||||
Reference in New Issue
Block a user