diff --git a/extension/background.js b/extension/background.js index a53dae0..c7815e6 100644 --- a/extension/background.js +++ b/extension/background.js @@ -289,10 +289,14 @@ async function releasedir(path) { if (route.releasedir) return route.releasedir(path); } +function log(...ss) { + console.log(...ss); +} + let port; /* let ws;*/ async function onMessage(req) { - console.log('req', req); + log('req', req); let response = { op: req.op, error: unix.EIO }; /* console.time(req.op + ':' + req.path);*/ @@ -366,14 +370,16 @@ async function onMessage(req) { } /* console.timeEnd(req.op + ':' + req.path);*/ - console.log('resp', response); - ws.send(JSON.stringify(response)); + log('resp', response); + /* ws.send(JSON.stringify(response));*/ }; function tryConnect() { port = chrome.runtime.connectNative('com.rsnous.TabFS'); - updateToolbarIcon(); + /* console.log('hello', port);*/ + /* updateToolbarIcon();*/ port.onMessage.addListener(onMessage); + port.onDisconnect.addListener(p => {log(p)}); /* ws = new WebSocket("ws://localhost:8888"); * updateToolbarIcon(); diff --git a/fs/test-native.c b/fs/test-native.c new file mode 100644 index 0000000..c53df29 --- /dev/null +++ b/fs/test-native.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +int main() { + FILE *log = fopen("log.txt", "w"); + fprintf(log, "hello\n"); fflush(log); + + for (;;) { + char *outMsg = "{\"text\":\"This is a response message\"}"; + unsigned int outLen = strlen(outMsg); + char *bOutLen = (char *)&outLen; + write(1, bOutLen, 4); // 1 is stdout + write(1, outMsg, outLen); + fflush(stdout); + fprintf(log, "wrote msg\n"); fflush(log); + + char bInLen[4]; + read(0, bInLen, 4); // 0 is stdin + unsigned int inLen = *(unsigned int *)bInLen; + char *inMsg = (char *)malloc(inLen); + read(0, inMsg, inLen); + inMsg[inLen] = '\0'; + fprintf(log, "msg: [%s]\n", inMsg); fflush(log); + free(inMsg); + + } + return 0; +}