"use strict"; const electron = require("electron"); const path = require("path"); electron.app.whenReady().then(() => { const win = new electron.BrowserWindow({ title: "银收客", width: 1024, height: 768, fullscreenable: true, fullscreen: false, simpleFullscreen: true, frame: true, webPreferences: { // 集成网页和 Node.js,也就是在渲染进程中,可以调用 Node.js 方法 nodeIntegration: true, contextIsolation: false } }); if (process.env.VITE_DEV_SERVER_URL) { win.loadURL(process.env.VITE_DEV_SERVER_URL); } else { win.loadFile(path.resolve(__dirname, "../dist/index.html")); } electron.app.on("activate", () => { if (electron.BrowserWindow.getAllWindows().length === 0) { createWindow(); } }); electron.ipcMain.on("quitHandler", (_, msg) => { electron.app.quit(); }); const printWin = new electron.BrowserWindow({ show: false, webPreferences: { // 集成网页和 Node.js,也就是在渲染进程中,可以调用 Node.js 方法 nodeIntegration: true, contextIsolation: false } }); if (process.env.VITE_DEV_SERVER_URL) { printWin.loadFile(path.join(__dirname, "../public/print.html")); } else { printWin.loadFile(path.resolve(__dirname, "../dist/print.html")); } printWin.webContents.openDevTools(); electron.ipcMain.on("printerInfoSync", (event, params) => { console.log(JSON.parse(params)); printWin.webContents.send("getParams", params); }); electron.ipcMain.on("printStart", () => { console.log("开始打印"); printWin.webContents.print({ silent: true }); }); }); electron.app.on("window-all-closed", () => { if (process.platform !== "darwin") electron.app.quit(); });