Skip to content

Commit 0d5366d

Browse files
committed
Support getting a specific window
1 parent fb234e7 commit 0d5366d

File tree

1 file changed

+46
-5
lines changed
  • resources/js/electron-plugin/src/server/api

1 file changed

+46
-5
lines changed

resources/js/electron-plugin/src/server/api/window.ts

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,60 @@ router.post('/hide', (req, res) => {
6464
})
6565

6666
router.get('/current', (req, res) => {
67-
const currentWindow = Object.values(state.windows).find(window => window.id === BrowserWindow.getFocusedWindow().id)
68-
// Find object key with matching value
69-
const id = Object.keys(state.windows).find(key => state.windows[key] === currentWindow)
67+
// Find the current window object
68+
const currentWindow = Object.values(state.windows).find(window => window.id === BrowserWindow.getFocusedWindow().id);
7069

71-
res.json({
70+
// Get the developer-assigned id for that window
71+
const id = Object.keys(state.windows).find(key => state.windows[key] === currentWindow);
72+
73+
res.json(getWindowData(id));
74+
});
75+
76+
router.get('/get/:id', (req, res) => {
77+
const {id} = req.params;
78+
79+
if (state.windows[id] === undefined) {
80+
res.sendStatus(404);
81+
return;
82+
}
83+
84+
res.json(getWindowData(id));
85+
});
86+
87+
function getWindowData(id) {
88+
const currentWindow = state.windows[id];
89+
90+
if (state.windows[id] === undefined) {
91+
throw `Window [${id}] not found`;
92+
}
93+
94+
return {
7295
id: id,
7396
x: currentWindow.getPosition()[0],
7497
y: currentWindow.getPosition()[1],
7598
width: currentWindow.getSize()[0],
7699
height: currentWindow.getSize()[1],
77100
title: currentWindow.getTitle(),
78101
alwaysOnTop: currentWindow.isAlwaysOnTop(),
79-
})
102+
url: currentWindow.webContents.getURL(),
103+
autoHideMenuBar: currentWindow.isMenuBarAutoHide(),
104+
fullscreen: currentWindow.isFullScreen(),
105+
fullscreenable: currentWindow.isFullScreenable(),
106+
kiosk: currentWindow.isKiosk(),
107+
showDevTools: currentWindow.webContents.isDevToolsOpened(),
108+
resizable: currentWindow.isResizable(),
109+
movable: currentWindow.isMovable(),
110+
minimizable: currentWindow.isMinimizable(),
111+
maximizable: currentWindow.isMaximizable(),
112+
closable: currentWindow.isClosable(),
113+
focusable: currentWindow.isFocusable(),
114+
focused: currentWindow.isFocused(),
115+
hasShadow: currentWindow.hasShadow(),
116+
// frame: currentWindow.frame(),
117+
// titleBarStyle: currentWindow.getTitleBarStyle(),
118+
// trafficLightPosition: currentWindow.getTrafficLightPosition(),
119+
};
120+
}
80121
});
81122

82123
router.post('/always-on-top', (req, res) => {

0 commit comments

Comments
 (0)