Skip to content

Commit 8e0a61f

Browse files
Add trafficLightsHidden method to hide traffic lights (#58)
* Add trafficLightsHidden method to hide traffic lights * Add setWindowButtonVisibility option to hide traffic lights
1 parent 504755b commit 8e0a61f

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ router.post('/closable', (req, res) => {
4141
(_a = state.windows[id]) === null || _a === void 0 ? void 0 : _a.setClosable(closable);
4242
res.sendStatus(200);
4343
});
44+
router.post('/window-button-visibility', (req, res) => {
45+
var _a;
46+
const { id, windowButtonVisibility } = req.body;
47+
(_a = state.windows[id]) === null || _a === void 0 ? void 0 : _a.setWindowButtonVisibility(windowButtonVisibility);
48+
res.sendStatus(200);
49+
});
4450
router.post('/show-dev-tools', (req, res) => {
4551
var _a;
4652
const { id } = req.body;
@@ -145,7 +151,7 @@ function getWindowData(id) {
145151
};
146152
}
147153
router.post('/open', (req, res) => {
148-
let { id, x, y, frame, width, height, minWidth, minHeight, maxWidth, maxHeight, focusable, skipTaskbar, hiddenInMissionControl, hasShadow, url, resizable, movable, minimizable, maximizable, closable, title, alwaysOnTop, titleBarStyle, trafficLightPosition, vibrancy, backgroundColor, transparency, showDevTools, fullscreen, fullscreenable, kiosk, autoHideMenuBar, webPreferences, zoomFactor, preventLeaveDomain, preventLeavePage, suppressNewWindows, } = req.body;
154+
let { id, x, y, frame, width, height, minWidth, minHeight, maxWidth, maxHeight, focusable, skipTaskbar, hiddenInMissionControl, hasShadow, url, resizable, movable, minimizable, maximizable, closable, title, alwaysOnTop, titleBarStyle, trafficLightPosition, windowButtonVisibility, vibrancy, backgroundColor, transparency, showDevTools, fullscreen, fullscreenable, kiosk, autoHideMenuBar, webPreferences, zoomFactor, preventLeaveDomain, preventLeavePage, suppressNewWindows, } = req.body;
149155
if (state.windows[id]) {
150156
state.windows[id].show();
151157
state.windows[id].focus();
@@ -193,6 +199,9 @@ router.post('/open', (req, res) => {
193199
return { action: "deny" };
194200
});
195201
}
202+
if (process.platform === 'darwin') {
203+
window.setWindowButtonVisibility(windowButtonVisibility);
204+
}
196205
window.on('blur', () => {
197206
notifyLaravel('events', {
198207
event: 'Native\\Desktop\\Events\\Windows\\WindowBlurred',

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ router.post('/closable', (req, res) => {
5858
res.sendStatus(200);
5959
});
6060

61+
router.post('/window-button-visibility', (req, res) => {
62+
const {id, windowButtonVisibility} = req.body;
63+
64+
state.windows[id]?.setWindowButtonVisibility(windowButtonVisibility);
65+
66+
res.sendStatus(200);
67+
});
68+
6169
router.post('/show-dev-tools', (req, res) => {
6270
const {id} = req.body;
6371

@@ -225,6 +233,7 @@ router.post('/open', (req, res) => {
225233
alwaysOnTop,
226234
titleBarStyle,
227235
trafficLightPosition,
236+
windowButtonVisibility,
228237
vibrancy,
229238
backgroundColor,
230239
transparency,
@@ -313,6 +322,10 @@ router.post('/open', (req, res) => {
313322
});
314323
}
315324

325+
if (process.platform === 'darwin') {
326+
window.setWindowButtonVisibility(windowButtonVisibility);
327+
}
328+
316329
window.on('blur', () => {
317330
notifyLaravel('events', {
318331
event: 'Native\\Desktop\\Events\\Windows\\WindowBlurred',

resources/electron/electron-plugin/tests/setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ mockForNodeRequire('electron', () => ({
3737
on: vi.fn(),
3838
setMenu: vi.fn(),
3939
setMenuBarVisibility: vi.fn(),
40+
setWindowButtonVisibility: vi.fn(),
4041
webContents: {
4142
on: vi.fn(),
4243
send: vi.fn(),

src/Windows/Window.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class Window
6060

6161
protected array $trafficLightPosition = [];
6262

63+
protected bool $windowButtonVisibility = true;
64+
6365
protected string $title = '';
6466

6567
protected string $id = 'main';
@@ -150,6 +152,18 @@ public function trafficLightPosition(int $x, int $y): self
150152
return $this;
151153
}
152154

155+
public function trafficLightsHidden(): self
156+
{
157+
return $this->windowButtonVisibility(false);
158+
}
159+
160+
public function windowButtonVisibility($visible = true): self
161+
{
162+
$this->windowButtonVisibility = $visible;
163+
164+
return $this;
165+
}
166+
153167
public function rememberState(): self
154168
{
155169
$this->rememberState = true;
@@ -392,6 +406,7 @@ public function toArray()
392406
'frame' => $this->frame,
393407
'titleBarStyle' => $this->titleBarStyle,
394408
'trafficLightPosition' => $this->trafficLightPosition,
409+
'windowButtonVisibility' => $this->windowButtonVisibility,
395410
'showDevTools' => $this->showDevTools,
396411
'vibrancy' => $this->vibrancy,
397412
'transparency' => $this->transparent,

tests/Windows/WindowTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
->closable()
3030
->fullscreen()
3131
->kiosk()
32-
->hideMenu();
32+
->hideMenu()
33+
->trafficLightsHidden();
3334

3435
$windowArray = $window->toArray();
3536

@@ -52,6 +53,7 @@
5253
expect($windowArray['fullscreen'])->toBeTrue();
5354
expect($windowArray['kiosk'])->toBeTrue();
5455
expect($windowArray['autoHideMenuBar'])->toBeTrue();
56+
expect($windowArray['windowButtonVisibility'])->toBeFalse();
5557
});
5658

5759
it('test title bar for window', function () {

0 commit comments

Comments
 (0)