diff --git a/src/main/ipc-handlers/schema.ts b/src/main/ipc-handlers/schema.ts index 8323b4e4..2d6b1e52 100644 --- a/src/main/ipc-handlers/schema.ts +++ b/src/main/ipc-handlers/schema.ts @@ -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 workers from 'common/interfaces/workers'; import { dialog, ipcMain } from 'electron'; @@ -8,9 +8,10 @@ import * as path from 'path'; import { validateSender } from '../libs/misc/validateSender'; 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}) => { - let exporter: ChildProcess = null; + let exporter: ChildProcessWithoutNullStreams = null; let importer: ChildProcess = null; ipcMain.handle('create-schema', async (event, params) => { @@ -228,9 +229,19 @@ export default (connections: {[key: string]: antares.Client}) => { } // Init exporter process - exporter = fork(isDevelopment ? './dist/exporter.js' : path.resolve(__dirname, './exporter.js'), [], { - execArgv: isDevelopment ? ['--inspect=9224'] : undefined - }); + if (isFlatpak) { + 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({ type: 'init', client: { @@ -311,9 +322,19 @@ export default (connections: {[key: string]: antares.Client}) => { const dbConfig = await connections[options.uid].getDbConfig(); // Init importer process - importer = fork(isDevelopment ? './dist/importer.js' : path.resolve(__dirname, './importer.js'), [], { - execArgv: isDevelopment ? ['--inspect=9224'] : undefined - }); + if (isFlatpak) { + 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({ type: 'init', dbConfig, @@ -348,6 +369,11 @@ export default (connections: {[key: string]: antares.Client}) => { break; } }); + + importer.on('exit', code => { + importer = null; + resolve({ status: 'error', response: `Operation ended with code: ${code}` }); + }); })(); }); }); diff --git a/src/main/workers/exporter.ts b/src/main/workers/exporter.ts index 93de4c92..70e8088e 100644 --- a/src/main/workers/exporter.ts +++ b/src/main/workers/exporter.ts @@ -8,6 +8,7 @@ import MysqlExporter from '../libs/exporters/sql/MysqlExporter'; import PostgreSQLExporter from '../libs/exporters/sql/PostgreSQLExporter'; let exporter: antares.Exporter; +// eslint-disable-next-line @typescript-eslint/no-explicit-any process.on('message', async ({ type, client, tables, options }: any) => { if (type === 'init') { const connection = await ClientsFactory.getClient({