Skip to content

Commit

Permalink
Feature/menubar improvement (#411)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
simonhamp authored Nov 14, 2024
1 parent 6e6cf13 commit c223e0f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
41 changes: 32 additions & 9 deletions src/MenuBar/MenuBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ class MenuBar

protected string $label = '';

protected bool $onlyShowContextWindow = false;
protected string $tooltip = '';

protected bool $resizable = true;

protected bool $onlyShowContextMenu = false;

protected ?Menu $contextMenu = null;

protected bool $alwaysOnTop = false;

protected ?string $event = null;

protected bool $showDockIcon = false;

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

public function onlyShowContextMenu(bool $onlyContextMenu = true): self
{
$this->onlyShowContextWindow = $onlyContextMenu;
$this->onlyShowContextMenu = $onlyContextMenu;

return $this;
}

public function url(string $url): self
public function showDockIcon($value = true): self
{
$this->url = $url;
$this->showDockIcon = $value;

return $this;
}

public function showDockIcon($value = true): self
public function label(string $label = ''): self
{
$this->showDockIcon = $value;
$this->label = $label;

return $this;
}

public function label(string $label = ''): self
public function tooltip(string $tooltip = ''): self
{
$this->label = $label;
$this->tooltip = $tooltip;

return $this;
}

public function resizable(bool $resizable = true): static
{
$this->resizable = $resizable;

return $this;
}
Expand All @@ -84,6 +97,13 @@ public function alwaysOnTop($alwaysOnTop = true): self
return $this;
}

public function event(string $event): self
{
$this->event = $event;

return $this;
}

public function withContextMenu(Menu $menu): self
{
$this->contextMenu = $menu;
Expand All @@ -100,15 +120,18 @@ public function toArray(): array
'x' => $this->x,
'y' => $this->y,
'label' => $this->label,
'tooltip' => $this->tooltip,
'resizable' => $this->resizable,
'width' => $this->width,
'height' => $this->height,
'vibrancy' => $this->vibrancy,
'showDockIcon' => $this->showDockIcon,
'transparency' => $this->transparent,
'backgroundColor' => $this->backgroundColor,
'onlyShowContextWindow' => $this->onlyShowContextWindow,
'onlyShowContextMenu' => $this->onlyShowContextMenu,
'contextMenu' => ! is_null($this->contextMenu) ? $this->contextMenu->toArray()['submenu'] : null,
'alwaysOnTop' => $this->alwaysOnTop,
'event' => $this->event,
];
}
}
14 changes: 14 additions & 0 deletions src/MenuBar/MenuBarManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ public function label(string $label)
]);
}

public function tooltip(string $tooltip)
{
$this->client->post('menu-bar/tooltip', [
'tooltip' => $tooltip,
]);
}

public function icon(string $icon)
{
$this->client->post('menu-bar/icon', [
'icon' => $icon,
]);
}

public function contextMenu(Menu $contextMenu)
{
$this->client->post('menu-bar/context-menu', [
Expand Down

0 comments on commit c223e0f

Please sign in to comment.