main.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. // Modules to control application life and create native browser window
  2. const {app, BrowserWindow, dialog, ipcMain, screen, session} = require('electron');
  3. app.commandLine.appendSwitch("--disable-http-cache");
  4. const {Builder, By, Key, until} = require("selenium-webdriver");
  5. const chrome = require('selenium-webdriver/chrome');
  6. const {ServiceBuilder} = require('selenium-webdriver/chrome');
  7. const {rootCertificates} = require('tls');
  8. const {exit} = require('process');
  9. const path = require('path');
  10. const fs = require('fs');
  11. const {exec, spawn} = require('child_process');
  12. const iconPath = path.join(__dirname, 'favicon.ico');
  13. const task_server = require(path.join(__dirname, 'server.js'));
  14. const util = require('util');
  15. let config = fs.readFileSync(path.join(task_server.getDir(), `config.json`), 'utf8');
  16. config = JSON.parse(config);
  17. if(config.debug){
  18. let logPath = 'info.log'
  19. let logFile = fs.createWriteStream(logPath, { flags: 'a' })
  20. console.log = function() {
  21. logFile.write(util.format.apply(null, arguments) + '\n')
  22. process.stdout.write(util.format.apply(null, arguments) + '\n')
  23. }
  24. console.error = function() {
  25. logFile.write(util.format.apply(null, arguments) + '\n')
  26. process.stderr.write(util.format.apply(null, arguments) + '\n')
  27. }
  28. }
  29. let allWindowSockets = [];
  30. let allWindowScoketNames = [];
  31. task_server.start(config.webserver_port); //start local server
  32. let server_address = `${config.webserver_address}:${config.webserver_port}`;
  33. const websocket_port = 8084; //目前只支持8084端口,写死,因为扩展里面写死了
  34. console.log("server_address: " + server_address);
  35. let driverPath = "";
  36. let chromeBinaryPath = "";
  37. let execute_path = "";
  38. console.log(process.arch);
  39. exec(`wmic os get Caption`, function(error, stdout, stderr) {
  40. if (error) {
  41. console.error(`执行的错误: ${error}`);
  42. return;
  43. }
  44. if (stdout.includes('Windows 7')) {
  45. console.log('Windows 7');
  46. let sys_arch = config.sys_arch;
  47. if (sys_arch === 'x64') {
  48. dialog.showMessageBoxSync({
  49. type: 'error',
  50. title: 'Error',
  51. message: 'Windows 7系统请下载使用x32版本的软件,不论Win 7系统为x64还是x32版本。\nFor Windows 7, please download and use the x32 version of the software, regardless of whether the Win 7 system is x64 or x32 version.',
  52. });
  53. }
  54. } else {
  55. console.log('Not Windows 7');
  56. }
  57. });
  58. if (process.platform === 'win32' && process.arch === 'ia32') {
  59. driverPath = path.join(__dirname, "chrome_win32/chromedriver_win32.exe");
  60. chromeBinaryPath = path.join(__dirname, "chrome_win32/chrome.exe");
  61. execute_path = path.join(__dirname, "chrome_win32/execute.bat");
  62. } else if (process.platform === 'win32' && process.arch === 'x64') {
  63. driverPath = path.join(__dirname, "chrome_win64/chromedriver_win64.exe");
  64. chromeBinaryPath = path.join(__dirname, "chrome_win64/chrome.exe");
  65. execute_path = path.join(__dirname, "chrome_win64/execute.bat");
  66. } else if (process.platform === 'darwin') {
  67. driverPath = path.join(__dirname, "chromedriver_mac64");
  68. chromeBinaryPath = path.join(__dirname, "chrome_mac64.app/Contents/MacOS/Google Chrome");
  69. execute_path = path.join(__dirname, "");
  70. } else if (process.platform === 'linux') {
  71. driverPath = path.join(__dirname, "chrome_linux64/chromedriver_linux64");
  72. chromeBinaryPath = path.join(__dirname, "chrome_linux64/chrome");
  73. execute_path = path.join(__dirname, "chrome_linux64/execute.sh");
  74. }
  75. console.log(driverPath, chromeBinaryPath, execute_path);
  76. let language = "en";
  77. let driver = null;
  78. let mainWindow = null;
  79. let flowchart_window = null;
  80. let current_handle = null;
  81. let old_handles = [];
  82. let handle_pairs = {};
  83. let socket_window = null;
  84. let socket_start = null;
  85. let socket_flowchart = null;
  86. let invoke_window = null;
  87. // var ffi = require('ffi-napi');
  88. // var libm = ffi.Library('libm', {
  89. // 'ceil': [ 'double', [ 'double' ] ]
  90. // });
  91. // libm.ceil(1.5); // 2
  92. // const {user32FindWindowEx,
  93. // winspoolGetDefaultPrinter,} = require('win32-api/fun');
  94. // async function testt(){
  95. // // 获取当前电脑当前用户默认打印机名
  96. // const printerName = await winspoolGetDefaultPrinter()
  97. // console.log(printerName);
  98. // }
  99. // testt();
  100. function createWindow() {
  101. // Create the browser window.
  102. mainWindow = new BrowserWindow({
  103. width: 550,
  104. height: 750,
  105. webPreferences: {
  106. preload: path.join(__dirname, 'src/js/preload.js')
  107. },
  108. icon: iconPath,
  109. // frame: false, //取消window自带的关闭最小化等
  110. resizable: false //禁止改变主窗口尺寸
  111. })
  112. // and load the index.html of the app.
  113. // mainWindow.loadFile('src/index.html');
  114. mainWindow.loadURL(server_address + '/index.html?user_data_folder=' + config.user_data_folder+"&copyright=" + config.copyright, { extraHeaders: 'pragma: no-cache\n' });
  115. // 隐藏菜单栏
  116. const {Menu} = require('electron');
  117. Menu.setApplicationMenu(null);
  118. mainWindow.on('close', function (e) {
  119. if (process.platform !== 'darwin') {
  120. app.quit();
  121. }
  122. });
  123. // mainWindow.webContents.openDevTools();
  124. // Open the DevTools.
  125. // mainWindow.webContents.openDevTools()
  126. }
  127. async function beginInvoke(msg, ws) {
  128. if (msg.type == 1) {
  129. if (msg.message.id != -1) {
  130. let url = "";
  131. if (language == "zh") {
  132. url = server_address + `/taskGrid/FlowChart_CN.html?id=${msg.message.id}&wsport=${websocket_port}&backEndAddressServiceWrapper=` + server_address;
  133. } else if (language == "en") {
  134. url = server_address + `/taskGrid/FlowChart.html?id=${msg.message.id}&wsport=${websocket_port}&backEndAddressServiceWrapper=` + server_address;
  135. }
  136. console.log(url);
  137. flowchart_window.loadURL(url, { extraHeaders: 'pragma: no-cache\n' });
  138. }
  139. mainWindow.hide();
  140. // Prints the currently focused window bounds.
  141. // This method has to be called on macOS before changing the window's bounds, otherwise it will throw an error.
  142. // It will prompt an accessibility permission request dialog, if needed.
  143. if(process.platform != "linux" && process.platform != "darwin"){
  144. const {windowManager} = require("node-window-manager");
  145. const window = windowManager.getActiveWindow();
  146. console.log(window);
  147. windowManager.requestAccessibility();
  148. // Sets the active window's bounds.
  149. let size = screen.getPrimaryDisplay().workAreaSize
  150. let width = parseInt(size.width)
  151. let height = parseInt(size.height * 0.6)
  152. window.setBounds({x: 0, y: size.height * 0.4, height: height, width: width});
  153. }
  154. flowchart_window.show();
  155. // flowchart_window.openDevTools();
  156. } else if (msg.type == 2) {
  157. // 键盘输入事件
  158. // const robot = require("@jitsi/robotjs");
  159. let keyInfo = msg.message.keyboardStr;
  160. let handles = await driver.getAllWindowHandles();
  161. console.log("handles", handles);
  162. let exit = false;
  163. let content_handle = handle_pairs[msg.message.id];
  164. console.log(msg.message.id, content_handle);
  165. let order = [...handles.filter(handle => handle != current_handle && handle != content_handle), current_handle, content_handle]; //搜索顺序
  166. let len = order.length;
  167. while (true) {
  168. // console.log("handles");
  169. try{
  170. let iframe = msg.message.iframe;
  171. let enter = false;
  172. if (/<enter>/i.test(keyInfo)) {
  173. keyInfo = keyInfo.replace(/<enter>/gi, '');
  174. enter = true;
  175. }
  176. let h = order[len - 1];
  177. console.log("current_handle", current_handle);
  178. if(h != null && handles.includes(h)){
  179. await driver.switchTo().window(h);
  180. current_handle = h;
  181. console.log("switch to handle: ", h);
  182. }
  183. // await driver.executeScript("window.stop();");
  184. // console.log("executeScript");
  185. if(!iframe){
  186. let element = await driver.findElement(By.xpath(msg.message.xpath));
  187. console.log("Find Element at handle: ", current_handle);
  188. // 使用正则表达式匹配 '<enter>',不论大小写
  189. await element.sendKeys(Key.HOME, Key.chord(Key.SHIFT, Key.END), keyInfo);
  190. if(enter){
  191. await element.sendKeys(Key.ENTER);
  192. }
  193. console.log("send key");
  194. break;
  195. } else {
  196. let iframes = await driver.findElements(By.tagName('iframe'));
  197. // 遍历所有的 iframe 并点击里面的元素
  198. for(let i = 0; i < iframes.length; i++) {
  199. let iframe = iframes[i];
  200. // 切换到 iframe
  201. await driver.switchTo().frame(iframe);
  202. // 在 iframe 中查找并点击元素
  203. let element;
  204. try {
  205. element = await driver.findElement(By.xpath(msg.message.xpath));
  206. } catch (error) {
  207. console.log('No such element found in the iframe');
  208. }
  209. if (element) {
  210. await element.sendKeys(Key.HOME, Key.chord(Key.SHIFT, Key.END), keyInfo);
  211. if(enter){
  212. await element.sendKeys(Key.ENTER);
  213. }
  214. }
  215. // 完成操作后切回主文档
  216. await driver.switchTo().defaultContent();
  217. }
  218. break;
  219. }
  220. } catch (error) {
  221. console.log("len", len);
  222. len = len - 1;
  223. if (len == 0) {
  224. break;
  225. }
  226. }
  227. }
  228. } else if (msg.type == 3) {
  229. try {
  230. if (msg.from == 0) {
  231. socket_flowchart.send(msg.message.pipe); //直接把消息转接
  232. let message = JSON.parse(msg.message.pipe);
  233. let type = message.type;
  234. console.log("FROM Browser: ", message);
  235. console.log("Iframe:", message.iframe);
  236. if(type.indexOf("Click")>=0){
  237. // 鼠标点击事件
  238. let iframe = message.iframe;
  239. let handles = await driver.getAllWindowHandles();
  240. console.log("handles", handles);
  241. let exit = false;
  242. let content_handle = handle_pairs[message.id];
  243. console.log(message.id, content_handle);
  244. let order = [...handles.filter(handle => handle != current_handle && handle != content_handle), current_handle, content_handle]; //搜索顺序
  245. let len = order.length;
  246. while(true) {
  247. try{
  248. let h = order[len - 1];
  249. console.log("current_handle", current_handle);
  250. if(h != null && handles.includes(h)){
  251. await driver.switchTo().window(h); //执行失败会抛出异常
  252. current_handle = h;
  253. console.log("switch to handle: ", h);
  254. }
  255. //下面是找到窗口的情况下
  256. if(!iframe){
  257. let element = await driver.findElement(By.xpath(message.xpath));
  258. await element.click();
  259. break;
  260. } else {
  261. let iframes = await driver.findElements(By.tagName('iframe'));
  262. // 遍历所有的 iframe 并点击里面的元素
  263. for(let i = 0; i < iframes.length; i++) {
  264. let iframe = iframes[i];
  265. // 切换到 iframe
  266. await driver.switchTo().frame(iframe);
  267. // 在 iframe 中查找并点击元素
  268. let element;
  269. try {
  270. element = await driver.findElement(By.xpath(message.xpath));
  271. } catch (error) {
  272. console.log('No such element found in the iframe');
  273. }
  274. if (element) {
  275. await element.click();
  276. }
  277. // 完成操作后切回主文档
  278. await driver.switchTo().defaultContent();
  279. }
  280. break;
  281. }
  282. } catch (error) {
  283. console.log("len", len); //如果没有找到元素,就切换到下一个窗口
  284. len = len - 1;
  285. if (len == 0) {
  286. break;
  287. }
  288. }
  289. }
  290. }
  291. } else {
  292. socket_window.send(msg.message.pipe);
  293. for(let i in allWindowSockets){
  294. try{
  295. allWindowSockets[i].send(msg.message.pipe);
  296. } catch {
  297. console.log("Cannot send to socket with id: ", allWindowScoketNames[i]);
  298. }
  299. }
  300. console.log("FROM Flowchart: ", JSON.parse(msg.message.pipe));
  301. }
  302. } catch (e) {
  303. console.log(e);
  304. }
  305. } else if (msg.type == 5) {
  306. let child = require('child_process').execFile;
  307. // 参数顺序: 1. task id 2. server address 3. saved_file_name 4. "remote" or "local" 5. user_data_folder
  308. // var parameters = [msg.message.id, server_address];
  309. let parameters = [];
  310. console.log(msg.message)
  311. if (msg.message.user_data_folder == null || msg.message.user_data_folder == undefined || msg.message.user_data_folder == "") {
  312. parameters = ["--id", "[" + msg.message.id + "]", "--server_address", server_address, "--user_data", 0];
  313. } else {
  314. let user_data_folder_path = path.join(task_server.getDir(), msg.message.user_data_folder);
  315. parameters = ["--id", "[" + msg.message.id + "]", "--server_address", server_address, "--user_data", 1];
  316. config.user_data_folder = msg.message.user_data_folder;
  317. config.absolute_user_data_folder = user_data_folder_path;
  318. fs.writeFileSync(path.join(task_server.getDir(), "config.json"), JSON.stringify(config));
  319. }
  320. if(msg.message.mysql_config_path != "-1"){
  321. config.mysql_config_path = msg.message.mysql_config_path;
  322. }
  323. fs.writeFileSync(path.join(task_server.getDir(), "config.json"), JSON.stringify(config));
  324. // child('Chrome/easyspider_executestage.exe', parameters, function(err,stdout, stderr) {
  325. // console.log(stdout);
  326. // });
  327. let spawn = require("child_process").spawn;
  328. if (process.platform != "darwin" && msg.message.execute_type == 1 && msg.message.id != -1) {
  329. let child_process = spawn(execute_path, parameters);
  330. child_process.stdout.on('data', function (data) {
  331. console.log(data.toString());
  332. });
  333. }
  334. ws.send(JSON.stringify({"config_folder": task_server.getDir() + "/", "easyspider_location": task_server.getEasySpiderLocation()}));
  335. } else if (msg.type == 6) {
  336. try{
  337. flowchart_window.openDevTools();
  338. } catch {
  339. console.log("open devtools error");
  340. }
  341. try{
  342. invoke_window.openDevTools();
  343. } catch {
  344. console.log("open devtools error");
  345. }
  346. } else if (msg.type == 7) {
  347. // 获得当前页面Cookies
  348. try{
  349. let cookies = await driver.manage().getCookies();
  350. console.log("Cookies: ", cookies);
  351. let cookiesText = cookies.map(cookie => `${cookie.name}=${cookie.value}`).join('\n');
  352. socket_flowchart.send(JSON.stringify({"type": "GetCookies", "message": cookiesText}));
  353. } catch {
  354. console.log("Cannot get Cookies");
  355. }
  356. }
  357. }
  358. const WebSocket = require('ws');
  359. const {all} = require("express/lib/application");
  360. let wss = new WebSocket.Server({port: websocket_port});
  361. wss.on('connection', function (ws) {
  362. ws.on('message', async function (message, isBinary) {
  363. let msg = JSON.parse(message.toString());
  364. console.log("\n\nGET A MESSAGE: ", msg);
  365. // console.log(msg, msg.type, msg.message);
  366. if (msg.type == 0) {
  367. if (msg.message.id == 0) {
  368. socket_window = ws;
  369. console.log("set socket_window")
  370. } else if (msg.message.id == 1) {
  371. socket_start = ws;
  372. console.log("set socket_start")
  373. } else if (msg.message.id == 2) {
  374. socket_flowchart = ws;
  375. console.log("set socket_flowchart");
  376. } else { //其他的ID是用来标识不同的浏览器标签页的
  377. await new Promise(resolve => setTimeout(resolve, 2300));
  378. let handles = await driver.getAllWindowHandles();
  379. if(arrayDifference(handles, old_handles).length > 0){
  380. old_handles = handles;
  381. current_handle = handles[handles.length - 1];
  382. console.log("New tab opened, change current_handle to: ", current_handle);
  383. }
  384. handle_pairs[msg.message.id] = current_handle;
  385. console.log("Set handle_pair for id: ", msg.message.id, " to ", current_handle, ", title is: ", msg.message.title);
  386. socket_flowchart.send(JSON.stringify({"type": "title", "data": {"title":msg.message.title}}));
  387. allWindowSockets.push(ws);
  388. allWindowScoketNames.push(msg.message.id);
  389. // console.log("handle_pairs: ", handle_pairs);
  390. }
  391. } else if (msg.type == 10) {
  392. let leave_handle = handle_pairs[msg.message.id];
  393. if (leave_handle!=null && leave_handle!=undefined && leave_handle!="")
  394. {
  395. await driver.switchTo().window(leave_handle);
  396. console.log("Switch to handle: ", leave_handle);
  397. current_handle = leave_handle;
  398. }
  399. }
  400. else {
  401. await beginInvoke(msg, ws);
  402. }
  403. });
  404. });
  405. console.log(process.platform);
  406. async function runBrowser(lang = "en", user_data_folder = '', mobile = false) {
  407. const serviceBuilder = new ServiceBuilder(driverPath);
  408. let options = new chrome.Options();
  409. options.addArguments('--disable-blink-features=AutomationControlled');
  410. language = lang;
  411. if (lang == "en") {
  412. options.addExtensions(path.join(__dirname, "EasySpider_en.crx"));
  413. } else if (lang == "zh") {
  414. options.addExtensions(path.join(__dirname, "EasySpider_zh.crx"));
  415. }
  416. options.addExtensions(path.join(__dirname, "XPathHelper.crx"));
  417. options.setChromeBinaryPath(chromeBinaryPath);
  418. if (user_data_folder != "") {
  419. let dir = path.join(task_server.getDir(), user_data_folder);
  420. console.log(dir);
  421. options.addArguments("--user-data-dir=" + dir);
  422. config.user_data_folder = user_data_folder;
  423. fs.writeFileSync(path.join(task_server.getDir(), "config.json"), JSON.stringify(config));
  424. }
  425. if (mobile) {
  426. const mobileEmulation = {
  427. deviceName: 'iPhone XR'
  428. };
  429. options.addArguments(`--user-agent="Mozilla/5.0 (iPhone; CPU iPhone OS 13_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"`);
  430. options.setMobileEmulation(mobileEmulation);
  431. }
  432. driver = new Builder()
  433. .forBrowser('chrome')
  434. .setChromeOptions(options)
  435. .setChromeService(serviceBuilder)
  436. .build();
  437. await driver.manage().setTimeouts({implicit: 10000, pageLoad: 10000, script: 10000});
  438. await driver.executeScript("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})");
  439. // await driver.executeScript("localStorage.clear();"); //重置参数数量
  440. const cdpConnection = await driver.createCDPConnection("page");
  441. let stealth_path = path.join(__dirname, "stealth.min.js");
  442. let stealth = fs.readFileSync(stealth_path, 'utf8');
  443. await cdpConnection.execute('Page.addScriptToEvaluateOnNewDocument', {
  444. source: stealth,
  445. });
  446. try {
  447. if(mobile){
  448. await driver.get(server_address + "/taskGrid/taskList.html?wsport=" + websocket_port + "&backEndAddressServiceWrapper=" + server_address + "&mobile=1&lang=" + lang);
  449. } else {
  450. await driver.get(server_address + "/taskGrid/taskList.html?wsport=" + websocket_port + "&backEndAddressServiceWrapper=" + server_address + "&lang=" + lang);
  451. }
  452. old_handles = await driver.getAllWindowHandles();
  453. current_handle = old_handles[old_handles.length - 1];
  454. } finally {
  455. // await driver.quit(); // 退出浏览器
  456. }
  457. }
  458. function handleOpenBrowser(event, lang = "en", user_data_folder = "", mobile = false) {
  459. const webContents = event.sender;
  460. const win = BrowserWindow.fromWebContents(webContents);
  461. runBrowser(lang, user_data_folder, mobile);
  462. let size = screen.getPrimaryDisplay().workAreaSize;
  463. let width = parseInt(size.width);
  464. let height = parseInt(size.height * 0.6);
  465. flowchart_window = new BrowserWindow({
  466. x: 0,
  467. y: 0,
  468. width: width,
  469. height: height,
  470. icon: iconPath,
  471. });
  472. let url = "";
  473. let id = -1;
  474. if (lang == "en") {
  475. url = server_address + `/taskGrid/FlowChart.html?id=${id}&wsport=${websocket_port}&backEndAddressServiceWrapper=` + server_address + "&mobile=" + mobile.toString();
  476. } else if (lang == "zh") {
  477. url = server_address + `/taskGrid/FlowChart_CN.html?id=${id}&wsport=${websocket_port}&backEndAddressServiceWrapper=` + server_address+ "&mobile=" + mobile.toString();
  478. }
  479. // and load the index.html of the app.
  480. flowchart_window.loadURL(url, { extraHeaders: 'pragma: no-cache\n' });
  481. if(process.platform != "darwin"){
  482. flowchart_window.hide();
  483. }
  484. flowchart_window.on('close', function (event) {
  485. mainWindow.show();
  486. driver.quit();
  487. });
  488. }
  489. function handleOpenInvoke(event, lang = "en") {
  490. invoke_window = new BrowserWindow({icon: iconPath});
  491. let url = "";
  492. language = lang;
  493. if (lang == "en") {
  494. url = server_address + `/taskGrid/taskList.html?type=1&wsport=${websocket_port}&backEndAddressServiceWrapper=` + server_address;
  495. } else if (lang == "zh") {
  496. url = server_address + `/taskGrid/taskList.html?type=1&wsport=${websocket_port}&backEndAddressServiceWrapper=` + server_address + "&lang=zh";
  497. }
  498. // and load the index.html of the app.
  499. invoke_window.loadURL(url, { extraHeaders: 'pragma: no-cache\n' });
  500. invoke_window.maximize();
  501. mainWindow.hide();
  502. invoke_window.on('close', function (event) {
  503. mainWindow.show();
  504. });
  505. }
  506. // This method will be called when Electron has finished
  507. // initialization and is ready to create browser windows.
  508. // Some APIs can only be used after this event occurs.
  509. app.whenReady().then(() => {
  510. session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
  511. details.requestHeaders['Accept-Language'] = 'zh'
  512. callback({ cancel: false, requestHeaders: details.requestHeaders })
  513. })
  514. ipcMain.on('start-design', handleOpenBrowser);
  515. ipcMain.on('start-invoke', handleOpenInvoke);
  516. ipcMain.on('accept-agreement', function (event, arg) {
  517. config.copyright = 1;
  518. fs.writeFileSync(path.join(task_server.getDir(), "config.json"), JSON.stringify(config));
  519. });
  520. createWindow();
  521. app.on('activate', function () {
  522. // On macOS it's common to re-create a window in the app when the
  523. // dock icon is clicked and there are no other windows open.
  524. if (BrowserWindow.getAllWindows().length === 0) {
  525. createWindow();
  526. }
  527. })
  528. })
  529. // Quit when all windows are closed, except on macOS. There, it's common
  530. // for applications and their menu bar to stay active until the user quits
  531. // explicitly with Cmd + Q.
  532. app.on('window-all-closed', function () {
  533. if (process.platform !== 'darwin') {
  534. app.quit();
  535. }
  536. })
  537. // In this file you can include the rest of your app's specific main process
  538. // code. You can also put them in separate files and require them here.
  539. function arrayDifference(arr1, arr2) {
  540. return arr1.filter(item => !arr2.includes(item));
  541. }