diff options
author | Omar Rizwan <omar@omar.website> | 2021-02-08 13:45:26 -0800 |
---|---|---|
committer | Omar Rizwan <omar@omar.website> | 2021-02-08 13:45:26 -0800 |
commit | 0f2ab4b4de7e828757091e323be1caab0a70b770 (patch) | |
tree | 39d35441314690e45235af7e2ecee91c92a19264 /extension/safari/TabFS/TabFSService | |
parent | 2f639e2a0276efb3dbb8a470e61ee8ffc2503f5b (diff) | |
download | TabFS-0f2ab4b4de7e828757091e323be1caab0a70b770.tar.gz TabFS-0f2ab4b4de7e828757091e323be1caab0a70b770.zip |
safari: fix some races when you reload Web inspector, make ws connection retry
Diffstat (limited to 'extension/safari/TabFS/TabFSService')
-rw-r--r-- | extension/safari/TabFS/TabFSService/TabFSService.swift | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/extension/safari/TabFS/TabFSService/TabFSService.swift b/extension/safari/TabFS/TabFSService/TabFSService.swift index 4a86dd6..5bf55ee 100644 --- a/extension/safari/TabFS/TabFSService/TabFSService.swift +++ b/extension/safari/TabFS/TabFSService/TabFSService.swift @@ -12,13 +12,36 @@ import os.log class TabFSService: NSObject, TabFSServiceProtocol { func start(withReply reply: @escaping () -> Void) { // This XPC call is enough to just force the XPC service to be started. - os_log("HELLO") + + // kill old copies of TabFSServer + let killall = Process() + killall.launchPath = "/usr/bin/killall" + killall.arguments = ["TabFSServer"] + killall.launch() + killall.waitUntilExit() + + // spin until old TabFSServer (if any) is gone + while true { + let pgrep = Process() + pgrep.launchPath = "/usr/bin/pgrep" + pgrep.arguments = ["TabFSServer"] + pgrep.launch() + pgrep.waitUntilExit() + if pgrep.terminationStatus != 0 { break } + + Thread.sleep(forTimeInterval: 0.01) + } + let server = Process() - os_log("HOW ARE YOU?") + let serverOutput = Pipe() server.executableURL = Bundle.main.url(forResource: "TabFSServer", withExtension: "")! - os_log("I AM GOOD") + server.standardOutput = serverOutput server.launch() - os_log("GREAT") + + // FIXME: should we wait for some signal that the server is ready? + // right now, background.js will just periodically retry until it can connect. + + // tell background.js to try to connect. reply() } } |