|
| 1 | +const { app, BrowserWindow, Menu, session } = require("electron"); |
| 2 | +const path = require("path"); |
| 3 | +const service = require("./service/service"); |
| 4 | +const sleep = require("./utils/sleep"); |
| 5 | +const is = require("electron-is"); |
| 6 | +// Handle creating/removing shortcuts on Windows when installing/uninstalling. |
| 7 | +if (require("electron-squirrel-startup")) { |
| 8 | + app.quit(); |
| 9 | +} |
| 10 | + |
| 11 | +const createWindow = () => { |
| 12 | + // session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => { |
| 13 | + // if (details.url.indexOf("baidu.com") >= 0) { |
| 14 | + // if (details.url.indexOf("%2Fweb%2Findex.html") >= 0) { |
| 15 | + // console.log(11, details.url); |
| 16 | + // details.url += "&xx=1"; |
| 17 | + // } |
| 18 | + // details.requestHeaders["Referer"] = "https://local-ai.dxcweb.com/"; |
| 19 | + // } |
| 20 | + // callback({ cancel: false, requestHeaders: details.requestHeaders }); |
| 21 | + // }); |
| 22 | + // Create the browser window. |
| 23 | + const mainWindow = new BrowserWindow({ |
| 24 | + titleBarStyle: "hidden", |
| 25 | + // width: 1200, |
| 26 | + // height: 800, |
| 27 | + width: 1500, |
| 28 | + height: 1000, |
| 29 | + webPreferences: { |
| 30 | + preload: path.join(__dirname, "preload.js"), |
| 31 | + }, |
| 32 | + }); |
| 33 | + service(mainWindow); |
| 34 | + if (is.macOS()) { |
| 35 | + // macOS |
| 36 | + const template = [ |
| 37 | + { |
| 38 | + label: "本地AI", |
| 39 | + submenu: [ |
| 40 | + { role: "undo", label: "撤销" }, |
| 41 | + { role: "redo", label: "重做" }, |
| 42 | + { role: "cut", label: "剪切" }, |
| 43 | + { role: "copy", label: "复制" }, |
| 44 | + { role: "paste", label: "粘贴" }, |
| 45 | + { role: "selectall", label: "全选" }, |
| 46 | + { role: "quit", label: "退出" }, |
| 47 | + ], |
| 48 | + }, |
| 49 | + ]; |
| 50 | + Menu.setApplicationMenu(Menu.buildFromTemplate(template)); |
| 51 | + } else { |
| 52 | + // Windows and Linux |
| 53 | + mainWindow.setMenu(null); |
| 54 | + } |
| 55 | + // and load the index.html of the app. |
| 56 | + // mainWindow.loadFile(path.join(__dirname, "web/index.html")); |
| 57 | + mainWindow.loadURL("https://ai.dxcweb.com/el/?v=1.4.0"); |
| 58 | + // mainWindow.loadURL("http://localhost:18888"); |
| 59 | + |
| 60 | + // Open the DevTools. |
| 61 | + // mainWindow.webContents.openDevTools(); |
| 62 | +}; |
| 63 | + |
| 64 | +// This method will be called when Electron has finished |
| 65 | +// initialization and is ready to create browser windows. |
| 66 | +// Some APIs can only be used after this event occurs. |
| 67 | +app.on("ready", createWindow); |
| 68 | + |
| 69 | +app.on("window-all-closed", () => { |
| 70 | + app.quit(); |
| 71 | +}); |
| 72 | + |
| 73 | +app.on("activate", () => { |
| 74 | + //在 macOS 上,点击 dock 图标时没有已打开的其他窗口时,会重新创建一个窗口 |
| 75 | + if (BrowserWindow.getAllWindows().length === 0) { |
| 76 | + createWindow(); |
| 77 | + } |
| 78 | +}); |
| 79 | +// 在应用程序退出之前执行 |
| 80 | + |
| 81 | +// In this file you can include the rest of your app's specific main process |
| 82 | +// code. You can also put them in separate files and import them here. |
0 commit comments