Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 861dfab

Browse files
authored
Add broadcasting endpoint & dispatch ipc event (#37)
1 parent 833bb83 commit 861dfab

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/server/api.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import appRoutes from "./api/app";
88
import screenRoutes from "./api/screen";
99
import dialogRoutes from "./api/dialog";
1010
import debugRoutes from "./api/debug";
11+
import broadcastingRoutes from "./api/broadcasting";
1112
import systemRoutes from "./api/system";
1213
import globalShortcutRoutes from "./api/globalShortcut";
1314
import notificationRoutes from "./api/notification";
@@ -54,6 +55,7 @@ async function startAPIServer(randomSecret: string): Promise<APIProcess> {
5455
httpServer.use("/api/menu-bar", menuBarRoutes);
5556
httpServer.use("/api/progress-bar", progressBarRoutes);
5657
httpServer.use("/api/power-monitor", powerMonitorRoutes);
58+
httpServer.use("/api/broadcast", broadcastingRoutes);
5759

5860
if (process.env.NODE_ENV === "development") {
5961
httpServer.use("/api/debug", debugRoutes);

src/server/api/broadcasting.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import express from 'express'
2+
import state from "../state";
3+
const router = express.Router();
4+
5+
router.post('/', (req, res) => {
6+
const {event, payload} = req.body;
7+
8+
Object.values(state.windows).forEach(window => {
9+
window.webContents.send('native-event', { event, payload })
10+
})
11+
12+
if (state.activeMenuBar?.window) {
13+
state.activeMenuBar.window.webContents.send('native-event', { event, payload })
14+
}
15+
16+
res.sendStatus(200)
17+
})
18+
19+
export default router;

0 commit comments

Comments
 (0)