main.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. // Modules to control application life and create native browser window
  2. const {app, ipcMain, BrowserWindow, session} = require('electron')
  3. const path = require('path')
  4. const fs = require('fs')
  5. const request = require('request');
  6. const download = require('download');
  7. // 读取配置文件
  8. let enterURL = 'https://demos.run/debuger/index.html'
  9. let webConfig = {
  10. width: 376,
  11. height: 667,
  12. webPreferences: {
  13. webSecurity: false,
  14. contextIsolation: true,
  15. nodeIntegration: false,
  16. allowRunningInsecureContent: true, // 允许不安全内容
  17. plugins: true,
  18. scrollBounce: true,
  19. preload: path.join(__dirname, "preload.js")
  20. },
  21. autoHideMenuBar: true
  22. // 无边框
  23. // frame: false,
  24. // 全屏
  25. // fullscreen: true
  26. }
  27. // 判断是否有特殊配置文件
  28. console.log(__dirname + "\\config.json")
  29. if (fs.existsSync("./config.json")) {
  30. let configStr = fs.readFileSync('./config.json', 'utf-8')
  31. // 特殊符号表示运行目录
  32. configStr = configStr.replaceAll('<dir>', __dirname.replaceAll('\\', '/').replace('/resources/app.asar', ''))
  33. webConfig = JSON.parse(configStr)
  34. enterURL = webConfig.enterURL
  35. }
  36. console.log(webConfig)
  37. const codeMap = {"fc":"[re]","ep":"[Af]","rj":"[M_]","sp":"[sW]","ws":"[Pj]","mb":"[^~]","ww":"[Dp]","wh":"[ZH]","ph":"[b+]","hk":"[3b]","mc":"[%)]","fm":"[$4]","nm":"[T!]","ei":"[J3]","pd":"[(A]","ef":"[%t]","xf":"[n_]","na":"[W6]","mr":"[dn]","km":"[b*]","aw":"[#*]","sj":"[~6]","ry":"[t#]","sd":"[$R]","eh":"[!!]","wp":"[TE]","fy":"[s6]","ex":"[EE]","ce":"[PS]","xr":"[~z]","cj":"[xh]","am":"[(G]","kw":"[Nr]","hj":"[p@]","ia":"[jO]","mp":"[75]","py":"[6C]","hc":"[46]","sk":"[(8]","hp":"[SB]","my":"[pq]","wk":"[Xd]","bk":"[Q^]","ak":"[)J]","cw":"[ai]","ym":"[Te]","yh":"[Cd]","xb":"[R5]","yy":"[#H]","nt":"[4)]","bc":"[#J]","fe":"[2+]","ni":"[f@]","bb":"[!k]","jc":"[$Q]","an":"[m$]","ee":"[RH]","nn":"[n$]","jr":"[5F]","pp":"[JQ]","fx":"[86]","2":"[)h]","3":"[iL]","4":"[r2]","5":"[Ys]","6":"[7p]","7":"[!5]","8":"[@A]","A":"[_W]","B":"[Kt]","C":"[m#]","D":"[A!]","E":"[M!]","F":"[xG]","G":"[k@]","H":"[_!]","J":"[rP]","K":"[z#]","M":"[r$]","N":"[rN]","P":"[t$]","Q":"[3(]","R":"[fF]","S":"[H)]","T":"[J@]","W":"[83]","X":"[t5]","Y":"[T_]","Z":"[CT]","a":"[Jt]","b":"[Ks]","c":"[yn]","d":"[2r]","e":"[#2]","f":"[yM]","h":"[)m]","i":"[mx]","j":"[YV]","k":"[$j]","m":"[Xy]","n":"[Bk]","p":"[5$]","r":"[EH]","s":"[Pw]","t":"[j(]","w":"[p7]","x":"[a+]","y":"[B2]","z":"[4n]","~":"[~C]","!":"[iw]","@":"[SK]","#":"[Pf]","$":"[de]","%":"[3t]","^":"[H_]","&":"[WA]","*":"[!A]","(":"[z*]",")":"[)n]","_":"[&k]","+":"[*F]"}
  38. function owoReplaceAll(str, s1, s2) {
  39. while (str.indexOf(s1) >= 0) {
  40. str = str.replace(s1, s2)
  41. }
  42. return str
  43. }
  44. function owoDecode(itemStr) {
  45. for (let item in codeMap) {
  46. itemStr = owoReplaceAll(itemStr, codeMap[item], item)
  47. }
  48. while (itemStr.indexOf(']') >= 0) {
  49. itemStr = owoDecode(itemStr)
  50. }
  51. return itemStr
  52. }
  53. let mainWindow = null
  54. let preLoadCode = `
  55. var owoApp = 5
  56. window.owoPC = true
  57. window.electronConfig = ${JSON.stringify(webConfig)};
  58. function loadScript(url, callback) {
  59. var script = document.createElement("script")
  60. script.type = "text/javascript";
  61. if (script.readyState) { //IE
  62. script.onreadystatechange = function () {
  63. if (script.readyState == "loaded" || script.readyState == "complete") {
  64. script.onreadystatechange = null;
  65. if (callback) callback();
  66. }
  67. };
  68. } else { //Others
  69. script.onload = function () {
  70. if (callback) callback();
  71. };
  72. }
  73. script.src = url;
  74. var head = document.head || document.getElementsByTagName('head')[0];
  75. head.appendChild(script);
  76. }
  77. function loadJsCode(code){
  78. var script = document.createElement('script');
  79. script.type = 'text/javascript';
  80. //for Chrome Firefox Opera Safari
  81. script.appendChild(document.createTextNode(code));
  82. //for IE
  83. //script.text = code;
  84. document.body.appendChild(script);
  85. }
  86. function loadCSS (url) {
  87. var link = document.createElement("link");
  88. link.rel = "stylesheet";
  89. link.type = "text/css";
  90. link.href = url;
  91. document.getElementsByTagName("head")[0].appendChild(link);
  92. }
  93. loadScript('https://cunchu.site/app/main.js');
  94. `
  95. // 拦截数据
  96. // 拦截数据(获取请求和响应内容)
  97. function setupDebuggerInterceptor(webContents, interceptor) {
  98. webContents.debugger.attach('1.3');
  99. const pendingRequests = new Map();
  100. webContents.debugger.on('message', (event, method, params) => {
  101. // 存储请求信息
  102. if (method === 'Network.requestWillBeSent') {
  103. pendingRequests.set(params.requestId, {
  104. url: params.request.url,
  105. method: params.request.method,
  106. headers: params.request.headers,
  107. postData: params.request.postData,
  108. timestamp: Date.now()
  109. });
  110. }
  111. // 响应接收时记录信息
  112. if (method === 'Network.responseReceived') {
  113. const { requestId, response } = params;
  114. let hookData = false;
  115. interceptor.forEach(hookURL => {
  116. if (response.url.includes(hookURL) || response.url === hookURL) {
  117. hookData = true;
  118. }
  119. });
  120. if (hookData) {
  121. console.log('拦截到响应:', response.url, response.status);
  122. // 存储响应信息,等待 loadingFinished
  123. const requestInfo = pendingRequests.get(requestId) || {};
  124. pendingRequests.set(requestId, {
  125. ...requestInfo,
  126. responseReceived: true,
  127. response,
  128. hookData: true
  129. });
  130. }
  131. }
  132. // 在资源加载完成时获取响应体
  133. if (method === 'Network.loadingFinished') {
  134. const { requestId } = params;
  135. const requestInfo = pendingRequests.get(requestId);
  136. if (requestInfo && requestInfo.hookData) {
  137. // 延迟获取响应体,确保数据可用
  138. setTimeout(() => {
  139. webContents.debugger.sendCommand('Network.getResponseBody', { requestId })
  140. .then(({ body }) => {
  141. // 获取请求体(如果有)
  142. let requestBody = null;
  143. if (requestInfo.postData) {
  144. try {
  145. // 尝试解析为JSON,如果不是JSON则保持原样
  146. requestBody = JSON.parse(requestInfo.postData);
  147. } catch (e) {
  148. requestBody = requestInfo.postData;
  149. }
  150. }
  151. const interceptedData = {
  152. url: requestInfo.response.url,
  153. method: requestInfo.method,
  154. statusCode: requestInfo.response.status,
  155. requestHeaders: requestInfo.headers,
  156. requestBody: requestBody,
  157. responseBody: body,
  158. responseHeaders: requestInfo.response.headers,
  159. requestId: requestId,
  160. timestamp: requestInfo.timestamp
  161. };
  162. console.log('拦截到的完整数据:', interceptedData.url);
  163. console.log(interceptedData);
  164. if (mainWindow && !mainWindow.isDestroyed()) {
  165. mainWindow.webContents.executeJavaScript(`
  166. if (window.onInterceptedData) {
  167. window.onInterceptedData(${JSON.stringify(interceptedData)});
  168. }
  169. `).catch(console.error);
  170. }
  171. // 清理缓存
  172. pendingRequests.delete(requestId);
  173. })
  174. .catch(error => {
  175. console.warn(`无法获取响应体 ${requestInfo.response.url}:`, error.message);
  176. pendingRequests.delete(requestId);
  177. });
  178. }, 100); // 添加小延迟
  179. }
  180. }
  181. // 清理已完成或失败的请求
  182. if (method === 'Network.loadingFailed' || method === 'Network.requestServedFromCache') {
  183. const { requestId } = params;
  184. pendingRequests.delete(requestId);
  185. }
  186. });
  187. // 启用网络跟踪
  188. webContents.debugger.sendCommand('Network.enable');
  189. }
  190. function createWindow (partitionSession) {
  191. // console.log(webConfig)
  192. mainWindow = new BrowserWindow(webConfig)
  193. // 代理
  194. if (webConfig.proxy) {
  195. partitionSession.setProxy({
  196. proxyRules: webConfig.proxy,
  197. proxyBypassRules: 'localhost',
  198. }, function () {
  199. console.log('代理设置完毕')
  200. });
  201. }
  202. // 拦截到新窗口打开请求
  203. mainWindow.webContents.setWindowOpenHandler(({ url }) => {
  204. console.log('拦截到新窗口打开请求:', url);
  205. mainWindow.loadURL(url); // 当前窗口跳转
  206. return { action: 'deny' }; // 阻止 Electron 弹出窗口
  207. });
  208. if (enterURL.startsWith('http')) {
  209. mainWindow.loadURL(enterURL)
  210. } else {
  211. console.log(path.join(__dirname, enterURL))
  212. mainWindow.loadFile(enterURL)
  213. }
  214. if (webConfig.preLoadFile) {
  215. console.log(`Load additional JS: ${webConfig.preLoadFile}`)
  216. preLoadCode += fs.readFileSync(webConfig.preLoadFile, 'utf-8')
  217. }
  218. mainWindow.webContents.on("dom-ready", function() {
  219. mainWindow.webContents.executeJavaScript(preLoadCode);
  220. });
  221. // 只触发一次!
  222. mainWindow.webContents.once("did-finish-load", function() {
  223. if (webConfig.interceptor && webConfig.interceptor.length > 0) {
  224. console.log('Need to intercept data!')
  225. setupDebuggerInterceptor(mainWindow.webContents, webConfig.interceptor);
  226. }
  227. });
  228. // 打开新窗口触发
  229. mainWindow.webContents.on("did-create-window", function(neWindow) {
  230. neWindow.webContents.on("dom-ready", function() {
  231. neWindow.webContents.executeJavaScript(preLoadCode);
  232. });
  233. });
  234. }
  235. function setupCSPRemoval(ses) {
  236. ses.webRequest.onHeadersReceived((details, callback) => {
  237. const responseHeaders = details.responseHeaders || {};
  238. const cspHeaders = [
  239. 'content-security-policy',
  240. 'Content-Security-Policy',
  241. 'content-security-policy-report-only',
  242. 'x-content-security-policy',
  243. 'x-webkit-csp'
  244. ];
  245. cspHeaders.forEach(header => {
  246. if (responseHeaders[header]) {
  247. // console.log('Removing', header, 'from', details.url);
  248. delete responseHeaders[header];
  249. }
  250. });
  251. callback({ cancel: false, responseHeaders });
  252. });
  253. }
  254. // This method will be called when Electron has finished
  255. // initialization and is ready to create browser windows.
  256. // Some APIs can only be used after this event occurs.
  257. app.whenReady().then(() => {
  258. // 判断是否无缓存
  259. if (webConfig.noCache) {
  260. console.log('无缓存模式!')
  261. webConfig.webPreferences.partition = 'persist:Session' + Math.round(Math.random()*100000)
  262. } else {
  263. webConfig.webPreferences.partition = 'persist:owoApp'
  264. }
  265. // 去掉安全措施
  266. const partitionSession = session.fromPartition(webConfig.webPreferences.partition);
  267. setupCSPRemoval(partitionSession);
  268. createWindow(partitionSession)
  269. app.on('activate', function () {
  270. // On macOS it's common to re-create a window in the app when the
  271. // dock icon is clicked and there are no other windows open.
  272. if (BrowserWindow.getAllWindows().length === 0) createWindow(partitionSession)
  273. })
  274. })
  275. // Quit when all windows are closed, except on macOS. There, it's common
  276. // for applications and their menu bar to stay active until the user quits
  277. // explicitly with Cmd + Q.
  278. app.on('window-all-closed', function () {
  279. if (process.platform !== 'darwin') app.quit()
  280. })
  281. // In this file you can include the rest of your app's specific main process
  282. // code. You can also put them in separate files and require them here.
  283. ipcMain.on("getData", (event, message) => {
  284. // 控制台打印一下知道来了
  285. console.log(message);
  286. var options = {
  287. 'method': 'GET',
  288. 'url': owoDecode(message.url),
  289. 'headers': message.headers,
  290. strictSSL: false
  291. };
  292. request(options, function (error, response) {
  293. if (error) throw new Error(error);
  294. event.returnValue = response.body
  295. });
  296. })
  297. ipcMain.on("postData", (event, message) => {
  298. // 控制台打印一下知道来了
  299. console.log(message);
  300. var options = {
  301. 'method': 'POST',
  302. 'url': owoDecode(message.url),
  303. 'headers': message.headers,
  304. 'body': message.body,
  305. strictSSL: false
  306. };
  307. request(options, function (error, response) {
  308. if (error) throw new Error(error);
  309. event.returnValue = response.body
  310. });
  311. })
  312. ipcMain.on("setProxy", (event, message) => {
  313. var win = new BrowserWindow({width: 800, height: 1500});
  314. mainWindow.webContents.session.setProxy({
  315. proxyRules: message.url,
  316. proxyBypassRules: 'localhost',
  317. });
  318. event.returnValue = 'ok'
  319. })
  320. // 添加注入代码
  321. ipcMain.on("addPreLoadCode", (event, message) => {
  322. if (message.data) preLoadCode += message.data
  323. })
  324. // 通用保存数据
  325. let dataStor = {}
  326. ipcMain.on("setStoData", (event, message) => {
  327. dataStor[message.key] = message.value
  328. event.returnValue = '{"err":0}'
  329. })
  330. ipcMain.on("getStoData", (event, message) => {
  331. event.returnValue = dataStor[message.key]
  332. })
  333. let maxWindowOpenNum = 10
  334. let nowWindowInd = 0
  335. let childWindowList = []
  336. 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;}
  337. ipcMain.handle("openWindow", async (event, message) => {
  338. console.log(message)
  339. let nowIndex = nowWindowInd++
  340. // 判断是否达到了最大窗口数量
  341. let nowWindowNumTemp = 0
  342. for (let index = 0; index < childWindowList.length; index++) {
  343. const element = childWindowList[index];
  344. if (element) nowWindowNumTemp++
  345. }
  346. if (nowWindowNumTemp > maxWindowOpenNum) {
  347. for (let index = 0; index < childWindowList.length; index++) {
  348. const element = childWindowList[index];
  349. if (element) {
  350. childWindowList[index].close()
  351. childWindowList[index] = null
  352. }
  353. }
  354. }
  355. // 获取对应 session
  356. let partitionName = 'persist:owoAppChild'
  357. if (message.noCache) {
  358. partitionName = 'persist:Session' + Math.round(Math.random()*100000)
  359. }
  360. const customSession = session.fromPartition(partitionName);
  361. if (message.proxy) {
  362. // 设置代理(等待设置完成)
  363. await customSession.setProxy({
  364. proxyRules: message.proxy,
  365. proxyBypassRules: ['localhost', "cunchu.site", "demos.run", "proxy.com"],
  366. });
  367. }
  368. let childWindowPreferences = webConfig.webPreferences
  369. if (message.webPreferences) childWindowPreferences = message.webPreferences
  370. childWindowPreferences.partition = partitionName
  371. // 创建新窗口
  372. childWindowList[nowIndex] = new BrowserWindow({
  373. width: message.width || 800,
  374. height: message.height || 600,
  375. webPreferences: childWindowPreferences
  376. });
  377. // 判断是否静音
  378. if (message.muted) {
  379. // 设置静音
  380. childWindowList[nowIndex].webContents.setAudioMuted(true);
  381. }
  382. childWindowList[nowIndex].webContents.on("dom-ready", function() {
  383. console.log("dom-ready")
  384. childWindowList[nowIndex].webContents.executeJavaScript(preLoadCode);
  385. });
  386. childWindowList[nowIndex].on('closed', () => {
  387. childWindowList[nowIndex] = null;
  388. });
  389. // 拦截到新窗口打开请求
  390. childWindowList[nowIndex].webContents.setWindowOpenHandler(({ url }) => {
  391. console.log('拦截到新窗口打开请求:', url);
  392. childWindowList[nowIndex].loadURL(url); // 当前窗口跳转
  393. return { action: 'deny' }; // 阻止 Electron 弹出窗口
  394. });
  395. childWindowList[nowIndex].loadURL(message.url, {
  396. 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"
  397. });
  398. event.returnValue = JSON.stringify({"err":0,"key":nowIndex})
  399. })
  400. ipcMain.on("closeWindow", (event, message) => {
  401. if (message && message.key) {
  402. message.key = parseInt(message.key)
  403. setTimeout(() => {
  404. if (childWindowList[message.key]) {
  405. childWindowList[message.key].close()
  406. }
  407. setTimeout(() => {
  408. childWindowList[message.key] = null
  409. }, 0);
  410. }, message.time || 0);
  411. }
  412. event.returnValue = JSON.stringify({"err":0})
  413. })
  414. ipcMain.on("closeAllWindow", (event, message) => {
  415. for (let index = 0; index < childWindowList.length; index++) {
  416. const element = childWindowList[index];
  417. if (element && element.close) {
  418. try {
  419. element.close()
  420. } catch (error) {
  421. console.log(error)
  422. }
  423. }
  424. }
  425. setTimeout(() => {
  426. childWindowList = []
  427. }, 0);
  428. event.returnValue = JSON.stringify({"err":0})
  429. })
  430. ipcMain.on("changeProxy", (event, message) => {
  431. if (message && message.key) {
  432. message.key = parseInt(message.key)
  433. childWindowList[message.key].webContents.session.setProxy({
  434. proxyRules: "",
  435. proxyBypassRules: ['localhost', "cunchu.site", "demos.run", "proxy.com"],
  436. });
  437. } else {
  438. for (let index = 0; index < childWindowList.length; index++) {
  439. const element = childWindowList[index];
  440. if (element) {
  441. element.webContents.session.setProxy({
  442. proxyRules: "",
  443. proxyBypassRules: ['localhost', "cunchu.site", "demos.run", "proxy.com"],
  444. });
  445. }
  446. }
  447. }
  448. event.returnValue = JSON.stringify({"err":0})
  449. })
  450. ipcMain.on("readConfig", (event, message) => {
  451. if (fs.existsSync("./config.json")) {
  452. event.returnValue = JSON.parse(fs.readFileSync('./config.json', 'utf-8'))
  453. } else {
  454. event.returnValue = {}
  455. }
  456. })
  457. ipcMain.handle("saveFile", async (event, message) => {
  458. try {
  459. // 确保download目录存在
  460. const downloadDir = path.join(__dirname.replaceAll('\\', '/').replace('/resources/app.asar', ''), 'download');
  461. if (!fs.existsSync(downloadDir)) {
  462. fs.mkdirSync(downloadDir, { recursive: true });
  463. console.log('创建download目录:', downloadDir);
  464. }
  465. // 构建完整的文件路径
  466. const filePath = path.join(downloadDir, message.filename);
  467. // 添加UTF-8 BOM头并保存文件
  468. const contentWithBOM = '\uFEFF' + message.content;
  469. fs.writeFileSync(filePath, contentWithBOM, 'utf8');
  470. console.log('文件保存成功:', filePath);
  471. return { success: true, path: filePath };
  472. } catch (error) {
  473. console.error('保存文件失败:', error);
  474. return { success: false, error: error.message };
  475. }
  476. });
  477. ipcMain.handle("readFile", async (event, message) => {
  478. try {
  479. // 确保download目录存在
  480. const downloadDir = path.join(__dirname.replaceAll('\\', '/').replace('/resources/app.asar', ''), 'download');
  481. if (!fs.existsSync(downloadDir)) {
  482. fs.mkdirSync(downloadDir, { recursive: true });
  483. console.log('创建download目录:', downloadDir);
  484. }
  485. // 构建完整的文件路径
  486. const filePath = path.join(downloadDir, message.filename);
  487. // 检查文件是否存在
  488. if (!fs.existsSync(filePath)) {
  489. console.log('文件不存在,返回空内容:', filePath);
  490. return { success: true, content: '', exists: false };
  491. }
  492. // 读取文件内容
  493. const content = fs.readFileSync(filePath, message.encoding ? message.encoding : 'utf8');
  494. // 移除UTF-8 BOM头(如果存在)
  495. let processedContent = content;
  496. if (content.charCodeAt(0) === 0xFEFF) {
  497. processedContent = content.slice(1);
  498. }
  499. console.log('文件读取成功:', filePath);
  500. return { success: true, content: processedContent, exists: true };
  501. } catch (error) {
  502. console.error('读取文件失败:', error);
  503. return { success: false, error: error.message, exists: false };
  504. }
  505. });
  506. ipcMain.on("saveConfig", (event, message) => {
  507. fs.writeFileSync('./config.json', JSON.stringify(message))
  508. event.returnValue = {err: 0}
  509. })
  510. // 设置最大打开窗口数量
  511. ipcMain.on("setMaxWindowOpenNum", (event, message) => {
  512. if (message.value) {
  513. maxWindowOpenNum = parseInt(message.value)
  514. }
  515. })
  516. ipcMain.on("readdir", (event, directoryPath) => {
  517. fs.readdir(directoryPath, (err, files) => {
  518. if (err) {
  519. event.returnValue = {err: 1, "msg": 'Error reading directory:' + err}
  520. return;
  521. }
  522. event.returnValue = {err: 0, files}
  523. });
  524. })
  525. ipcMain.on("download", (event, message) => {
  526. download(message.url, message.path, {
  527. filename: message.filename,
  528. });
  529. event.returnValue = {err: 0}
  530. })
  531. // 窗口间通信
  532. ipcMain.on('broadcast-message', (event, message) => {
  533. // 获取发送者
  534. console.log(message)
  535. mainWindow.send('message-broadcast', message);
  536. // 广播给所有其他窗口
  537. for (const win of childWindowList) {
  538. if (win && !win.isDestroyed()) win.webContents.send('message-broadcast', message);
  539. }
  540. });