Skip to content

Commit c75d1e6

Browse files
committed
code style
1 parent dda9bc3 commit c75d1e6

File tree

1 file changed

+109
-87
lines changed
  • resources/js/electron-plugin/src/server/api

1 file changed

+109
-87
lines changed

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

Lines changed: 109 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,95 @@
1-
import express from 'express'
2-
import {BrowserWindow, clipboard, NativeImage} from 'electron'
3-
import state from '../state'
1+
import express from 'express';
2+
import {BrowserWindow, clipboard, NativeImage} from 'electron';
3+
import state from '../state';
44
import {join} from "path";
55
import {notifyLaravel} from "../utils";
66
const router = express.Router();
77
import windowStateKeeper from "electron-window-state";
88

99
router.post('/maximize', (req, res) => {
10-
const {id} = req.body
11-
state.windows[id]?.maximize()
10+
const {id} = req.body;
1211

13-
res.sendStatus(200)
12+
state.windows[id]?.maximize();
13+
14+
res.sendStatus(200);
1415
});
1516

1617
router.post('/minimize', (req, res) => {
17-
const {id} = req.body
18-
state.windows[id]?.minimize()
18+
const {id} = req.body;
19+
20+
state.windows[id]?.minimize();
1921

20-
res.sendStatus(200)
22+
res.sendStatus(200);
2123
});
2224

2325
router.post('/resize', (req, res) => {
24-
const {id, width, height} = req.body
26+
const {id, width, height} = req.body;
27+
28+
state.windows[id]?.setSize(parseInt(width), parseInt(height));
29+
30+
res.sendStatus(200);
31+
});
32+
33+
router.post('/title', (req, res) => {
34+
const {id, title} = req.body;
2535

26-
state.windows[id]?.setSize(parseInt(width), parseInt(height))
36+
state.windows[id]?.setTitle(title);
2737

28-
res.sendStatus(200)
29-
})
38+
res.sendStatus(200);
39+
});
40+
41+
router.post('/url', (req, res) => {
42+
const {id, url} = req.body;
43+
44+
state.windows[id]?.loadURL(url);
3045

46+
res.sendStatus(200);
47+
});
3148

3249
router.post('/position', (req, res) => {
33-
const {id, x, y, animate} = req.body
50+
const {id, x, y, animate} = req.body;
3451

35-
state.windows[id]?.setPosition(parseInt(x), parseInt(y), animate)
52+
state.windows[id]?.setPosition(parseInt(x), parseInt(y), animate);
3653

37-
res.sendStatus(200)
38-
})
54+
res.sendStatus(200);
55+
});
3956

4057
router.post('/reload', (req, res) => {
41-
const {id} = req.body
42-
state.windows[id]?.reload()
58+
const {id} = req.body;
59+
60+
state.windows[id]?.reload();
4361

44-
res.sendStatus(200)
62+
res.sendStatus(200);
4563
});
4664

4765
router.post('/close', (req, res) => {
48-
const {id} = req.body
66+
const {id} = req.body;
4967

5068
if (state.windows[id]) {
51-
state.windows[id].close()
52-
delete state.windows[id]
69+
state.windows[id].close();
70+
delete state.windows[id];
5371
}
54-
return res.sendStatus(200)
55-
})
72+
73+
return res.sendStatus(200);
74+
});
5675

5776
router.post('/hide', (req, res) => {
58-
const {id} = req.body
77+
const {id} = req.body;
5978

6079
if (state.windows[id]) {
61-
state.windows[id].hide()
80+
state.windows[id].hide();
6281
}
63-
return res.sendStatus(200)
64-
})
82+
83+
return res.sendStatus(200);
84+
});
85+
86+
router.post('/always-on-top', (req, res) => {
87+
const {id, alwaysOnTop} = req.body;
88+
89+
state.windows[id]?.setAlwaysOnTop(alwaysOnTop);
90+
91+
res.sendStatus(200);
92+
});
6593

6694
router.get('/current', (req, res) => {
6795
// Find the current window object
@@ -118,14 +146,6 @@ function getWindowData(id) {
118146
// trafficLightPosition: currentWindow.getTrafficLightPosition(),
119147
};
120148
}
121-
});
122-
123-
router.post('/always-on-top', (req, res) => {
124-
const {id, alwaysOnTop} = req.body
125-
state.windows[id]?.setAlwaysOnTop(alwaysOnTop)
126-
127-
res.sendStatus(200)
128-
});
129149

