8000 Feature/menubar improvement (#411) · NativePHP/laravel@c223e0f · GitHub
[go: up one dir, main page]

Skip to content

Commit c223e0f

Browse files
authored
Feature/menubar improvement (#411)
* Refactor variable * Remove override method `url` is already available from the `HasUrl` trait * Add tooltip setting * Add resizable setting * Allow updating of tooltip * Allow updating of icon * Support firing a custom event on click
1 parent 6e6cf13 commit c223e0f

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed
8000

src/MenuBar/MenuBar.php

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@ class MenuBar
2020

2121
protected string $label = '';
2222

23-
protected bool $onlyShowContextWindow = false;
23+
protected string $tooltip = '';
24+
25+
protected bool $resizable = true;
26+
27+
protected bool $onlyShowContextMenu = false;
2428

2529
protected ?Menu $contextMenu = null;
2630

2731
protected bool $alwaysOnTop = false;
2832

33+
protected ?string $event = null;
34+
2935
protected bool $showDockIcon = false;
3036

3137
protected Client $client;
@@ -51,28 +57,35 @@ public function icon(string $icon): self
5157

5258
public function onlyShowContextMenu(bool $onlyContextMenu = true): self
5359
{
54-
$this->onlyShowContextWindow = $onlyContextMenu;
60+
$this->onlyShowContextMenu = $onlyContextMenu;
5561

5662
return $this;
5763
}
5864

59-
public function url(string $url): self
65+
public function showDockIcon($value = true): self
6066
{
61-
$this->url = $url;
67+
$this->showDockIcon = $value;
6268

6369
return $this;
6470
}
6571

66-
public function showDockIcon($value = true): self
72+
public function label(string $label = ''): self
6773
{
68-
$this->showDockIcon = $value;
74+
$this->label = $label;
6975

7076
return $this;
7177
}
7278

73-
public function label(string $label = ''): self
79+
public function tooltip(string $tooltip = ''): self
7480
{
75-
$this->label = $label;
81+
$this->tooltip = $tooltip;
82+
83+
return $this;
84+
}
85+
86+
public function resizable(bool $resizable = true): static
87+
{
88+
$this->resizable = $resizable;
7689

7790
return $this;
7891
}
@@ -84,6 +97,13 @@ public function alwaysOnTop($alwaysOnTop = true): self
8497
return $this;
8598
}
8699

100+
public function event(string $event): self
101+
{
102+
$this->event = $event;
103+
104+
return $this;
105+
}
106+
87107
public function withContextMenu(Menu $menu): self
88108
{
89109
$this->contextMenu = $menu;
@@ -100,15 +120,18 @@ public function toArray(): array
100120
'x' => $this->x,
101121
'y' => $this->y,
102122
'label' => $this->label,
123+
'tooltip' => $this->tooltip,
124+
'resizable' => $this->resizable,
103125
'width' => $this->width,
104126
'height' => $this->height,
105127
'vibrancy' => $this->vibrancy,
106128
'showDockIcon' => $this->showDockIcon,
107129
'transparency' => $this->transparent,
108130
'backgroundColor' => $this->backgroundColor,
109-
'onlyShowContextWindow' => $this->onlyShowContextWindow,
131+
'onlyShowContextMenu' => $this->onlyShowContextMenu,
110132
'contextMenu' => ! is_null($this->contextMenu) ? $this->contextMenu->toArray()['submenu'] : null,
111133
'alwaysOnTop' => $this->alwaysOnTop,
134+
'event' => $this->event,
112135
];
113136
}
114137
}

src/MenuBar/MenuBarManager.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ public function label(string $label)
3131
]);
3232
}
3333

34+
public function tooltip(string $tooltip)
35+
{
36+
$this->client->post('menu-bar/tooltip', [
37+
'tooltip' => $tooltip,
38+
]);
39+
}
40+
41+
public function icon(string $icon)
42+
{
43+
$this->client->post('menu-bar/icon', [
44+
'icon' => $icon,
45+
]);
46+
}
47+
3448
public function contextMenu(Menu $contextMenu)
3549
{
3650
$this->client->post('menu-bar/context-menu', [

0 commit comments

Comments
 (0)
0