diff --git a/.gitmodules b/.gitmodules index 8dd9825..775a802 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,3 @@ [submodule "fs/cJSON"] path = fs/cJSON url = https://github.com/DaveGamble/cJSON.git -[submodule "fs/mmx"] - path = fs/mmx - url = https://github.com/vurtun/mmx.git -[submodule "fs/base64"] - path = fs/base64 - url = https://github.com/zhicheng/base64.git diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f15f5dc --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +EXE_PATH=$(shell pwd)/fs/tabfs +define NATIVE_MESSAGING_APP_MANIFEST +{ + "name": "com.rsnous.TabFS", + "description": "TabFS", + "path": "$(EXE_PATH)", + "type": "stdio", + "allowed_extensions": ["tabfs@rsnous.com"] +} +endef +export NATIVE_MESSAGING_APP_MANIFEST + +# "allowed_origins": [ +# "chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/" +# ] + +# ~/Library/Application Support/Google/Chrome/NativeMessagingHosts +MANIFEST_LOCATION="$$HOME/Library/Application Support/Mozilla/NativeMessagingHosts" +APP_NAME="com.rsnous.TabFS" +install: +# install native messaging json + mkdir -p $(MANIFEST_LOCATION) + echo "$$NATIVE_MESSAGING_APP_MANIFEST" > $(MANIFEST_LOCATION)/$(APP_NAME).json 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 { diff --git a/extension/manifest.json b/extension/manifest.json index ac424f1..7900406 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -5,12 +5,18 @@ "description": "Connects to TabFS filesystem", "version": "1.0", - "permissions": ["tabs", "debugger"], + "permissions": ["tabs", "debugger", "nativeMessaging"], "browser_action": {}, "background": { "scripts": ["background.js"], "persistent": true + }, + + "browser_specific_settings": { + "gecko": { + "id": "tabfs@rsnous.com" + } } } diff --git a/fs/mmx b/fs/mmx deleted file mode 160000 index dc54ba5..0000000 --- a/fs/mmx +++ /dev/null @@ -1 +0,0 @@ -Subproject commit dc54ba5c8cf6518d9876eb8586c83603b683a118 diff --git a/fs/tabfs.c b/fs/tabfs.c index b992548..2b8bc99 100644 --- a/fs/tabfs.c +++ b/fs/tabfs.c @@ -12,7 +12,6 @@ #include "base64/base64.c" #include "common.h" -#include "ws.h" static cJSON *send_request_then_await_response(cJSON *req) { // Will be freed at receiver (ws.c, receive_tabfs_request_then_send_to_browser).