refactor: inport/export change for flatpak

This commit is contained in:
Fabio286 2023-11-26 16:42:30 +01:00
parent 984aa893d3
commit 390bf88bb8
2 changed files with 35 additions and 8 deletions

View File

@ -1,4 +1,4 @@
import { ChildProcess, fork } from 'child_process'; import { ChildProcess, ChildProcessWithoutNullStreams, fork, spawn } from 'child_process';
import * as antares from 'common/interfaces/antares'; import * as antares from 'common/interfaces/antares';
import * as workers from 'common/interfaces/workers'; import * as workers from 'common/interfaces/workers';
import { dialog, ipcMain } from 'electron'; import { dialog, ipcMain } from 'electron';
@ -8,9 +8,10 @@ import * as path from 'path';
import { validateSender } from '../libs/misc/validateSender'; import { validateSender } from '../libs/misc/validateSender';
const isDevelopment = process.env.NODE_ENV !== 'production'; const isDevelopment = process.env.NODE_ENV !== 'production';
const isFlatpak = process.platform === 'linux' && Boolean(process.env.FLATPAK_ID?.includes('fabiodistasio') || process.env.FLATPAK_ID?.includes('AntaresSQL'));
export default (connections: {[key: string]: antares.Client}) => { export default (connections: {[key: string]: antares.Client}) => {
let exporter: ChildProcess = null; let exporter: ChildProcessWithoutNullStreams = null;
let importer: ChildProcess = null; let importer: ChildProcess = null;
ipcMain.handle('create-schema', async (event, params) => { ipcMain.handle('create-schema', async (event, params) => {
@ -228,9 +229,19 @@ export default (connections: {[key: string]: antares.Client}) => {
} }
// Init exporter process // Init exporter process
exporter = fork(isDevelopment ? './dist/exporter.js' : path.resolve(__dirname, './exporter.js'), [], { if (isFlatpak) {
execArgv: isDevelopment ? ['--inspect=9224'] : undefined const exporterPath = isDevelopment ? './dist/exporter.js' : path.resolve(__dirname, './exporter.js');
});
exporter = spawn('flatpak-spawn', ['--host', 'node', exporterPath], {
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
});
}
else {
exporter = fork(isDevelopment ? './dist/exporter.js' : path.resolve(__dirname, './exporter.js'), [], {
execArgv: isDevelopment ? ['--inspect=9224'] : undefined
});
}
exporter.send({ exporter.send({
type: 'init', type: 'init',
client: { client: {
@ -311,9 +322,19 @@ export default (connections: {[key: string]: antares.Client}) => {
const dbConfig = await connections[options.uid].getDbConfig(); const dbConfig = await connections[options.uid].getDbConfig();
// Init importer process // Init importer process
importer = fork(isDevelopment ? './dist/importer.js' : path.resolve(__dirname, './importer.js'), [], { if (isFlatpak) {
execArgv: isDevelopment ? ['--inspect=9224'] : undefined const importerPath = isDevelopment ? './dist/importer.js' : path.resolve(__dirname, './importer.js');
});
importer = spawn('flatpak-spawn', ['--host', 'node', importerPath], {
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
});
}
else {
importer = fork(isDevelopment ? './dist/importer.js' : path.resolve(__dirname, './importer.js'), [], {
execArgv: isDevelopment ? ['--inspect=9224'] : undefined
});
}
importer.send({ importer.send({
type: 'init', type: 'init',
dbConfig, dbConfig,
@ -348,6 +369,11 @@ export default (connections: {[key: string]: antares.Client}) => {
break; break;
} }
}); });
importer.on('exit', code => {
importer = null;
resolve({ status: 'error', response: `Operation ended with code: ${code}` });
});
})(); })();
}); });
}); });

View File

@ -8,6 +8,7 @@ import MysqlExporter from '../libs/exporters/sql/MysqlExporter';
import PostgreSQLExporter from '../libs/exporters/sql/PostgreSQLExporter'; import PostgreSQLExporter from '../libs/exporters/sql/PostgreSQLExporter';
let exporter: antares.Exporter; let exporter: antares.Exporter;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
process.on('message', async ({ type, client, tables, options }: any) => { process.on('message', async ({ type, client, tables, options }: any) => {
if (type === 'init') { if (type === 'init') {
const connection = await ClientsFactory.getClient({ const connection = await ClientsFactory.getClient({