mirror of
https://github.com/osnr/TabFS.git
synced 2024-06-10 09:52:21 +02:00
safari: clean up code a bit
This commit is contained in:
parent
b19f68cc8e
commit
78f67aa873
|
@ -12,23 +12,16 @@ class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
|
||||||
|
|
||||||
func beginRequest(with context: NSExtensionContext) {
|
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
|
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 let message = item.userInfo?["message"] as? [AnyHashable: Any] else { return }
|
||||||
|
|
||||||
if message["op"] as! String == "safari_did_connect" {
|
guard message["op"] as! String == "safari_did_connect" else { return }
|
||||||
os_log(.default, "TabFSmsg sdc")
|
|
||||||
|
|
||||||
// The XPC service is a subprocess that lives outside the macOS App Sandbox.
|
// 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.
|
// It can do forbidden things like spawn tabfs filesystem and set up WebSocket server.
|
||||||
|
|
||||||
let connection = NSXPCConnection(serviceName: "com.rsnous.TabFSService")
|
let connection = NSXPCConnection(serviceName: "com.rsnous.TabFSService")
|
||||||
|
|
||||||
connection.remoteObjectInterface = NSXPCInterface(with: TabFSServiceProtocol.self)
|
connection.remoteObjectInterface = NSXPCInterface(with: TabFSServiceProtocol.self)
|
||||||
|
|
||||||
connection.resume()
|
connection.resume()
|
||||||
|
|
||||||
let service = connection.remoteObjectProxyWithErrorHandler { error in
|
let service = connection.remoteObjectProxyWithErrorHandler { error in
|
||||||
|
@ -49,6 +42,5 @@ class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -14,8 +14,8 @@
|
||||||
filePath = "TabFS Extension/SafariWebExtensionHandler.swift"
|
filePath = "TabFS Extension/SafariWebExtensionHandler.swift"
|
||||||
startingColumnNumber = "9223372036854775807"
|
startingColumnNumber = "9223372036854775807"
|
||||||
endingColumnNumber = "9223372036854775807"
|
endingColumnNumber = "9223372036854775807"
|
||||||
startingLineNumber = "17"
|
startingLineNumber = "15"
|
||||||
endingLineNumber = "17"
|
endingLineNumber = "15"
|
||||||
landmarkName = "beginRequest(with:)"
|
landmarkName = "beginRequest(with:)"
|
||||||
landmarkType = "7">
|
landmarkType = "7">
|
||||||
</BreakpointContent>
|
</BreakpointContent>
|
||||||
|
@ -36,37 +36,5 @@
|
||||||
landmarkType = "7">
|
landmarkType = "7">
|
||||||
</BreakpointContent>
|
</BreakpointContent>
|
||||||
</BreakpointProxy>
|
</BreakpointProxy>
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "C3177652-3D89-4E01-8BF5-03C666008BDB"
|
|
||||||
shouldBeEnabled = "Yes"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "TabFS Extension/SafariWebExtensionHandler.swift"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "20"
|
|
||||||
endingLineNumber = "20"
|
|
||||||
landmarkName = "beginRequest(with:)"
|
|
||||||
landmarkType = "7">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
uuid = "111CBF7A-E3E9-4303-9961-9812F8781A39"
|
|
||||||
shouldBeEnabled = "Yes"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "TabFS Extension/SafariWebExtensionHandler.swift"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "15"
|
|
||||||
endingLineNumber = "15"
|
|
||||||
landmarkName = "beginRequest(with:)"
|
|
||||||
landmarkType = "7">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
</Breakpoints>
|
</Breakpoints>
|
||||||
</Bucket>
|
</Bucket>
|
||||||
|
|
|
@ -27,9 +27,7 @@ class TabFSService: NSObject, TabFSServiceProtocol {
|
||||||
fsInput = inputPipe.fileHandleForWriting
|
fsInput = inputPipe.fileHandleForWriting
|
||||||
fsOutput = outputPipe.fileHandleForReading
|
fsOutput = outputPipe.fileHandleForReading
|
||||||
|
|
||||||
os_log(.default, "TabFSmsg tfs service: willrun")
|
|
||||||
try! fs.run()
|
try! fs.run()
|
||||||
os_log(.default, "TabFSmsg tfs service: ran")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var ws: NWListener!
|
var ws: NWListener!
|
||||||
|
@ -61,7 +59,7 @@ class TabFSService: NSObject, TabFSServiceProtocol {
|
||||||
let context = NWConnection.ContentContext(identifier: "context", metadata: [metaData])
|
let context = NWConnection.ContentContext(identifier: "context", metadata: [metaData])
|
||||||
conn.send(content: req, contentContext: context, completion: .contentProcessed({ err in
|
conn.send(content: req, contentContext: context, completion: .contentProcessed({ err in
|
||||||
if err != nil {
|
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
|
// FIXME: ERROR
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
@ -75,7 +73,6 @@ class TabFSService: NSObject, TabFSServiceProtocol {
|
||||||
return
|
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(withUnsafeBytes(of: UInt32(resp.count)) { Data($0) })
|
||||||
self.fsInput.write(resp)
|
self.fsInput.write(resp)
|
||||||
read()
|
read()
|
||||||
|
@ -89,7 +86,6 @@ class TabFSService: NSObject, TabFSServiceProtocol {
|
||||||
while true {
|
while true {
|
||||||
// read from them
|
// read from them
|
||||||
let length = self.fsOutput.readData(ofLength: 4).withUnsafeBytes { $0.load(as: UInt32.self) }
|
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))
|
let req = self.fsOutput.readData(ofLength: Int(length))
|
||||||
|
|
||||||
// send to other side of WEBSOCKET
|
// send to other side of WEBSOCKET
|
||||||
|
@ -107,17 +103,10 @@ class TabFSService: NSObject, TabFSServiceProtocol {
|
||||||
let response = string.uppercased()
|
let response = string.uppercased()
|
||||||
reply(response)
|
reply(response)
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// func response(_ resp: Data) {
|
|
||||||
// fsInput.write(withUnsafeBytes(of: UInt32(resp.count)) { Data($0) })
|
|
||||||
// fsInput.write(resp)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TabFSServiceDelegate: NSObject, NSXPCListenerDelegate {
|
class TabFSServiceDelegate: NSObject, NSXPCListenerDelegate {
|
||||||
func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool {
|
func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool {
|
||||||
os_log(.default, "TabFSmsg tfs service: starting delegate")
|
|
||||||
|
|
||||||
let exportedObject = TabFSService()
|
let exportedObject = TabFSService()
|
||||||
newConnection.exportedInterface = NSXPCInterface(with: TabFSServiceProtocol.self)
|
newConnection.exportedInterface = NSXPCInterface(with: TabFSServiceProtocol.self)
|
||||||
newConnection.exportedObject = exportedObject
|
newConnection.exportedObject = exportedObject
|
||||||
|
|
Loading…
Reference in a new issue