mirror of
https://github.com/EEVengers/ThunderScope.git
synced 2025-04-08 06:25:30 +00:00
Run C++ inside Electron
This commit is contained in:
parent
aa9280ed2e
commit
96b46c3ac4
@ -2,17 +2,39 @@
|
||||
// It has the same sandbox as a Chrome extension.
|
||||
|
||||
import * as fs from 'fs';
|
||||
import { exec } from 'child_process';
|
||||
import { spawn } from 'child_process';
|
||||
import { contextBridge } from 'electron';
|
||||
|
||||
const cwd = process.cwd();
|
||||
const cpp = spawn(cwd + "\\build_cpp\\Release\\scope.exe", ["-c"]);
|
||||
|
||||
var did_open = false;
|
||||
const SOCKET_PREFIX = (process.platform == "win32") ? "\\\\.\\pipe\\" : "/tmp/";
|
||||
const SOCKETFILE_TX = SOCKET_PREFIX + "testPipeRX";
|
||||
const SOCKETFILE_RX = SOCKET_PREFIX + "testPipeTX";
|
||||
|
||||
var TX_FD = -1;
|
||||
var RX_FD = -1;
|
||||
fs.open(SOCKETFILE_TX, "w", (err, fd) => {TX_FD = fd;});
|
||||
fs.open(SOCKETFILE_RX, "r", (err, fd) => {RX_FD = fd;});
|
||||
|
||||
cpp.stdout.on('data', (data) => {
|
||||
console.log(`cpp stdout: ${data}`);
|
||||
if(TX_FD != -1 && RX_FD != 1) {
|
||||
did_open = true;
|
||||
}
|
||||
if(!did_open) {
|
||||
fs.open(SOCKETFILE_TX, "w", (err, fd) => {
|
||||
if(err) {
|
||||
console.error(err);
|
||||
}
|
||||
TX_FD = fd;
|
||||
});
|
||||
fs.open(SOCKETFILE_RX, "r", (err, fd) => {
|
||||
if(err) {
|
||||
console.error(err);
|
||||
}
|
||||
RX_FD = fd;
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
//Welcome to the future: https://www.electronjs.org/docs/tutorial/context-isolation
|
||||
contextBridge.exposeInMainWorld("thunderBridge", {
|
||||
|
Loading…
Reference in New Issue
Block a user