Skip to content

Commit

Permalink
Dock goodies (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhamp authored Nov 26, 2024
1 parent 1cdb27a commit 41e4650
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
61 changes: 54 additions & 7 deletions resources/js/electron-plugin/src/server/api/dock.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,61 @@
import express from 'express'
import {app, Menu} from 'electron'
import {mapMenu} from "./helper";
import express from 'express';
import { app, Menu } from 'electron';
import { mapMenu } from './helper';
import state from '../state';

const router = express.Router();

router.post('/', (req, res) => {
const menuEntries = req.body.items.map(mapMenu)
const menuEntries = req.body.items.map(mapMenu);

const menu = Menu.buildFromTemplate(menuEntries);
app.dock.setMenu(menu);

res.sendStatus(200);
});

router.post('/show', (req, res) => {
app.dock.show();

res.sendStatus(200);
});

router.post('/hide', (req, res) => {
app.dock.hide();

res.sendStatus(200);
});

router.post('/icon', (req, res) => {
app.dock.setIcon(req.body.path);

res.sendStatus(200);
});

router.post('/bounce', (req, res) => {
const { type } = req.body;

state.dockBounce = app.dock.bounce(type);

res.sendStatus(200);
});

router.post('/cancel-bounce', (req, res) => {
app.dock.cancelBounce(state.dockBounce);

res.sendStatus(200);
});

router.get('/badge', (req, res) => {
res.json({
label: app.dock.getBadge(),
});
});

router.post('/badge', (req, res) => {
app.dock.setBadge(req.body.label);

const menu = Menu.buildFromTemplate(menuEntries)
app.dock.setMenu(menu)
res.sendStatus(200)
res.sendStatus(200);
});

export default router;
1 change: 1 addition & 0 deletions resources/js/electron-plugin/src/server/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface State {
randomSecret: string;
store: Store;
findWindow: (id: string) => BrowserWindow | null;
dockBounce: number;
}

function generateRandomString(length: number) {
Expand Down

0 comments on commit 41e4650

Please sign in to comment.