Skip to content

Commit ff07152

Browse files
Add --no-focus flag to native:run command (#93)
* Add --no-focus flag to native:run command * Fix test * Attempt to fix workflow for PRs --------- Co-authored-by: Simon Hamp <simon.hamp@me.com>
1 parent 6d1455f commit ff07152

File tree

12 files changed

+26
-3
lines changed

12 files changed

+26
-3
lines changed

.github/workflows/fix-php-code-style-issues.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
uses: actions/checkout@v5
2424
with:
2525
ref: ${{ github.head_ref || github.sha }}
26+
fetch-depth: 0
2627

2728
- name: Check PHP code style issues
2829
if: github.event_name == 'push'

resources/electron/electron-plugin/dist/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class NativePHP {
9595
details.requestHeaders['X-NativePHP-Secret'] = state.randomSecret;
9696
callback({ requestHeaders: details.requestHeaders });
9797
});
98+
if (process.env.NATIVEPHP_NO_FOCUS) {
99+
state.noFocusOnRestart = true;
100+
}
98101
yield notifyLaravel("booted");
99102
});
100103
}

resources/electron/electron-plugin/dist/server/api/window.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ router.post('/open', (req, res) => {
274274
});
275275
}
276276
window.webContents.on('did-finish-load', () => {
277+
if (state.noFocusOnRestart && window.isVisible()) {
278+
return;
279+
}
277280
window.show();
278281
});
279282
window.webContents.on('did-fail-load', (event) => {

resources/electron/electron-plugin/dist/server/state.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default {
3636
randomSecret: generateRandomString(32),
3737
processes: {},
3838
windows: {},
39+
noFocusOnRestart: false,
3940
findWindow(id) {
4041
return this.windows[id] || null;
4142
},

resources/electron/electron-plugin/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ class NativePHP {
131131
callback({ requestHeaders: details.requestHeaders });
132132
});
133133

134+
if (process.env.NATIVEPHP_NO_FOCUS) {
135+
state.noFocusOnRestart = true;
136+
}
137+
134138
await notifyLaravel("booted");
135139
}
136140

resources/electron/electron-plugin/src/server/api/window.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ router.post('/open', (req, res) => {
415415
}
416416

417417
window.webContents.on('did-finish-load', () => {
418+
if (state.noFocusOnRestart && window.isVisible()) {
419+
return;
420+
}
421+
418422
window.show();
419423
});
420424

resources/electron/electron-plugin/src/server/state.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ interface State {
3333
randomSecret: string;
3434
store: Store;
3535
findWindow: (id: string) => BrowserWindow | null;
36+
noFocusOnRestart: boolean;
3637
dockBounce: number;
3738
}
3839

@@ -63,6 +64,7 @@ export default {
6364
randomSecret: generateRandomString(32),
6465
processes: {},
6566
windows: {},
67+
noFocusOnRestart: false,
6668
findWindow(id: string) {
6769
return this.windows[id] || null;
6870
},

src/Drivers/Electron/Commands/RunCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class RunCommand extends Command
2525
use InstallsAppIcon;
2626
use PatchesPackagesJson;
2727

28-
protected $signature = 'native:run {--no-queue} {--D|no-dependencies} {--installer=npm}';
28+
protected $signature = 'native:run {--no-queue} {--no-focus} {--D|no-dependencies} {--installer=npm}';
2929

3030
public function __construct(
3131
protected Builder $builder
@@ -62,6 +62,7 @@ public function handle(): void
6262
$this->runDeveloper(
6363
installer: $this->option('installer'),
6464
skip_queue: $this->option('no-queue'),
65+
no_focus: $this->option('no-focus'),
6566
withoutInteraction: $this->option('no-interaction')
6667
);
6768
}

src/Drivers/Electron/Commands/ServeCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
)]
1313
class ServeCommand extends RunCommand
1414
{
15-
protected $signature = 'native:serve {--no-queue} {--D|no-dependencies} {--installer=npm}';
15+
protected $signature = 'native:serve {--no-queue} {--no-focus} {--D|no-dependencies} {--installer=npm}';
1616

1717
public function handle(): void
1818
{

src/Drivers/Electron/Traits/Developer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ trait Developer
88
{
99
use ExecuteCommand;
1010

11-
protected function runDeveloper(string $installer, bool $skip_queue, bool $withoutInteraction = false): void
11+
protected function runDeveloper(string $installer, bool $skip_queue, bool $no_focus = false, bool $withoutInteraction = false): void
1212
{
1313
[$installer, $command] = $this->getInstallerAndCommand(installer: $installer, type: 'dev');
1414

@@ -18,6 +18,7 @@ protected function runDeveloper(string $installer, bool $skip_queue, bool $witho
1818
command: $command,
1919
skip_queue: $skip_queue,
2020
type: 'serve',
21+
no_focus: $no_focus,
2122
withoutInteraction: $withoutInteraction
2223
);
2324
}

0 commit comments

Comments
 (0)