diff --git a/resources/js/electron-plugin/dist/index.js b/resources/js/electron-plugin/dist/index.js index a34180b..f4212f4 100644 --- a/resources/js/electron-plugin/dist/index.js +++ b/resources/js/electron-plugin/dist/index.js @@ -16,7 +16,9 @@ import { notifyLaravel } from "./server/utils.js"; import { resolve } from "path"; import { stopAllProcesses } from "./server/api/childProcess.js"; import ps from "ps-node"; +import { watch } from "fs"; import electronUpdater from 'electron-updater'; +import { getAppPath } from "./server/php.js"; const { autoUpdater } = electronUpdater; class NativePHP { constructor() { @@ -78,6 +80,9 @@ class NativePHP { state.phpIni = yield this.loadPhpIni(); yield this.startPhpApp(); this.startScheduler(); + if (process.env.NODE_ENV === "development") { + this.watchPhpChanges(); + } yield notifyLaravel("booted"); }); } @@ -173,5 +178,18 @@ class NativePHP { } }); } + watchPhpChanges() { + const appPath = getAppPath(); + watch(appPath, { recursive: true }, (eventType, filename) => { + if (filename && filename.endsWith('.php')) { + console.log(`PHP file changed: ${filename} (${eventType})`); + notifyLaravel('events', { + event: '\\Native\\Laravel\\Events\\App\\ProjectFileChanged', + payload: [filename], + }); + } + }); + console.log(`Watching for PHP file changes in: ${appPath}`); + } } export default new NativePHP(); diff --git a/resources/js/electron-plugin/src/index.ts b/resources/js/electron-plugin/src/index.ts index 191c5d9..69ce396 100644 --- a/resources/js/electron-plugin/src/index.ts +++ b/resources/js/electron-plugin/src/index.ts @@ -14,9 +14,11 @@ import { notifyLaravel } from "./server/utils.js"; import { resolve } from "path"; import { stopAllProcesses } from "./server/api/childProcess.js"; import ps from "ps-node"; +import {watch} from "fs"; // Workaround for CommonJS module import electronUpdater from 'electron-updater'; +import {getAppPath} from "./server/php.js"; const { autoUpdater } = electronUpdater; class NativePHP { @@ -107,6 +109,10 @@ class NativePHP { await this.startPhpApp(); this.startScheduler(); + if (process.env.NODE_ENV === "development") { + this.watchPhpChanges(); + } + await notifyLaravel("booted"); } @@ -216,6 +222,22 @@ class NativePHP { } }); } + + private watchPhpChanges() { + const appPath = getAppPath(); + + watch(appPath, { recursive: true }, (eventType, filename) => { + if (filename && filename.endsWith('.php')) { + console.log(`PHP file changed: ${filename} (${eventType})`); + notifyLaravel('events', { + event: '\\Native\\Laravel\\Events\\App\\ProjectFileChanged', + payload: [filename], + }); + } + }); + + console.log(`Watching for PHP file changes in: ${appPath}`); + } } export default new NativePHP();