From 3146cad0cfad0a29206017f7b5b32412aa7017cf Mon Sep 17 00:00:00 2001 From: Matt Stauffer Date: Tue, 3 Mar 2026 15:01:26 -0500 Subject: [PATCH 1/3] Add --no-focus flag to native:run command --- resources/electron/electron-plugin/dist/index.js | 3 +++ resources/electron/electron-plugin/dist/server/api/window.js | 3 +++ resources/electron/electron-plugin/dist/server/state.js | 1 + resources/electron/electron-plugin/src/index.ts | 4 ++++ resources/electron/electron-plugin/src/server/api/window.ts | 4 ++++ resources/electron/electron-plugin/src/server/state.ts | 2 ++ src/Drivers/Electron/Commands/RunCommand.php | 3 ++- src/Drivers/Electron/Commands/ServeCommand.php | 2 +- src/Drivers/Electron/Traits/Developer.php | 3 ++- src/Drivers/Electron/Traits/ExecuteCommand.php | 2 ++ 10 files changed, 24 insertions(+), 3 deletions(-) diff --git a/resources/electron/electron-plugin/dist/index.js b/resources/electron/electron-plugin/dist/index.js index 6f089e8..54fb882 100644 --- a/resources/electron/electron-plugin/dist/index.js +++ b/resources/electron/electron-plugin/dist/index.js @@ -95,6 +95,9 @@ class NativePHP { details.requestHeaders['X-NativePHP-Secret'] = state.randomSecret; callback({ requestHeaders: details.requestHeaders }); }); + if (process.env.NATIVEPHP_NO_FOCUS) { + state.noFocusOnRestart = true; + } yield notifyLaravel("booted"); }); } diff --git a/resources/electron/electron-plugin/dist/server/api/window.js b/resources/electron/electron-plugin/dist/server/api/window.js index 1754f77..e34e8bc 100644 --- a/resources/electron/electron-plugin/dist/server/api/window.js +++ b/resources/electron/electron-plugin/dist/server/api/window.js @@ -274,6 +274,9 @@ router.post('/open', (req, res) => { }); } window.webContents.on('did-finish-load', () => { + if (state.noFocusOnRestart && window.isVisible()) { + return; + } window.show(); }); window.webContents.on('did-fail-load', (event) => { diff --git a/resources/electron/electron-plugin/dist/server/state.js b/resources/electron/electron-plugin/dist/server/state.js index cb565b5..1bc243f 100644 --- a/resources/electron/electron-plugin/dist/server/state.js +++ b/resources/electron/electron-plugin/dist/server/state.js @@ -36,6 +36,7 @@ export default { randomSecret: generateRandomString(32), processes: {}, windows: {}, + noFocusOnRestart: false, findWindow(id) { return this.windows[id] || null; }, diff --git a/resources/electron/electron-plugin/src/index.ts b/resources/electron/electron-plugin/src/index.ts index 7eca5b0..a1a9680 100644 --- a/resources/electron/electron-plugin/src/index.ts +++ b/resources/electron/electron-plugin/src/index.ts @@ -131,6 +131,10 @@ class NativePHP { callback({ requestHeaders: details.requestHeaders }); }); + if (process.env.NATIVEPHP_NO_FOCUS) { + state.noFocusOnRestart = true; + } + await notifyLaravel("booted"); } diff --git a/resources/electron/electron-plugin/src/server/api/window.ts b/resources/electron/electron-plugin/src/server/api/window.ts index 8b5dcbe..b9a8f5e 100644 --- a/resources/electron/electron-plugin/src/server/api/window.ts +++ b/resources/electron/electron-plugin/src/server/api/window.ts @@ -415,6 +415,10 @@ router.post('/open', (req, res) => { } window.webContents.on('did-finish-load', () => { + if (state.noFocusOnRestart && window.isVisible()) { + return; + } + window.show(); }); diff --git a/resources/electron/electron-plugin/src/server/state.ts b/resources/electron/electron-plugin/src/server/state.ts index 503485e..e807b48 100644 --- a/resources/electron/electron-plugin/src/server/state.ts +++ b/resources/electron/electron-plugin/src/server/state.ts @@ -33,6 +33,7 @@ interface State { randomSecret: string; store: Store; findWindow: (id: string) => BrowserWindow | null; + noFocusOnRestart: boolean; dockBounce: number; } @@ -63,6 +64,7 @@ export default { randomSecret: generateRandomString(32), processes: {}, windows: {}, + noFocusOnRestart: false, findWindow(id: string) { return this.windows[id] || null; }, diff --git a/src/Drivers/Electron/Commands/RunCommand.php b/src/Drivers/Electron/Commands/RunCommand.php index 5c0d71f..32dfce5 100644 --- a/src/Drivers/Electron/Commands/RunCommand.php +++ b/src/Drivers/Electron/Commands/RunCommand.php @@ -25,7 +25,7 @@ class RunCommand extends Command use InstallsAppIcon; use PatchesPackagesJson; - protected $signature = 'native:run {--no-queue} {--D|no-dependencies} {--installer=npm}'; + protected $signature = 'native:run {--no-queue} {--no-focus} {--D|no-dependencies} {--installer=npm}'; public function __construct( protected Builder $builder @@ -62,6 +62,7 @@ public function handle(): void $this->runDeveloper( installer: $this->option('installer'), skip_queue: $this->option('no-queue'), + no_focus: $this->option('no-focus'), withoutInteraction: $this->option('no-interaction') ); } diff --git a/src/Drivers/Electron/Commands/ServeCommand.php b/src/Drivers/Electron/Commands/ServeCommand.php index 586b3fb..911aa21 100644 --- a/src/Drivers/Electron/Commands/ServeCommand.php +++ b/src/Drivers/Electron/Commands/ServeCommand.php @@ -12,7 +12,7 @@ )] class ServeCommand extends RunCommand { - protected $signature = 'native:serve {--no-queue} {--D|no-dependencies} {--installer=npm}'; + protected $signature = 'native:serve {--no-queue} {--no-focus} {--D|no-dependencies} {--installer=npm}'; public function handle(): void { diff --git a/src/Drivers/Electron/Traits/Developer.php b/src/Drivers/Electron/Traits/Developer.php index 94dcca1..7e5a248 100644 --- a/src/Drivers/Electron/Traits/Developer.php +++ b/src/Drivers/Electron/Traits/Developer.php @@ -8,7 +8,7 @@ trait Developer { use ExecuteCommand; - protected function runDeveloper(string $installer, bool $skip_queue, bool $withoutInteraction = false): void + protected function runDeveloper(string $installer, bool $skip_queue, bool $no_focus = false, bool $withoutInteraction = false): void { [$installer, $command] = $this->getInstallerAndCommand(installer: $installer, type: 'dev'); @@ -18,6 +18,7 @@ protected function runDeveloper(string $installer, bool $skip_queue, bool $witho command: $command, skip_queue: $skip_queue, type: 'serve', + no_focus: $no_focus, withoutInteraction: $withoutInteraction ); } diff --git a/src/Drivers/Electron/Traits/ExecuteCommand.php b/src/Drivers/Electron/Traits/ExecuteCommand.php index 3a2bad2..1d72384 100644 --- a/src/Drivers/Electron/Traits/ExecuteCommand.php +++ b/src/Drivers/Electron/Traits/ExecuteCommand.php @@ -14,6 +14,7 @@ protected function executeCommand( string $command, bool $skip_queue = false, string $type = 'install', + bool $no_focus = false, bool $withoutInteraction = false ): void { @@ -32,6 +33,7 @@ protected function executeCommand( 'NATIVEPHP_BUILDING' => false, 'NATIVEPHP_ELECTRON_PATH' => ElectronServiceProvider::electronPath(), 'NATIVEPHP_BUILD_PATH' => ElectronServiceProvider::buildPath(), + 'NATIVEPHP_NO_FOCUS' => $no_focus, ], ]; From 1f3a2917a57a61fd8749304248be68a1aa5da0ea Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 4 Mar 2026 11:45:59 +0100 Subject: [PATCH 2/3] Fix test --- tests/QueueWorker/QueueWorkerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/QueueWorker/QueueWorkerTest.php b/tests/QueueWorker/QueueWorkerTest.php index 19e3f5a..dbd8da8 100644 --- a/tests/QueueWorker/QueueWorkerTest.php +++ b/tests/QueueWorker/QueueWorkerTest.php @@ -21,6 +21,7 @@ '--memory=128', '--timeout=61', '--sleep=5', + '--quiet', ]); expect($iniSettings)->toBe([ From e18fe63261d6a30c9f8b334bb982b93112893fef Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 4 Mar 2026 11:55:48 +0100 Subject: [PATCH 3/3] Attempt to fix workflow for PRs --- .github/workflows/fix-php-code-style-issues.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml index 95c93e0..8b457d2 100644 --- a/.github/workflows/fix-php-code-style-issues.yml +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -23,6 +23,7 @@ jobs: uses: actions/checkout@v5 with: ref: ${{ github.head_ref || github.sha }} + fetch-depth: 0 - name: Check PHP code style issues if: github.event_name == 'push'