Эх сурвалжийг харах

修复子窗口代理问题

PUGE 8 сар өмнө
parent
commit
dd588d3043
3 өөрчлөгдсөн 30 нэмэгдсэн , 20 устгасан
  1. 1 1
      config.json
  2. 14 6
      index.html
  3. 15 13
      main.js

+ 1 - 1
config.json

@@ -14,5 +14,5 @@
     "redirect":[],
     "redirectURL":"",
     "proxy":"",
-    "noCache": false
+    "noCache": true
 }

+ 14 - 6
index.html

@@ -26,7 +26,7 @@
 <body>
   <div class="box owo">
     <h4>网址</h4>
-    <input type="text" id="wangzhan" value="https://sexkk01.xyz" stored="">
+    <input type="text" id="wangzhan" value="https://www.ip138.com/" stored="">
     <h4>代理地址</h4>
     <input type="text" id="dldz" value="http://api.tianqiip.com/getip?secret=8nieqg3rpcg2ml08&num=1&type=txt&port=1&time=3&mr=1&sign=73a2f344b40ba112a9625e589751c19a" stored="">
     <h4>停留时间(秒)</h4>
@@ -34,7 +34,7 @@
     <h4>循环间隔(秒)</h4>
     <input type="number" id="xhjg" value="30" stored="">
     <h4>浏览器身份</h4>
-    <textarea id="ua">userAgent: message.userAgent ? message.userAgent : "Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1</textarea>
+    <textarea id="ua">Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1</textarea>
     <div class="owo button" onclick="window.running=true;start()">启动</div>
     <div class="owo button" onclick="window.running=false;">停止</div>
     <div id="xsxx"></div>
@@ -52,17 +52,25 @@
         .then((dldz) => {
             console.log(dldz)
             window.xsxx.innerText = `获取到代理:${dldz}`
+            window.dldzSet = dldz
+            window.dldzSet = window.dldzSet.replaceAll('\r', '').replaceAll('\n', '')
             window.electronAPI.openWindow({
+                "width": 350,
+                "height": 700,
                 "url": window.wangzhan.value,
-                "proxy": "49.85.115.54:40045",
-                "userAgent": window.ua.value
+                "proxy": `http=${window.dldzSet};https=${window.dldzSet}`,
+                "userAgent": window.ua.value,
+                "noCache": false
             })
             setTimeout(() => {
-                window.electronAPI.closeAllWindow()
+              window.electronAPI.closeAllWindow()
+            }, parseInt(window.tljg.value) * 1000);
+            setTimeout(() => {
+                
                 if (window.running) {
                     start()
                 }
-            }, parseInt(window.xhjg.value) * 1000);
+            }, (parseInt(window.xhjg.value) + parseInt(window.tljg.value)) * 1000);
             
         })
         .catch((error) => console.error(error));

+ 15 - 13
main.js

@@ -259,27 +259,29 @@ ipcMain.handle("openWindow", async (event, message) => {
       }
     }
   }
-  // 创建新窗口
-  childWindowList[nowIndex] = new BrowserWindow({
-    width: message.width || 800,
-    height: message.height || 600,
-    webPreferences: webConfig.webPreferences
-  });
   
+  // 获取对应 session
+  let partitionName = 'persist:owoApp'
+  if (message.noCache) {
+    partitionName = 'persist:Session' + Math.round(Math.random()*100000)
+  }
+  const customSession = session.fromPartition(partitionName);
   if (message.proxy) {
-    // 获取对应 session
-    let partitionName = 'persist:owoApp'
-    if (webConfig.noCache) {
-      partitionName = 'persist:Session' + Math.round(Math.random()*100000)
-    }
-    const customSession = session.fromPartition(partitionName);
-    
     // 设置代理(等待设置完成)
     await customSession.setProxy({
       proxyRules: message.proxy,
       proxyBypassRules: ['localhost', "cunchu.site", "demos.run", "proxy.com"],
     });
   }
+  let childWindowPreferences = webConfig.webPreferences
+  if (message.webPreferences) childWindowPreferences = message.webPreferences
+  childWindowPreferences.partition = partitionName
+  // 创建新窗口
+  childWindowList[nowIndex] = new BrowserWindow({
+    width: message.width || 800,
+    height: message.height || 600,
+    webPreferences: childWindowPreferences
+  });
   // 判断是否静音
   if (message.muted) {
     // 设置静音