mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 06:36:00 +00:00
events work in electron IPC
This commit is contained in:
@@ -136,7 +136,11 @@ module.exports = {
|
||||
raw: true,
|
||||
},
|
||||
test(req, res) {
|
||||
const subprocess = fork(process.argv[1], ['--start-process', 'connectProcess', ...process.argv.slice(3)]);
|
||||
const subprocess = fork(global['API_PACKAGE'] || process.argv[1], [
|
||||
'--start-process',
|
||||
'connectProcess',
|
||||
...process.argv.slice(3),
|
||||
]);
|
||||
subprocess.on('message', resp => {
|
||||
if (handleProcessCommunication(resp, subprocess)) return;
|
||||
// @ts-ignore
|
||||
|
||||
@@ -74,7 +74,7 @@ module.exports = {
|
||||
const existing = this.opened.find(x => x.conid == conid && x.database == database);
|
||||
if (existing) return existing;
|
||||
const connection = await connections.get({ conid });
|
||||
const subprocess = fork(process.argv[1], [
|
||||
const subprocess = fork(global['API_PACKAGE'] || process.argv[1], [
|
||||
'--start-process',
|
||||
'databaseConnectionProcess',
|
||||
...process.argv.slice(3),
|
||||
|
||||
@@ -103,7 +103,7 @@ module.exports = {
|
||||
stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
|
||||
env: {
|
||||
...process.env,
|
||||
DBGATE_API: global['dbgateApiModulePath'] || process.argv[1],
|
||||
DBGATE_API: global['API_PACKAGE'] || global['dbgateApiModulePath'] || process.argv[1],
|
||||
..._.fromPairs(pluginNames.map(name => [`PLUGIN_${_.camelCase(name)}`, getPluginBackendPath(name)])),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -37,7 +37,7 @@ module.exports = {
|
||||
const existing = this.opened.find(x => x.conid == conid);
|
||||
if (existing) return existing;
|
||||
const connection = await connections.get({ conid });
|
||||
const subprocess = fork(process.argv[1], [
|
||||
const subprocess = fork(global['API_PACKAGE'] || process.argv[1], [
|
||||
'--start-process',
|
||||
'serverConnectionProcess',
|
||||
...process.argv.slice(3),
|
||||
|
||||
@@ -65,7 +65,11 @@ module.exports = {
|
||||
async create({ conid, database }) {
|
||||
const sesid = uuidv1();
|
||||
const connection = await connections.get({ conid });
|
||||
const subprocess = fork(process.argv[1], ['--start-process', 'sessionProcess', ...process.argv.slice(3)]);
|
||||
const subprocess = fork(global['API_PACKAGE'] || process.argv[1], [
|
||||
'--start-process',
|
||||
'sessionProcess',
|
||||
...process.argv.slice(3),
|
||||
]);
|
||||
const newOpened = {
|
||||
conid,
|
||||
database,
|
||||
|
||||
@@ -90,7 +90,7 @@ function start() {
|
||||
|
||||
// Tell the client to retry every 10 seconds if connectivity is lost
|
||||
res.write('retry: 10000\n\n');
|
||||
socket.set(res);
|
||||
socket.setSseResponse(res);
|
||||
});
|
||||
|
||||
app.use(bodyParser.json({ limit: '50mb' }));
|
||||
@@ -162,4 +162,8 @@ function useAllControllers(app, electron) {
|
||||
useController(app, electron, '/query-history', queryHistory);
|
||||
}
|
||||
|
||||
module.exports = { start, useAllControllers };
|
||||
function initializeElectronSender(electronSender) {
|
||||
socket.setElectronSender(electronSender);
|
||||
}
|
||||
|
||||
module.exports = { start, useAllControllers, initializeElectronSender };
|
||||
|
||||
@@ -29,7 +29,11 @@ class DatastoreProxy {
|
||||
|
||||
async ensureSubprocess() {
|
||||
if (!this.subprocess) {
|
||||
this.subprocess = fork(process.argv[1], ['--start-process', 'jslDatastoreProcess', ...process.argv.slice(3)]);
|
||||
this.subprocess = fork(global['API_PACKAGE'] || process.argv[1], [
|
||||
'--start-process',
|
||||
'jslDatastoreProcess',
|
||||
...process.argv.slice(3),
|
||||
]);
|
||||
|
||||
this.subprocess.on('message', message => {
|
||||
// @ts-ignore
|
||||
|
||||
@@ -1,35 +1,29 @@
|
||||
let res = null;
|
||||
let sseResponse = null;
|
||||
let electronSender = null;
|
||||
let init = '';
|
||||
|
||||
module.exports = {
|
||||
set(value) {
|
||||
res = value;
|
||||
setSseResponse(value) {
|
||||
sseResponse = value;
|
||||
},
|
||||
setElectronSender(value) {
|
||||
electronSender = value;
|
||||
},
|
||||
// get() {
|
||||
// return socket;
|
||||
// },
|
||||
emit(message, data) {
|
||||
if (res) {
|
||||
if (electronSender) {
|
||||
electronSender.send(message, data == null ? null : data);
|
||||
} else if (sseResponse) {
|
||||
if (init) {
|
||||
res.write(init);
|
||||
sseResponse.write(init);
|
||||
init = '';
|
||||
}
|
||||
res.write(`event: ${message}\ndata: ${JSON.stringify(data == null ? null : data)}\n\n`);
|
||||
sseResponse.write(`event: ${message}\ndata: ${JSON.stringify(data == null ? null : data)}\n\n`);
|
||||
} else {
|
||||
init += res;
|
||||
init += sseResponse;
|
||||
}
|
||||
|
||||
// console.log('EMIT:', message, data);
|
||||
// socket.emit(message, data);
|
||||
},
|
||||
emitChanged(key) {
|
||||
this.emit('clean-cache', key);
|
||||
this.emit(key);
|
||||
// console.log('EMIT_CHANGED:', key);
|
||||
// socket.emit('clean-cache', key);
|
||||
// socket.emit(key);
|
||||
|
||||
// socket.send(key, 'clean-cache');
|
||||
// socket.send(null, key);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -28,7 +28,7 @@ module.exports = function useController(app, electron, route, controller) {
|
||||
if (electron) {
|
||||
if (meta === true) {
|
||||
const handler = `${route.substring(1)}-${_.kebabCase(key)}`;
|
||||
console.log('REGISTERING HANDLER', handler);
|
||||
// console.log('REGISTERING HANDLER', handler);
|
||||
electron.ipcMain.handle(handler, async (event, args) => {
|
||||
const data = await controller[key](args);
|
||||
return data;
|
||||
|
||||
Reference in New Issue
Block a user