|
|
@@ -221,11 +221,28 @@ ipcMain.on("setStoData", (event, message) => {
|
|
|
ipcMain.on("getStoData", (event, message) => {
|
|
|
event.returnValue = dataStor[message.key]
|
|
|
})
|
|
|
-
|
|
|
-let childWindowList = {}
|
|
|
+let maxWindowOpenNum = 10
|
|
|
+let nowWindowInd = 0
|
|
|
+let childWindowList = []
|
|
|
function randomString(n){const str = 'abcdefghijklmnopqrstuvwxyz9876543210';let tmp = '',i = 0,l = str.length;for (i = 0; i < n; i++) {tmp += str.charAt(Math.floor(Math.random() * l));}return tmp;}
|
|
|
ipcMain.on("openWindow", (event, message) => {
|
|
|
- let nowIndex = message.key ? message.key : randomString(6)
|
|
|
+ let nowIndex = nowWindowInd++
|
|
|
+ // 判断是否达到了最大窗口数量
|
|
|
+ let nowWindowNumTemp = 0
|
|
|
+ for (let index = 0; index < childWindowList.length; index++) {
|
|
|
+ const element = childWindowList[index];
|
|
|
+ if (element) nowWindowNumTemp++
|
|
|
+ }
|
|
|
+ if (nowWindowNumTemp > maxWindowOpenNum) {
|
|
|
+ for (let index = 0; index < childWindowList.length; index++) {
|
|
|
+ const element = childWindowList[index];
|
|
|
+ if (element) {
|
|
|
+ childWindowList[index].close()
|
|
|
+ childWindowList[index] = null
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 创建新窗口
|
|
|
childWindowList[nowIndex] = new BrowserWindow({
|
|
|
width: message.width || 800,
|
|
|
height: message.height || 600,
|
|
|
@@ -251,6 +268,7 @@ ipcMain.on("openWindow", (event, message) => {
|
|
|
|
|
|
ipcMain.on("closeWindow", (event, message) => {
|
|
|
if (message && message.key) {
|
|
|
+ message.key = parseInt(message.key)
|
|
|
setTimeout(() => {
|
|
|
if (childWindowList[message.key]) {
|
|
|
childWindowList[message.key].close()
|
|
|
@@ -259,19 +277,17 @@ ipcMain.on("closeWindow", (event, message) => {
|
|
|
}, message.time || 0);
|
|
|
|
|
|
} else {
|
|
|
- for (const key in childWindowList) {
|
|
|
- if (Object.hasOwnProperty.call(childWindowList, key)) {
|
|
|
- const element = childWindowList[key];
|
|
|
- if (element && element.close) {
|
|
|
- try {
|
|
|
- element.close()
|
|
|
- } catch (error) {
|
|
|
- console.log(error)
|
|
|
- }
|
|
|
+ for (let index = 0; index < childWindowList.length; index++) {
|
|
|
+ const element = childWindowList[index];
|
|
|
+ if (element && element.close) {
|
|
|
+ try {
|
|
|
+ element.close()
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- childWindowList = {}
|
|
|
+ childWindowList = []
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -281,19 +297,19 @@ ipcMain.on("closeWindow", (event, message) => {
|
|
|
|
|
|
ipcMain.on("changeProxy", (event, message) => {
|
|
|
if (message && message.key) {
|
|
|
+ message.key = parseInt(message.key)
|
|
|
childWindowList[message.key].webContents.session.setProxy({
|
|
|
proxyRules: "",
|
|
|
proxyBypassRules: ['localhost', "cunchu.site", "demos.run", "proxy.com"],
|
|
|
});
|
|
|
} else {
|
|
|
- for (const key in childWindowList) {
|
|
|
- if (Object.hasOwnProperty.call(childWindowList, key)) {
|
|
|
- if (element) {
|
|
|
- element.webContents.session.setProxy({
|
|
|
- proxyRules: "",
|
|
|
- proxyBypassRules: ['localhost', "cunchu.site", "demos.run", "proxy.com"],
|
|
|
- });
|
|
|
- }
|
|
|
+ for (let index = 0; index < childWindowList.length; index++) {
|
|
|
+ const element = childWindowList[index];
|
|
|
+ if (element) {
|
|
|
+ element.webContents.session.setProxy({
|
|
|
+ proxyRules: "",
|
|
|
+ proxyBypassRules: ['localhost', "cunchu.site", "demos.run", "proxy.com"],
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -316,6 +332,13 @@ ipcMain.on("saveConfig", (event, message) => {
|
|
|
event.returnValue = {err: 0}
|
|
|
})
|
|
|
|
|
|
+// 设置最大打开窗口数量
|
|
|
+ipcMain.on("setMaxWindowOpenNum", (event, message) => {
|
|
|
+ if (message.value) {
|
|
|
+ maxWindowOpenNum = parseInt(message.value)
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
ipcMain.on("readdir", (event, directoryPath) => {
|
|
|
fs.readdir(directoryPath, (err, files) => {
|
|
|
if (err) {
|