diff --git a/extension/safari/TabFS/TabFS Extension/SafariWebExtensionHandler.swift b/extension/safari/TabFS/TabFS Extension/SafariWebExtensionHandler.swift index e5a7b51..d3b6843 100644 --- a/extension/safari/TabFS/TabFS Extension/SafariWebExtensionHandler.swift +++ b/extension/safari/TabFS/TabFS Extension/SafariWebExtensionHandler.swift @@ -12,43 +12,35 @@ class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling { func beginRequest(with context: NSExtensionContext) { - os_log(.default, "TabFSmsg Received message from browser.runtime.sendNativefffMessage: %@", context as! CVarArg) - let item = context.inputItems[0] as! NSExtensionItem - - os_log(.default, "TabFSmsg item.userInfo %{public}@", item.userInfo as! CVarArg) guard let message = item.userInfo?["message"] as? [AnyHashable: Any] else { return } + + guard message["op"] as! String == "safari_did_connect" else { return } - if message["op"] as! String == "safari_did_connect" { - os_log(.default, "TabFSmsg sdc") + // The XPC service is a subprocess that lives outside the macOS App Sandbox. + // It can do forbidden things like spawn tabfs filesystem and set up WebSocket server. + + let connection = NSXPCConnection(serviceName: "com.rsnous.TabFSService") + connection.remoteObjectInterface = NSXPCInterface(with: TabFSServiceProtocol.self) + connection.resume() + + let service = connection.remoteObjectProxyWithErrorHandler { error in + os_log(.default, "Received error: %{public}@", error as! CVarArg) + } as? TabFSServiceProtocol + + // need this one XPC call to actually initialize the service + service?.upperCaseString("hello XPC") { response in + os_log(.default, "Response from XPC service: %{public}@", response) - // The XPC service is a subprocess that lives outside the macOS App Sandbox. - // It can do forbidden things like spawn tabfs filesystem and set up WebSocket server. - - let connection = NSXPCConnection(serviceName: "com.rsnous.TabFSService") - - connection.remoteObjectInterface = NSXPCInterface(with: TabFSServiceProtocol.self) - - connection.resume() - - let service = connection.remoteObjectProxyWithErrorHandler { error in - os_log(.default, "Received error: %{public}@", error as! CVarArg) - } as? TabFSServiceProtocol - - // need this one XPC call to actually initialize the service - service?.upperCaseString("hello XPC") { response in - os_log(.default, "Response from XPC service: %{public}@", response) - - // FIXME: report port back? - let response = NSExtensionItem() - response.userInfo = [ "message": [ "aResponse to": "moop" ] ] - context.completeRequest(returningItems: [response]) { (what) in - print(what) - } + // FIXME: report port back? + let response = NSExtensionItem() + response.userInfo = [ "message": [ "aResponse to": "moop" ] ] + context.completeRequest(returningItems: [response]) { (what) in + print(what) } - - return } + + return } } diff --git a/extension/safari/TabFS/TabFS.xcodeproj/project.xcworkspace/xcuserdata/osnr.xcuserdatad/UserInterfaceState.xcuserstate b/extension/safari/TabFS/TabFS.xcodeproj/project.xcworkspace/xcuserdata/osnr.xcuserdatad/UserInterfaceState.xcuserstate index 961a29f..7b02891 100644 Binary files a/extension/safari/TabFS/TabFS.xcodeproj/project.xcworkspace/xcuserdata/osnr.xcuserdatad/UserInterfaceState.xcuserstate and b/extension/safari/TabFS/TabFS.xcodeproj/project.xcworkspace/xcuserdata/osnr.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/extension/safari/TabFS/TabFS.xcodeproj/xcuserdata/osnr.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/extension/safari/TabFS/TabFS.xcodeproj/xcuserdata/osnr.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 0a7caef..2134761 100644 --- a/extension/safari/TabFS/TabFS.xcodeproj/xcuserdata/osnr.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/extension/safari/TabFS/TabFS.xcodeproj/xcuserdata/osnr.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -14,8 +14,8 @@ filePath = "TabFS Extension/SafariWebExtensionHandler.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "17" - endingLineNumber = "17" + startingLineNumber = "15" + endingLineNumber = "15" landmarkName = "beginRequest(with:)" landmarkType = "7"> @@ -36,37 +36,5 @@ landmarkType = "7"> - - - - - - - - diff --git a/extension/safari/TabFS/TabFSService/TabFSService.swift b/extension/safari/TabFS/TabFSService/TabFSService.swift index ee58fa0..c722eac 100644 --- a/extension/safari/TabFS/TabFSService/TabFSService.swift +++ b/extension/safari/TabFS/TabFSService/TabFSService.swift @@ -27,9 +27,7 @@ class TabFSService: NSObject, TabFSServiceProtocol { fsInput = inputPipe.fileHandleForWriting fsOutput = outputPipe.fileHandleForReading - os_log(.default, "TabFSmsg tfs service: willrun") try! fs.run() - os_log(.default, "TabFSmsg tfs service: ran") } var ws: NWListener! @@ -61,7 +59,7 @@ class TabFSService: NSObject, TabFSServiceProtocol { let context = NWConnection.ContentContext(identifier: "context", metadata: [metaData]) conn.send(content: req, contentContext: context, completion: .contentProcessed({ err in if err != nil { - os_log(.default, "%{public}@ error: %{public}@", String(data: req, encoding: .utf8) as! CVarArg, err!.debugDescription as CVarArg) + os_log(.default, "req %{public}@ error: %{public}@", String(data: req, encoding: .utf8) as! CVarArg, err!.debugDescription as CVarArg) // FIXME: ERROR } })) @@ -75,7 +73,6 @@ class TabFSService: NSObject, TabFSServiceProtocol { return } - os_log(.default, "resp %{public}@", String(data: resp, encoding: .utf8) as! CVarArg) self.fsInput.write(withUnsafeBytes(of: UInt32(resp.count)) { Data($0) }) self.fsInput.write(resp) read() @@ -89,7 +86,6 @@ class TabFSService: NSObject, TabFSServiceProtocol { while true { // read from them let length = self.fsOutput.readData(ofLength: 4).withUnsafeBytes { $0.load(as: UInt32.self) } - os_log(.default, "TabFSmsg tfs service: read %{public}d", length) let req = self.fsOutput.readData(ofLength: Int(length)) // send to other side of WEBSOCKET @@ -107,17 +103,10 @@ class TabFSService: NSObject, TabFSServiceProtocol { let response = string.uppercased() reply(response) } -// -// func response(_ resp: Data) { -// fsInput.write(withUnsafeBytes(of: UInt32(resp.count)) { Data($0) }) -// fsInput.write(resp) -// } } class TabFSServiceDelegate: NSObject, NSXPCListenerDelegate { func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool { - os_log(.default, "TabFSmsg tfs service: starting delegate") - let exportedObject = TabFSService() newConnection.exportedInterface = NSXPCInterface(with: TabFSServiceProtocol.self) newConnection.exportedObject = exportedObject