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

Add broadcasting endpoint & dispatch ipc event #37

Merged
merged 1 commit into from
Sep 10, 2024
Merged
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
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;
Loading