130150
router.post('/open', (req, res) => {
131151
let {
@@ -159,24 +179,24 @@ router.post('/open', (req, res) => {
159179
fullscreenable,
160180
kiosk,
161181
autoHideMenuBar,
162-
} = req.body
182+
} = req.body;
163183

164184
if (state.windows[id]) {
165-
state.windows[id].show()
166-
state.windows[id].focus()
167-
return res.sendStatus(200)
185+
state.windows[id].show();
186+
state.windows[id].focus();
187+
return res.sendStatus(200);
168188
}
169189

170190
let preloadPath = join(__dirname, '../../electron-plugin/dist/preload/index.js')
171191

172-
let windowState: windowStateKeeper.State | undefined = undefined
192+
let windowState: windowStateKeeper.State | undefined = undefined;
173193

174194
if (req.body.rememberState === true) {
175-
windowState = windowStateKeeper({
176-
file: `window-state-${id}.json`,
177-
defaultHeight: parseInt(height),
178-
defaultWidth: parseInt(width),
179-
})
195+
windowState = windowStateKeeper({
196+
file: `window-state-${id}.json`,
197+
defaultHeight: parseInt(height),
198+
defaultWidth: parseInt(width),
199+
});
180200
}
181201

182202
const window = new BrowserWindow({
@@ -217,93 +237,95 @@ router.post('/open', (req, res) => {
217237
fullscreen,
218238
fullscreenable,
219239
kiosk,
220-
})
240+
});
221241

222242
if ((process.env.NODE_ENV === 'development' || showDevTools === true) && showDevTools !== false) {
223243
window.webContents.openDevTools();
224244
}
225245

226-
require("@electron/remote/main").enable(window.webContents)
246+
require("@electron/remote/main").enable(window.webContents);
227247

228248
if (req.body.rememberState === true) {
229-
windowState.manage(window)
249+
windowState.manage(window);
230250
}
231251

232252
window.on('blur', () => {
233253
notifyLaravel('events', {
234-
event: 'Native\\Laravel\\Events\\Windows\\WindowBlurred',
235-
payload: [id]
236-
})
254+
event: 'Native\\Laravel\\Events\\Windows\\WindowBlurred',
255+
payload: [id]
256+
});
237257
});
238258

239259
window.on('focus', () => {
240260
notifyLaravel('events', {
241261
event: 'Native\\Laravel\\Events\\Windows\\WindowFocused',
242262
payload: [id]
243-
})
244-
})
263+
});
264+
});
245265

246266
window.on('minimize', () => {
247267
notifyLaravel('events', {
248268
event: 'Native\\Laravel\\Events\\Windows\\WindowMinimized',
249269
payload: [id]
250-
})
251-
})
270+
});
271+
});
252272

253273
window.on('maximize', () => {
254-
notifyLaravel('events', {
255-
event: 'Native\\Laravel\\Events\\Windows\\WindowMaximized',
256-
payload: [id]
257-
})
258-
})
259-
260-
window.on('show', () => {
261-
notifyLaravel('events', {
262-
event: 'Native\\Laravel\\Events\\Windows\\WindowShown',
263-
payload: [id]
264-
})
265-
});
274+
notifyLaravel('events', {
275+
event: 'Native\\Laravel\\Events\\Windows\\WindowMaximized',
276+
payload: [id]
277+
});
278+
});
279+
280+
window.on('show', () => {
281+
notifyLaravel('events', {
282+
event: 'Native\\Laravel\\Events\\Windows\\WindowShown',
283+
payload: [id]
284+
});
285+
});
266286

267287
window.on('resized', () => {
268-
notifyLaravel('events', {
269-
event: 'Native\\Laravel\\Events\\Windows\\WindowResized',
270-
payload: [id, window.getSize()[0], window.getSize()[1]]
271-
})
288+
notifyLaravel('events', {
289+
event: 'Native\\Laravel\\Events\\Windows\\WindowResized',
290+
payload: [id, window.getSize()[0], window.getSize()[1]]
291+
});
272292
});
273293

274294
window.on('page-title-updated', (evt) => {
275-
evt.preventDefault()
276-
})
295+
evt.preventDefault();
296+
});
277297

278298
window.on('close', (evt) => {
279299
if (state.windows[id]) {
280-
delete state.windows[id]
300+
delete state.windows[id];
281301
}
302+
282303
notifyLaravel('events', {
283304
event: 'Native\\Laravel\\Events\\Windows\\WindowClosed',
284305
payload: [id]
285-
})
286-
})
306+
});
307+
});
287308

288309
// @ts-ignore
289310
window.on('hide', (evt) => {
290311
notifyLaravel('events', {
291312
event: 'Native\\Laravel\\Events\\Windows\\WindowHidden',
292313
payload: [id]
293-
})
294-
})
314+
});
315+
});
295316

296317
// Append the window id to the url
297-
url += (url.indexOf('?') === -1 ? '?' : '&') + '_windowId=' + id
318+
url += (url.indexOf('?') === -1 ? '?' : '&') + '_windowId=' + id;
298319

299-
window.loadURL(url)
320+
window.loadURL(url);
300321

301322
window.webContents.on('did-finish-load', () => {
302-
window.show()
303-
})
304-
state.windows[id] = window
323+
window.show();
324+
});
305325

306-
res.sendStatus(200)
307-
})
326+
state.windows[id] = window;
327+
328+
res.sendStatus(200);
329+
});
308330

309331
export default router;

0 commit comments

Comments
 (0)