summaryrefslogtreecommitdiff
path: root/extension/safari/TabFS/TabFSService
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2021-02-14 16:45:07 -0800
committerGitHub <noreply@github.com>2021-02-14 16:45:07 -0800
commit5350b73c2a68dae4f822d06e70897ef57031346d (patch)
tree39d35441314690e45235af7e2ecee91c92a19264 /extension/safari/TabFS/TabFSService
parentd7f462e96415fcbb265cdaac854ddfc47b3482ca (diff)
parent0f2ab4b4de7e828757091e323be1caab0a70b770 (diff)
downloadTabFS-5350b73c2a68dae4f822d06e70897ef57031346d.tar.gz
TabFS-5350b73c2a68dae4f822d06e70897ef57031346d.zip
Merge pull request #64 from osnr/safari
Safari support
Diffstat (limited to 'extension/safari/TabFS/TabFSService')
-rw-r--r--extension/safari/TabFS/TabFSService/Info.plist29
-rw-r--r--extension/safari/TabFS/TabFSService/TabFSService.swift58
-rw-r--r--extension/safari/TabFS/TabFSService/TabFSServiceProtocols.swift12
-rw-r--r--extension/safari/TabFS/TabFSService/main.swift15
4 files changed, 114 insertions, 0 deletions
diff --git a/extension/safari/TabFS/TabFSService/Info.plist b/extension/safari/TabFS/TabFSService/Info.plist
new file mode 100644
index 0000000..8b1c3aa
--- /dev/null
+++ b/extension/safari/TabFS/TabFSService/Info.plist
@@ -0,0 +1,29 @@
+<?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>CFBundleDevelopmentRegion</key>
+ <string>$(DEVELOPMENT_LANGUAGE)</string>
+ <key>CFBundleDisplayName</key>
+ <string>TabFSService</string>
+ <key>CFBundleExecutable</key>
+ <string>$(EXECUTABLE_NAME)</string>
+ <key>CFBundleIdentifier</key>
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>$(PRODUCT_NAME)</string>
+ <key>CFBundlePackageType</key>
+ <string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>XPCService</key>
+ <dict>
+ <key>ServiceType</key>
+ <string>Application</string>
+ </dict>
+</dict>
+</plist>
diff --git a/extension/safari/TabFS/TabFSService/TabFSService.swift b/extension/safari/TabFS/TabFSService/TabFSService.swift
new file mode 100644
index 0000000..5bf55ee
--- /dev/null
+++ b/extension/safari/TabFS/TabFSService/TabFSService.swift
@@ -0,0 +1,58 @@
+//
+// TabFSService.swift
+// TabFSService
+//
+// Created by Omar Rizwan on 2/7/21.
+//
+
+import Foundation
+import Network
+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.
+
+ // 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()
+ let serverOutput = Pipe()
+ server.executableURL = Bundle.main.url(forResource: "TabFSServer", withExtension: "")!
+ server.standardOutput = serverOutput
+ server.launch()
+
+ // 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()
+ }
+}
+
+class TabFSServiceDelegate: NSObject, NSXPCListenerDelegate {
+ func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool {
+ let exportedObject = TabFSService()
+ newConnection.exportedInterface = NSXPCInterface(with: TabFSServiceProtocol.self)
+ newConnection.exportedObject = exportedObject
+
+ newConnection.resume()
+ return true
+ }
+}
diff --git a/extension/safari/TabFS/TabFSService/TabFSServiceProtocols.swift b/extension/safari/TabFS/TabFSService/TabFSServiceProtocols.swift
new file mode 100644
index 0000000..4dd6e77
--- /dev/null
+++ b/extension/safari/TabFS/TabFSService/TabFSServiceProtocols.swift
@@ -0,0 +1,12 @@
+//
+// TabFSServiceProtocols.swift
+// app-sandbox-xpc-test
+//
+// Created by Omar Rizwan on 2/7/21.
+//
+
+import Foundation
+
+@objc public protocol TabFSServiceProtocol {
+ func start(withReply reply: @escaping () -> Void)
+}
diff --git a/extension/safari/TabFS/TabFSService/main.swift b/extension/safari/TabFS/TabFSService/main.swift
new file mode 100644
index 0000000..f0a4486
--- /dev/null
+++ b/extension/safari/TabFS/TabFSService/main.swift
@@ -0,0 +1,15 @@
+//
+// main.m
+// TabFSService
+//
+// Created by Omar Rizwan on 2/7/21.
+//
+
+import Foundation
+
+ProcessInfo.processInfo.disableAutomaticTermination("ok")
+
+let delegate = TabFSServiceDelegate()
+let listener = NSXPCListener.service()
+listener.delegate = delegate
+listener.resume()