From 74b1b0f789ea4e310a138c4b6d476a78d49cf557 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Fri, 16 Oct 2020 21:56:49 -0700 Subject: Starting to move to native messaging. Why? The WebSocket stuff is broken right now, and I want to get rid of the dep... --- extension/background.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'extension/background.js') diff --git a/extension/background.js b/extension/background.js index b204876..a53dae0 100644 --- a/extension/background.js +++ b/extension/background.js @@ -289,9 +289,9 @@ async function releasedir(path) { if (route.releasedir) return route.releasedir(path); } -let ws; -async function onmessage(event) { - const req = JSON.parse(event.data); +let port; +/* let ws;*/ +async function onMessage(req) { console.log('req', req); let response = { op: req.op, error: unix.EIO }; @@ -371,14 +371,18 @@ async function onmessage(event) { }; function tryConnect() { - ws = new WebSocket("ws://localhost:8888"); + port = chrome.runtime.connectNative('com.rsnous.TabFS'); updateToolbarIcon(); - ws.onopen = ws.onclose = updateToolbarIcon; - ws.onmessage = onmessage; + port.onMessage.addListener(onMessage); + + /* ws = new WebSocket("ws://localhost:8888"); + * updateToolbarIcon(); + * ws.onopen = ws.onclose = updateToolbarIcon; + * ws.onmessage = onmessage;*/ } function updateToolbarIcon() { - if (ws && ws.readyState == 1) { // OPEN + if (port && port.onMessage) { // OPEN chrome.browserAction.setBadgeBackgroundColor({color: 'blue'}); chrome.browserAction.setBadgeText({text: 'f'}); } else { -- cgit v1.2.3