diff options
Diffstat (limited to 'extension/background.js')
-rw-r--r-- | extension/background.js | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/extension/background.js b/extension/background.js index f38f29e..62ec7d0 100644 --- a/extension/background.js +++ b/extension/background.js @@ -713,24 +713,29 @@ async function onMessage(req) { }; function tryConnect() { - console.log('start tryConnect'); - port = chrome.runtime.connectNative('com.rsnous.tabfs'); - console.log('start tryConnect - did connectNative'); - port.onMessage.addListener(onMessage); - port.onDisconnect.addListener(p => {console.log('disconnect', p)}); - - console.log('tryConnect - about to sNM'); // 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. + // so we poke that app to wake it up, get it to start the TabFS process + // and boot a WebSocket, then connect to it. // 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('didConnect resp'); + chrome.runtime.sendNativeMessage('com.rsnous.tabfs', {op: 'safari_did_connect'}, resp => { console.log(resp); + const socket = new WebSocket('ws://localhost:9991'); + + socket.addEventListener('message', event => { + onMessage(JSON.parse(event.data)); + }); + + port = { postMessage(message) { + socket.send(JSON.stringify(message)); + } }; }); + return; } - console.log('tryConnect - did sNM'); + + port = chrome.runtime.connectNative('com.rsnous.tabfs'); + port.onMessage.addListener(onMessage); + port.onDisconnect.addListener(p => {console.log('disconnect', p)}); } if (!TESTING) { |