From cbbca08f2d7f3fb6d86c3f166ef8f2ac89d26543 Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Mon, 11 Nov 2024 23:00:53 +0100 Subject: [PATCH 01/16] remove commented env merge --- resources/js/electron-plugin/src/server/childProcess.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/resources/js/electron-plugin/src/server/childProcess.ts b/resources/js/electron-plugin/src/server/childProcess.ts index 01428ea2..e6595c28 100644 --- a/resources/js/electron-plugin/src/server/childProcess.ts +++ b/resources/js/electron-plugin/src/server/childProcess.ts @@ -2,14 +2,7 @@ const { spawn } = require('child_process') const proc = spawn( process.argv[2], - process.argv.slice(3), - { - // cwd: options.cwd, - // env: { - // ...process.env, - // ...options.env - // }, - } + process.argv.slice(3) ); process.parentPort.on('message', (message) => { From db2c9f724d0c8d1ec216204466f50998c7781ff4 Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Tue, 12 Nov 2024 12:27:32 +0100 Subject: [PATCH 02/16] fix typo --- resources/js/electron-plugin/src/server/api/childProcess.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/js/electron-plugin/src/server/api/childProcess.ts b/resources/js/electron-plugin/src/server/api/childProcess.ts index 0edf064a..b1518d7c 100644 --- a/resources/js/electron-plugin/src/server/api/childProcess.ts +++ b/resources/js/electron-plugin/src/server/api/childProcess.ts @@ -81,7 +81,7 @@ function startProcess(settings) { delete state.processes[alias]; if (settings.persistent) { - console.log('Process [' + alias + '] wathchdog restarting...'); + console.log('Process [' + alias + '] watchdog restarting...'); startProcess(settings); } }); From 5f07510ad80f7440f2a8f65d8804aa25820bbcf9 Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Tue, 12 Nov 2024 21:47:05 +0100 Subject: [PATCH 03/16] forward native env variables to child process --- .../electron-plugin/src/server/api/childProcess.ts | 12 ++++++++++-- resources/js/electron-plugin/src/server/php.ts | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/resources/js/electron-plugin/src/server/api/childProcess.ts b/resources/js/electron-plugin/src/server/api/childProcess.ts index b1518d7c..7897d851 100644 --- a/resources/js/electron-plugin/src/server/api/childProcess.ts +++ b/resources/js/electron-plugin/src/server/api/childProcess.ts @@ -3,6 +3,8 @@ import { utilityProcess } from 'electron'; import state from '../state'; import { notifyLaravel } from "../utils"; import { join } from 'path'; +import { getDefaultEnvironmentVariables } from "../php"; + const router = express.Router(); const killSync = require('kill-sync'); @@ -14,16 +16,22 @@ function startProcess(settings) { return state.processes[alias]; } + const defaultEnv = getDefaultEnvironmentVariables( + state.randomSecret, + state.electronApiPort + ); + const proc = utilityProcess.fork( join(__dirname, '../../electron-plugin/dist/server/childProcess.js'), cmd, { cwd, - serviceName: alias, stdio: 'pipe', + serviceName: alias, env: { ...process.env, - ...env, + ...defaultEnv, + ...env } } ); diff --git a/resources/js/electron-plugin/src/server/php.ts b/resources/js/electron-plugin/src/server/php.ts index 92208e3a..701a27c7 100644 --- a/resources/js/electron-plugin/src/server/php.ts +++ b/resources/js/electron-plugin/src/server/php.ts @@ -165,7 +165,7 @@ function getDefaultEnvironmentVariables(secret, apiPort) { NATIVEPHP_STORAGE_PATH: storagePath, NATIVEPHP_DATABASE_PATH: databaseFile, NATIVEPHP_API_URL: `http://localhost:${apiPort}/api/`, - NATIVEPHP_RUNNING: true, + NATIVEPHP_RUNNING: 'true', NATIVEPHP_SECRET: secret, NATIVEPHP_USER_HOME_PATH: getPath('home'), NATIVEPHP_APP_DATA_PATH: getPath('appData'), @@ -267,4 +267,4 @@ function serveApp(secret, apiPort, phpIniSettings): Promise { }) } -export {startQueueWorker, startScheduler, serveApp, getAppPath, retrieveNativePHPConfig, retrievePhpIniSettings} +export {startQueueWorker, startScheduler, serveApp, getAppPath, retrieveNativePHPConfig, retrievePhpIniSettings, getDefaultEnvironmentVariables} From c37c96e42f77d7fb396ecd832b4e67ebe7dee569 Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Tue, 12 Nov 2024 20:48:31 +0000 Subject: [PATCH 04/16] Build plugin --- .../js/electron-plugin/dist/server/api/childProcess.js | 8 +++++--- resources/js/electron-plugin/dist/server/php.js | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/resources/js/electron-plugin/dist/server/api/childProcess.js b/resources/js/electron-plugin/dist/server/api/childProcess.js index 9f2228c5..9d21aae0 100644 --- a/resources/js/electron-plugin/dist/server/api/childProcess.js +++ b/resources/js/electron-plugin/dist/server/api/childProcess.js @@ -12,6 +12,7 @@ import { utilityProcess } from 'electron'; import state from '../state'; import { notifyLaravel } from "../utils"; import { join } from 'path'; +import { getDefaultEnvironmentVariables } from "../php"; const router = express.Router(); const killSync = require('kill-sync'); function startProcess(settings) { @@ -19,11 +20,12 @@ function startProcess(settings) { if (getProcess(alias) !== undefined) { return state.processes[alias]; } + const defaultEnv = getDefaultEnvironmentVariables(state.randomSecret, state.electronApiPort); const proc = utilityProcess.fork(join(__dirname, '../../electron-plugin/dist/server/childProcess.js'), cmd, { cwd, - serviceName: alias, stdio: 'pipe', - env: Object.assign(Object.assign({}, process.env), env) + serviceName: alias, + env: Object.assign(Object.assign(Object.assign({}, process.env), defaultEnv), env) }); proc.stdout.on('data', (data) => { notifyLaravel('events', { @@ -68,7 +70,7 @@ function startProcess(settings) { const settings = Object.assign({}, getSettings(alias)); delete state.processes[alias]; if (settings.persistent) { - console.log('Process [' + alias + '] wathchdog restarting...'); + console.log('Process [' + alias + '] watchdog restarting...'); startProcess(settings); } }); diff --git a/resources/js/electron-plugin/dist/server/php.js b/resources/js/electron-plugin/dist/server/php.js index 9bb14972..bc0df624 100644 --- a/resources/js/electron-plugin/dist/server/php.js +++ b/resources/js/electron-plugin/dist/server/php.js @@ -139,7 +139,7 @@ function getDefaultEnvironmentVariables(secret, apiPort) { NATIVEPHP_STORAGE_PATH: storagePath, NATIVEPHP_DATABASE_PATH: databaseFile, NATIVEPHP_API_URL: `http://localhost:${apiPort}/api/`, - NATIVEPHP_RUNNING: true, + NATIVEPHP_RUNNING: 'true', NATIVEPHP_SECRET: secret, NATIVEPHP_USER_HOME_PATH: getPath('home'), NATIVEPHP_APP_DATA_PATH: getPath('appData'), @@ -220,4 +220,4 @@ function serveApp(secret, apiPort, phpIniSettings) { }); })); } -export { startQueueWorker, startScheduler, serveApp, getAppPath, retrieveNativePHPConfig, retrievePhpIniSettings }; +export { startQueueWorker, startScheduler, serveApp, getAppPath, retrieveNativePHPConfig, retrievePhpIniSettings, getDefaultEnvironmentVariables }; From 339c9fe96faba03c685f1a1f8919c46043efd564 Mon Sep 17 00:00:00 2001 From: Willem Leuverink Date: Wed, 13 Nov 2024 09:14:41 +0100 Subject: [PATCH 05/16] Update resources/js/electron-plugin/src/server/api/childProcess.ts Co-authored-by: Simon Hamp --- resources/js/electron-plugin/src/server/api/childProcess.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/js/electron-plugin/src/server/api/childProcess.ts b/resources/js/electron-plugin/src/server/api/childProcess.ts index 7897d851..7937ac3d 100644 --- a/resources/js/electron-plugin/src/server/api/childProcess.ts +++ b/resources/js/electron-plugin/src/server/api/childProcess.ts @@ -30,8 +30,8 @@ function startProcess(settings) { serviceName: alias, env: { ...process.env, + ...env, ...defaultEnv, - ...env } } ); From 9d7d993fdfddff25ea5d9e4558ac89ef52b6e543 Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Wed, 13 Nov 2024 08:15:24 +0000 Subject: [PATCH 06/16] Build plugin --- resources/js/electron-plugin/dist/server/api/childProcess.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/js/electron-plugin/dist/server/api/childProcess.js b/resources/js/electron-plugin/dist/server/api/childProcess.js index 9d21aae0..ee19e68e 100644 --- a/resources/js/electron-plugin/dist/server/api/childProcess.js +++ b/resources/js/electron-plugin/dist/server/api/childProcess.js @@ -25,7 +25,7 @@ function startProcess(settings) { cwd, stdio: 'pipe', serviceName: alias, - env: Object.assign(Object.assign(Object.assign({}, process.env), defaultEnv), env) + env: Object.assign(Object.assign(Object.assign({}, process.env), env), defaultEnv) }); proc.stdout.on('data', (data) => { notifyLaravel('events', { From ce652a8a2131795a4f6539c954368ce75572f9f1 Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Fri, 15 Nov 2024 16:57:49 +0100 Subject: [PATCH 07/16] add php endpoint with native env variables --- .../src/server/api/childProcess.ts | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/resources/js/electron-plugin/src/server/api/childProcess.ts b/resources/js/electron-plugin/src/server/api/childProcess.ts index 7937ac3d..df6fdbea 100644 --- a/resources/js/electron-plugin/src/server/api/childProcess.ts +++ b/resources/js/electron-plugin/src/server/api/childProcess.ts @@ -16,11 +16,6 @@ function startProcess(settings) { return state.processes[alias]; } - const defaultEnv = getDefaultEnvironmentVariables( - state.randomSecret, - state.electronApiPort - ); - const proc = utilityProcess.fork( join(__dirname, '../../electron-plugin/dist/server/childProcess.js'), cmd, @@ -31,7 +26,6 @@ function startProcess(settings) { env: { ...process.env, ...env, - ...defaultEnv, } } ); @@ -137,6 +131,27 @@ router.post('/start', (req, res) => { res.json(proc); }); +router.post('/start-php', (req, res) => { + + const defaultEnv = getDefaultEnvironmentVariables( + state.randomSecret, + state.electronApiPort + ); + + let settings = { + ...req.body, + cmd: [state.php].push(req.body.cmd), + env: { + ...req.body.env, + ...defaultEnv + } + } + + const proc = startProcess(settings); + + res.json(proc); +}); + router.post('/stop', (req, res) => { const {alias} = req.body; From 2ee09b8270e3dc169ef085c40d729d8b3645f6d2 Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Fri, 15 Nov 2024 16:58:14 +0100 Subject: [PATCH 08/16] extract defaultPhpIniSettings function --- resources/js/electron-plugin/src/server/php.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/resources/js/electron-plugin/src/server/php.ts b/resources/js/electron-plugin/src/server/php.ts index 8c4fafc1..8a172956 100644 --- a/resources/js/electron-plugin/src/server/php.ts +++ b/resources/js/electron-plugin/src/server/php.ts @@ -53,13 +53,8 @@ async function retrieveNativePHPConfig() { } function callPhp(args, options, phpIniSettings = {}) { - let defaultIniSettings = { - 'memory_limit': '512M', - 'curl.cainfo': state.caCert, - 'openssl.cafile': state.caCert - } - let iniSettings = Object.assign(defaultIniSettings, phpIniSettings); + let iniSettings = Object.assign(getDefaultPhpIniSettings(), phpIniSettings); Object.keys(iniSettings).forEach(key => { args.unshift('-d', `${key}=${iniSettings[key]}`); @@ -180,6 +175,14 @@ function getDefaultEnvironmentVariables(secret, apiPort) { }; } +function getDefaultPhpIniSettings() { + return { + 'memory_limit': '512M', + 'curl.cainfo': state.caCert, + 'openssl.cafile': state.caCert + } +} + function serveApp(secret, apiPort, phpIniSettings): Promise { return new Promise(async (resolve, reject) => { const appPath = getAppPath(); @@ -267,4 +270,4 @@ function serveApp(secret, apiPort, phpIniSettings): Promise { }) } -export {startQueueWorker, startScheduler, serveApp, getAppPath, retrieveNativePHPConfig, retrievePhpIniSettings, getDefaultEnvironmentVariables} +export {startQueueWorker, startScheduler, serveApp, getAppPath, retrieveNativePHPConfig, retrievePhpIniSettings, getDefaultEnvironmentVariables, getDefaultPhpIniSettings} From f7478bc5b70254f9b7382821d4d90f5a0ebd23a1 Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Fri, 15 Nov 2024 17:04:43 +0100 Subject: [PATCH 09/16] mix in php ini settings --- .../src/server/api/childProcess.ts | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/resources/js/electron-plugin/src/server/api/childProcess.ts b/resources/js/electron-plugin/src/server/api/childProcess.ts index df6fdbea..45ec77ef 100644 --- a/resources/js/electron-plugin/src/server/api/childProcess.ts +++ b/resources/js/electron-plugin/src/server/api/childProcess.ts @@ -3,7 +3,7 @@ import { utilityProcess } from 'electron'; import state from '../state'; import { notifyLaravel } from "../utils"; import { join } from 'path'; -import { getDefaultEnvironmentVariables } from "../php"; +import { getDefaultEnvironmentVariables, getDefaultPhpIniSettings } from "../php"; const router = express.Router(); @@ -138,14 +138,20 @@ router.post('/start-php', (req, res) => { state.electronApiPort ); + // Construct command args from ini settings + const iniSettings = getDefaultPhpIniSettings(); + const iniArgs = Object.keys(iniSettings).map(key => { + return ['-d', `${key}=${iniSettings[key]}`]; + }).flat(); + + let settings = { ...req.body, - cmd: [state.php].push(req.body.cmd), - env: { - ...req.body.env, - ...defaultEnv - } - } + // Prepend cmd with php executable path & ini settings + cmd: [ state.php, ...iniArgs, ...req.body.cmd ], + // Mix in the internal NativePHP env + env: { ...req.body.env, ...defaultEnv } + }; const proc = startProcess(settings); From 183882c7db82b55d0336905d038f97fd706d5281 Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Fri, 15 Nov 2024 17:13:03 +0100 Subject: [PATCH 10/16] boyscouting - cleanup startQueueWorker --- resources/js/electron-plugin/src/server/php.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/resources/js/electron-plugin/src/server/php.ts b/resources/js/electron-plugin/src/server/php.ts index 8a172956..da8ba909 100644 --- a/resources/js/electron-plugin/src/server/php.ts +++ b/resources/js/electron-plugin/src/server/php.ts @@ -115,15 +115,7 @@ function ensureAppFoldersAreAvailable() { } function startQueueWorker(secret, apiPort, phpIniSettings = {}) { - const env = { - APP_ENV: process.env.NODE_ENV === 'development' ? 'local' : 'production', - APP_DEBUG: process.env.NODE_ENV === 'development' ? 'true' : 'false', - NATIVEPHP_STORAGE_PATH: storagePath, - NATIVEPHP_DATABASE_PATH: databaseFile, - NATIVEPHP_API_URL: `http://localhost:${apiPort}/api/`, - NATIVEPHP_RUNNING: true, - NATIVEPHP_SECRET: secret - }; + const env = getDefaultEnvironmentVariables(secret, apiPort); const phpOptions = { cwd: appPath, From 39ec97dd0ac99dce30a37a37b4913bde8ad1c838 Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Fri, 15 Nov 2024 16:13:56 +0000 Subject: [PATCH 11/16] Build plugin --- .../dist/server/api/childProcess.js | 15 ++++++++--- .../js/electron-plugin/dist/server/php.js | 26 +++++++------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/resources/js/electron-plugin/dist/server/api/childProcess.js b/resources/js/electron-plugin/dist/server/api/childProcess.js index ee19e68e..9feca430 100644 --- a/resources/js/electron-plugin/dist/server/api/childProcess.js +++ b/resources/js/electron-plugin/dist/server/api/childProcess.js @@ -12,7 +12,7 @@ import { utilityProcess } from 'electron'; import state from '../state'; import { notifyLaravel } from "../utils"; import { join } from 'path'; -import { getDefaultEnvironmentVariables } from "../php"; +import { getDefaultEnvironmentVariables, getDefaultPhpIniSettings } from "../php"; const router = express.Router(); const killSync = require('kill-sync'); function startProcess(settings) { @@ -20,12 +20,11 @@ function startProcess(settings) { if (getProcess(alias) !== undefined) { return state.processes[alias]; } - const defaultEnv = getDefaultEnvironmentVariables(state.randomSecret, state.electronApiPort); const proc = utilityProcess.fork(join(__dirname, '../../electron-plugin/dist/server/childProcess.js'), cmd, { cwd, stdio: 'pipe', serviceName: alias, - env: Object.assign(Object.assign(Object.assign({}, process.env), env), defaultEnv) + env: Object.assign(Object.assign({}, process.env), env) }); proc.stdout.on('data', (data) => { notifyLaravel('events', { @@ -107,6 +106,16 @@ router.post('/start', (req, res) => { const proc = startProcess(req.body); res.json(proc); }); +router.post('/start-php', (req, res) => { + const defaultEnv = getDefaultEnvironmentVariables(state.randomSecret, state.electronApiPort); + const iniSettings = getDefaultPhpIniSettings(); + const iniArgs = Object.keys(iniSettings).map(key => { + return ['-d', `${key}=${iniSettings[key]}`]; + }).flat(); + let settings = Object.assign(Object.assign({}, req.body), { cmd: [state.php, ...iniArgs, ...req.body.cmd], env: Object.assign(Object.assign({}, req.body.env), defaultEnv) }); + const proc = startProcess(settings); + res.json(proc); +}); router.post('/stop', (req, res) => { const { alias } = req.body; stopProcess(alias); diff --git a/resources/js/electron-plugin/dist/server/php.js b/resources/js/electron-plugin/dist/server/php.js index bc0df624..d11d2298 100644 --- a/resources/js/electron-plugin/dist/server/php.js +++ b/resources/js/electron-plugin/dist/server/php.js @@ -58,12 +58,7 @@ function retrieveNativePHPConfig() { }); } function callPhp(args, options, phpIniSettings = {}) { - let defaultIniSettings = { - 'memory_limit': '512M', - 'curl.cainfo': state.caCert, - 'openssl.cafile': state.caCert - }; - let iniSettings = Object.assign(defaultIniSettings, phpIniSettings); + let iniSettings = Object.assign(getDefaultPhpIniSettings(), phpIniSettings); Object.keys(iniSettings).forEach(key => { args.unshift('-d', `${key}=${iniSettings[key]}`); }); @@ -101,15 +96,7 @@ function ensureAppFoldersAreAvailable() { } } function startQueueWorker(secret, apiPort, phpIniSettings = {}) { - const env = { - APP_ENV: process.env.NODE_ENV === 'development' ? 'local' : 'production', - APP_DEBUG: process.env.NODE_ENV === 'development' ? 'true' : 'false', - NATIVEPHP_STORAGE_PATH: storagePath, - NATIVEPHP_DATABASE_PATH: databaseFile, - NATIVEPHP_API_URL: `http://localhost:${apiPort}/api/`, - NATIVEPHP_RUNNING: true, - NATIVEPHP_SECRET: secret - }; + const env = getDefaultEnvironmentVariables(secret, apiPort); const phpOptions = { cwd: appPath, env @@ -153,6 +140,13 @@ function getDefaultEnvironmentVariables(secret, apiPort) { NATIVEPHP_RECENT_PATH: getPath('recent'), }; } +function getDefaultPhpIniSettings() { + return { + 'memory_limit': '512M', + 'curl.cainfo': state.caCert, + 'openssl.cafile': state.caCert + }; +} function serveApp(secret, apiPort, phpIniSettings) { return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { const appPath = getAppPath(); @@ -220,4 +214,4 @@ function serveApp(secret, apiPort, phpIniSettings) { }); })); } -export { startQueueWorker, startScheduler, serveApp, getAppPath, retrieveNativePHPConfig, retrievePhpIniSettings, getDefaultEnvironmentVariables }; +export { startQueueWorker, startScheduler, serveApp, getAppPath, retrieveNativePHPConfig, retrievePhpIniSettings, getDefaultEnvironmentVariables, getDefaultPhpIniSettings }; From e4c58a5b5f3e3e37bf4b02b0d6d6533599db5578 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 15 Nov 2024 16:51:46 +0000 Subject: [PATCH 12/16] Code style --- resources/js/electron-plugin/src/server/api/childProcess.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/js/electron-plugin/src/server/api/childProcess.ts b/resources/js/electron-plugin/src/server/api/childProcess.ts index 45ec77ef..d16e4fbc 100644 --- a/resources/js/electron-plugin/src/server/api/childProcess.ts +++ b/resources/js/electron-plugin/src/server/api/childProcess.ts @@ -132,7 +132,6 @@ router.post('/start', (req, res) => { }); router.post('/start-php', (req, res) => { - const defaultEnv = getDefaultEnvironmentVariables( state.randomSecret, state.electronApiPort From 10cb99062f36d6e34eaf50473c8b4849856d3efe Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Sat, 16 Nov 2024 22:37:12 +0100 Subject: [PATCH 13/16] merge defaults with user configured ini settings --- resources/js/electron-plugin/src/server/api/childProcess.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/js/electron-plugin/src/server/api/childProcess.ts b/resources/js/electron-plugin/src/server/api/childProcess.ts index 45ec77ef..2b38b6fb 100644 --- a/resources/js/electron-plugin/src/server/api/childProcess.ts +++ b/resources/js/electron-plugin/src/server/api/childProcess.ts @@ -139,7 +139,7 @@ router.post('/start-php', (req, res) => { ); // Construct command args from ini settings - const iniSettings = getDefaultPhpIniSettings(); + const iniSettings = { ...getDefaultPhpIniSettings(), ...state.phpIni }; const iniArgs = Object.keys(iniSettings).map(key => { return ['-d', `${key}=${iniSettings[key]}`]; }).flat(); From 4e9201c19fb60cf76bd5cb9ed6ab83e6fa02f211 Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Sat, 16 Nov 2024 21:38:57 +0000 Subject: [PATCH 14/16] Build plugin --- resources/js/electron-plugin/dist/server/api/childProcess.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/js/electron-plugin/dist/server/api/childProcess.js b/resources/js/electron-plugin/dist/server/api/childProcess.js index 9feca430..f760c7c6 100644 --- a/resources/js/electron-plugin/dist/server/api/childProcess.js +++ b/resources/js/electron-plugin/dist/server/api/childProcess.js @@ -108,7 +108,7 @@ router.post('/start', (req, res) => { }); router.post('/start-php', (req, res) => { const defaultEnv = getDefaultEnvironmentVariables(state.randomSecret, state.electronApiPort); - const iniSettings = getDefaultPhpIniSettings(); + const iniSettings = Object.assign(Object.assign({}, getDefaultPhpIniSettings()), state.phpIni); const iniArgs = Object.keys(iniSettings).map(key => { return ['-d', `${key}=${iniSettings[key]}`]; }).flat(); From 9b7ca516be117f61e0899e0c17b3b6a79a7b08a2 Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Sun, 17 Nov 2024 00:54:53 +0100 Subject: [PATCH 15/16] tidy --- .../src/server/api/childProcess.ts | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/resources/js/electron-plugin/src/server/api/childProcess.ts b/resources/js/electron-plugin/src/server/api/childProcess.ts index 59ecd8ee..c2f869a2 100644 --- a/resources/js/electron-plugin/src/server/api/childProcess.ts +++ b/resources/js/electron-plugin/src/server/api/childProcess.ts @@ -95,6 +95,30 @@ function startProcess(settings) { }; } +function startPhpProcess(settings) { + const defaultEnv = getDefaultEnvironmentVariables( + state.randomSecret, + state.electronApiPort + ); + + // Construct command args from ini settings + const iniSettings = { ...getDefaultPhpIniSettings(), ...state.phpIni }; + const iniArgs = Object.keys(iniSettings).map(key => { + return ['-d', `${key}=${iniSettings[key]}`]; + }).flat(); + + + settings = { + ...settings, + // Prepend cmd with php executable path & ini settings + cmd: [ state.php, ...iniArgs, ...settings.cmd ], + // Mix in the internal NativePHP env + env: { ...settings.env, ...defaultEnv } + }; + + return startProcess(settings); +} + function stopProcess(alias) { const proc = getProcess(alias); @@ -132,27 +156,7 @@ router.post('/start', (req, res) => { }); router.post('/start-php', (req, res) => { - const defaultEnv = getDefaultEnvironmentVariables( - state.randomSecret, - state.electronApiPort - ); - - // Construct command args from ini settings - const iniSettings = { ...getDefaultPhpIniSettings(), ...state.phpIni }; - const iniArgs = Object.keys(iniSettings).map(key => { - return ['-d', `${key}=${iniSettings[key]}`]; - }).flat(); - - - let settings = { - ...req.body, - // Prepend cmd with php executable path & ini settings - cmd: [ state.php, ...iniArgs, ...req.body.cmd ], - // Mix in the internal NativePHP env - env: { ...req.body.env, ...defaultEnv } - }; - - const proc = startProcess(settings); + const proc = startPhpProcess(req.body); res.json(proc); }); From b05a599e6d2bd2cca8a6e25a85d3c4400000ee6a Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Sat, 16 Nov 2024 23:56:35 +0000 Subject: [PATCH 16/16] Build plugin --- .../dist/server/api/childProcess.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/resources/js/electron-plugin/dist/server/api/childProcess.js b/resources/js/electron-plugin/dist/server/api/childProcess.js index f760c7c6..a922e785 100644 --- a/resources/js/electron-plugin/dist/server/api/childProcess.js +++ b/resources/js/electron-plugin/dist/server/api/childProcess.js @@ -79,6 +79,15 @@ function startProcess(settings) { settings }; } +function startPhpProcess(settings) { + const defaultEnv = getDefaultEnvironmentVariables(state.randomSecret, state.electronApiPort); + const iniSettings = Object.assign(Object.assign({}, getDefaultPhpIniSettings()), state.phpIni); + const iniArgs = Object.keys(iniSettings).map(key => { + return ['-d', `${key}=${iniSettings[key]}`]; + }).flat(); + settings = Object.assign(Object.assign({}, settings), { cmd: [state.php, ...iniArgs, ...settings.cmd], env: Object.assign(Object.assign({}, settings.env), defaultEnv) }); + return startProcess(settings); +} function stopProcess(alias) { const proc = getProcess(alias); if (proc === undefined) { @@ -107,13 +116,7 @@ router.post('/start', (req, res) => { res.json(proc); }); router.post('/start-php', (req, res) => { - const defaultEnv = getDefaultEnvironmentVariables(state.randomSecret, state.electronApiPort); - const iniSettings = Object.assign(Object.assign({}, getDefaultPhpIniSettings()), state.phpIni); - const iniArgs = Object.keys(iniSettings).map(key => { - return ['-d', `${key}=${iniSettings[key]}`]; - }).flat(); - let settings = Object.assign(Object.assign({}, req.body), { cmd: [state.php, ...iniArgs, ...req.body.cmd], env: Object.assign(Object.assign({}, req.body.env), defaultEnv) }); - const proc = startProcess(settings); + const proc = startPhpProcess(req.body); res.json(proc); }); router.post('/stop', (req, res) => {