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