mirror of
https://github.com/osnr/TabFS.git
synced 2024-05-17 21:16:35 +02:00
native messaging test file.
This commit is contained in:
parent
c78377d464
commit
69c167a134
|
@ -289,10 +289,14 @@ async function releasedir(path) {
|
||||||
if (route.releasedir) return route.releasedir(path);
|
if (route.releasedir) return route.releasedir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function log(...ss) {
|
||||||
|
console.log(...ss);
|
||||||
|
}
|
||||||
|
|
||||||
let port;
|
let port;
|
||||||
/* let ws;*/
|
/* let ws;*/
|
||||||
async function onMessage(req) {
|
async function onMessage(req) {
|
||||||
console.log('req', req);
|
log('req', req);
|
||||||
|
|
||||||
let response = { op: req.op, error: unix.EIO };
|
let response = { op: req.op, error: unix.EIO };
|
||||||
/* console.time(req.op + ':' + req.path);*/
|
/* console.time(req.op + ':' + req.path);*/
|
||||||
|
@ -366,14 +370,16 @@ async function onMessage(req) {
|
||||||
}
|
}
|
||||||
/* console.timeEnd(req.op + ':' + req.path);*/
|
/* console.timeEnd(req.op + ':' + req.path);*/
|
||||||
|
|
||||||
console.log('resp', response);
|
log('resp', response);
|
||||||
ws.send(JSON.stringify(response));
|
/* ws.send(JSON.stringify(response));*/
|
||||||
};
|
};
|
||||||
|
|
||||||
function tryConnect() {
|
function tryConnect() {
|
||||||
port = chrome.runtime.connectNative('com.rsnous.TabFS');
|
port = chrome.runtime.connectNative('com.rsnous.TabFS');
|
||||||
updateToolbarIcon();
|
/* console.log('hello', port);*/
|
||||||
|
/* updateToolbarIcon();*/
|
||||||
port.onMessage.addListener(onMessage);
|
port.onMessage.addListener(onMessage);
|
||||||
|
port.onDisconnect.addListener(p => {log(p)});
|
||||||
|
|
||||||
/* ws = new WebSocket("ws://localhost:8888");
|
/* ws = new WebSocket("ws://localhost:8888");
|
||||||
* updateToolbarIcon();
|
* updateToolbarIcon();
|
||||||
|
|
30
fs/test-native.c
Normal file
30
fs/test-native.c
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
Loading…
Reference in a new issue