summaryrefslogtreecommitdiff
path: root/extension/background.js
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2021-02-02 23:07:24 -0800
committerOmar Rizwan <omar@omar.website>2021-02-02 23:07:24 -0800
commita465ad6a8fbb64184dcdcfa451dbb2aa9346ac2d (patch)
treebc358f2f67341695a09516ca1f1b1c7296c34224 /extension/background.js
parentf5b00deb7e5aac26049a24ad61a789a252920f8e (diff)
downloadTabFS-a465ad6a8fbb64184dcdcfa451dbb2aa9346ac2d.tar.gz
TabFS-a465ad6a8fbb64184dcdcfa451dbb2aa9346ac2d.zip
safari: checkpoint as I try to get the terrible wiring right
Diffstat (limited to 'extension/background.js')
-rw-r--r--extension/background.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/extension/background.js b/extension/background.js
index 5e487cf..e6fba2b 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -673,6 +673,10 @@ function findRoute(path) {
let port;
async function onMessage(req) {
+ // Safari / Safari extension app API forces you to adopt their
+ // {name, userInfo} structure for the request.
+ if (req.name === 'ToSafari') req = req.userInfo;
+
if (req.buf) req.buf = atob(req.buf);
console.log('req', req);
@@ -712,6 +716,16 @@ function tryConnect() {
port = chrome.runtime.connectNative('com.rsnous.tabfs');
port.onMessage.addListener(onMessage);
port.onDisconnect.addListener(p => {console.log('disconnect', p)});
+
+ // Safari is very weird -- it has this native app that we have to talk to,
+ // so we poke that app to wake it up, get it to start the TabFS process,
+ // and get it to start calling us whenever TabFS wants to do an FS call.
+ // Is there a better way to do this?
+ if (chrome.runtime.getURL('/').startsWith('safari-web-extension://')) { // Safari-only
+ chrome.runtime.sendNativeMessage('com.rsnous.tabfs', {op: 'safari_did_connect'}, function(resp) {
+ console.log(resp);
+ });
+ }
}
if (!TESTING) {