-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
85 lines (79 loc) · 1.79 KB
/
main.js
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const { app, BrowserWindow, Menu, Tray } = require("electron");
const { createProxyMiddleware } = require("http-proxy-middleware");
const cors = require("cors");
const app1 = require("express")();
const path = require("path");
let win = null;
function createWindow() {
win = new BrowserWindow({
width: 300,
height: 200,
resizable: false,
autoHideMenuBar: true,
skipTaskbar: true,
icon: path.join(__dirname, "./favicon.ico"),
webPreferences: {
nodeIntegration: true,
},
});
win.loadFile("index.html");
//实现点击关闭按钮让应用保存在托盘里面 ,双击托盘打开应用
win.on("close", (e) => {
if (!win.isFocused()) {
win = null;
} else {
e.preventDefault(); //阻止窗口的关闭事件
win.hide();
}
});
}
let tray = null;
function createTray() {
tray = new Tray(path.join(__dirname, "./favicon.ico"));
const contextMenu = Menu.buildFromTemplate([
{
label: "退出",
click: function () {
app.quit();
},
},
]);
tray.setToolTip("Chrome浏览器插件");
tray.setContextMenu(contextMenu);
//监听任务栏图标的点击事件
tray.on("double-click", function () {
win.show();
});
}
app
.whenReady()
.then(createWindow)
.then(createTray)
.catch((err) => {
console.log(err);
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
app1.use(cors());
const proxy = {
target: "http://0.0.0.0:19196",
port: 62351,
};
app1.all(
"/*",
createProxyMiddleware({
target: proxy.target,
changeOrigin: true,
})
);
app1.listen(proxy.port, () => {
console.log("listen http://0.0.0.0:" + proxy.port);
});