mirror of
https://github.com/Fabio286/antares.git
synced 2025-02-13 02:00:36 +01:00
refactor: inport/export change for flatpak
This commit is contained in:
parent
984aa893d3
commit
390bf88bb8
@ -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}` });
|
||||
});
|
||||
})();
|
||||
});
|
||||
});
|
||||
|
@ -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({
|
||||
|
Loading…
x
Reference in New Issue
Block a user