Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions resources/electron/electron-plugin/dist/server/api/menuBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ router.post("/context-menu", (req, res) => {
const { contextMenu } = req.body;
(_a = state.tray) === null || _a === void 0 ? void 0 : _a.setContextMenu(buildMenu(contextMenu));
});
router.post("/show-context-menu", (req, res) => {
var _a;
res.sendStatus(200);
(_a = state.tray) === null || _a === void 0 ? void 0 : _a.popUpContextMenu();
});
router.post("/show", (req, res) => {
res.sendStatus(200);
state.activeMenuBar.showWindow();
Expand Down
6 changes: 6 additions & 0 deletions resources/electron/electron-plugin/src/server/api/menuBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ router.post("/context-menu", (req, res) => {
state.tray?.setContextMenu(buildMenu(contextMenu));
});

router.post("/show-context-menu", (req, res) => {
res.sendStatus(200);

state.tray?.popUpContextMenu();
});

router.post("/show", (req, res) => {
res.sendStatus(200);

Expand Down
1 change: 1 addition & 0 deletions src/Facades/MenuBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @method static void icon(string $icon)
* @method static void resize(int $width, int $height)
* @method static void contextMenu(Menu $contextMenu)
* @method static void showContextMenu()
* @method static void webPreferences(array $preferences)
*/
class MenuBar extends Facade
Expand Down
5 changes: 5 additions & 0 deletions src/MenuBar/MenuBarManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ public function contextMenu(Menu $contextMenu)
'contextMenu' => $contextMenu->toArray()['submenu'],
]);
}

public function showContextMenu()
{
$this->client->post('menu-bar/show-context-menu');
}
}
13 changes: 13 additions & 0 deletions tests/MenuBar/MenuBarTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Illuminate\Support\Facades\Http;
use Native\Desktop\Facades\Menu;
use Native\Desktop\Facades\MenuBar;

Expand Down Expand Up @@ -30,3 +31,15 @@
$this->assertEquals('trayCenter', $menuBarArray['windowPosition']);
$this->assertIsArray($menuBarArray['contextMenu']);
});

it('can show context menu programmatically', function () {
Http::fake([
'*/menu-bar/show-context-menu' => Http::response([], 200),
]);

MenuBar::showContextMenu();

Http::assertSent(function ($request) {
return str_contains($request->url(), 'menu-bar/show-context-menu');
});
});
Loading