Skip to content

Commit

Permalink
Add broadcasting endpoint & dispatch ipc event (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
gwleuverink authored Sep 10, 2024
1 parent 833bb83 commit 861dfab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/server/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import appRoutes from "./api/app";
import screenRoutes from "./api/screen";
import dialogRoutes from "./api/dialog";
import debugRoutes from "./api/debug";
import broadcastingRoutes from "./api/broadcasting";
import systemRoutes from "./api/system";
import globalShortcutRoutes from "./api/globalShortcut";
import notificationRoutes from "./api/notification";
Expand Down Expand Up @@ -54,6 +55,7 @@ async function startAPIServer(randomSecret: string): Promise<APIProcess> {
httpServer.use("/api/menu-bar", menuBarRoutes);
httpServer.use("/api/progress-bar", progressBarRoutes);
httpServer.use("/api/power-monitor", powerMonitorRoutes);
httpServer.use("/api/broadcast", broadcastingRoutes);

if (process.env.NODE_ENV === "development") {
httpServer.use("/api/debug", debugRoutes);
Expand Down
19 changes: 19 additions & 0 deletions src/server/api/broadcasting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import express from 'express'
import state from "../state";
const router = express.Router();

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

Object.values(state.windows).forEach(window => {
window.webContents.send('native-event', { event, payload })
})

if (state.activeMenuBar?.window) {
state.activeMenuBar.window.webContents.send('native-event', { event, payload })
}

res.sendStatus(200)
})

export default router;

0 comments on commit 861dfab

Please sign in to comment.