-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.cjs
More file actions
67 lines (54 loc) · 1.47 KB
/
server.cjs
File metadata and controls
67 lines (54 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require('dotenv').config();
const path = require('path');
const {
app: App,
BrowserWindow,
ipcMain,
shell,
session
} = require('electron');
const express = require('express');
async function setup() {
const { handler } = await import('./build/handler.js');
const app = express();
const PORT = process.env.PORT ?? 3000;
app.use(handler);
app.listen(PORT);
const createWindow = () => {
const win = new BrowserWindow({
width: 1920,
height: 1080,
webPreferences: {
nodeIntegration: true,
preload: path.join(__dirname, 'preload.cjs')
},
frame: false
})
const handleWindow = ({ url }) => {
if (!url.includes('localhost')) {
shell.openExternal(url);
return { action: 'deny' };
}
}
session.defaultSession.cookies.on('change', () => session.defaultSession.cookies.flushStore());
win.webContents.setWindowOpenHandler(handleWindow);
win.loadURL(`http://localhost:${PORT}`);
}
App.whenReady().then(() => {
ipcMain.on('minimize', () => {
let curwindow = BrowserWindow.getFocusedWindow();
curwindow.minimize();
})
ipcMain.on('maximize', () => {
let curwindow = BrowserWindow.getFocusedWindow();
if(curwindow.isMaximized()) curwindow.unmaximize();
else curwindow.maximize();
})
ipcMain.on('close', () => {
let curwindow = BrowserWindow.getFocusedWindow();
curwindow.close();
})
createWindow()
})
}
setup();