diff --git a/dist-electron/main.js b/dist-electron/main.js index eda7f33..05cae54 100644 --- a/dist-electron/main.js +++ b/dist-electron/main.js @@ -1,115 +1 @@ -"use strict"; -const path = require("path"); -const electron = require("electron"); -const os = require("os"); -let win; -electron.app.whenReady().then(() => { - win = new electron.BrowserWindow({ - title: "银收客", - width: 1024, - height: 768, - fullscreenable: true, - fullscreen: process.env.VITE_DEV_SERVER_URL ? false : true, - simpleFullscreen: true, - frame: process.env.VITE_DEV_SERVER_URL ? true : false, - 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) => { - win = null; - electron.app.exit(); - }); - electron.ipcMain.on("getPrintList", () => { - win.webContents.getPrintersAsync().then((res) => { - win.webContents.send("printList", res); - }); - }); - electron.ipcMain.on("getOSmacSync", () => { - let mac = ""; - if (os.networkInterfaces().WLAN) { - mac = os.networkInterfaces().WLAN[0].mac; - console.log("wlan.mac===", mac); - } else { - mac = os.networkInterfaces()["以太网"][0].mac; - console.log("以太网.mac===", mac); - } - win.webContents.send("getOSmacRes", mac); - }); - const tagPrintWin = new electron.BrowserWindow({ - show: false, - width: 360, - height: 240, - webPreferences: { - nodeIntegration: true, - contextIsolation: false - } - }); - if (process.env.VITE_DEV_SERVER_URL) { - tagPrintWin.loadFile(path.join(__dirname, "../public/tag_print.html")); - } else { - tagPrintWin.loadFile(path.resolve(__dirname, "../dist/tag_print.html")); - } - electron.ipcMain.on("printerTagSync", (event, arg) => { - console.log(arg); - tagPrintWin.webContents.send("getParams", arg); - }); - electron.ipcMain.on("printTagStart", (event, arg) => { - const _parmas = JSON.parse(arg); - let name = _parmas.deviceName; - tagPrintWin.webContents.print({ - silent: true, - deviceName: name, - pageSize: { - width: 45e3, - height: 3e4 - }, - scaleFactor: 80, - landscape: false, - margins: { - marginType: "none", - top: 0, - bottom: 0, - left: 0, - right: 0 - }, - dpi: { - horizontal: 203, - vertical: 203 - } - }); - }); - const gotTheLock = electron.app.requestSingleInstanceLock(); - if (!gotTheLock) { - electron.app.quit(); - } else { - electron.app.on("second-instance", (event, commandLine, workingDirectory) => { - if (win) { - if (win.isMinimized()) - win.restore(); - win.focus(); - win.show(); - } - }); - } - win.on("close", (e) => { - e.preventDefault(); - win.webContents.send("showCloseDialog"); - }); -}); -electron.app.on("window-all-closed", () => { - if (process.platform !== "darwin") - electron.app.quit(); -}); +"use strict";const s=require("path"),e=require("electron"),a=require("os");let n;e.app.whenReady().then(()=>{n=new e.BrowserWindow({title:"银收客",width:1024,height:768,fullscreenable:!0,fullscreen:!process.env.VITE_DEV_SERVER_URL,simpleFullscreen:!0,frame:!!process.env.VITE_DEV_SERVER_URL,webPreferences:{nodeIntegration:!0,contextIsolation:!1}}),process.env.VITE_DEV_SERVER_URL?n.loadURL(process.env.VITE_DEV_SERVER_URL):n.loadFile(s.resolve(__dirname,"../dist/index.html")),e.app.on("activate",()=>{e.BrowserWindow.getAllWindows().length===0&&createWindow()}),e.ipcMain.on("quitHandler",(t,o)=>{n=null,e.app.exit()}),e.ipcMain.on("getPrintList",()=>{n.webContents.getPrintersAsync().then(t=>{n.webContents.send("printList",t)})}),e.ipcMain.on("getOSmacSync",()=>{let t="";a.networkInterfaces().WLAN?(t=a.networkInterfaces().WLAN[0].mac,console.log("wlan.mac===",t)):(t=a.networkInterfaces().以太网[0].mac,console.log("以太网.mac===",t)),n.webContents.send("getOSmacRes",t)});const i=new e.BrowserWindow({show:!1,width:360,height:240,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?i.loadFile(s.join(__dirname,"../public/tag_print.html")):i.loadFile(s.resolve(__dirname,"../dist/tag_print.html")),e.ipcMain.on("printerTagSync",(t,o)=>{console.log(o),i.webContents.send("getParams",o)}),e.ipcMain.on("printTagStart",(t,o)=>{let l=JSON.parse(o).deviceName;i.webContents.print({silent:!0,deviceName:l,pageSize:{width:45e3,height:3e4},scaleFactor:80,landscape:!1,margins:{marginType:"none",top:0,bottom:0,left:0,right:0},dpi:{horizontal:203,vertical:203}})}),e.app.requestSingleInstanceLock()?e.app.on("second-instance",(t,o,r)=>{n&&(n.isMinimized()&&n.restore(),n.focus(),n.show())}):e.app.quit(),n.on("close",t=>{t.preventDefault(),n.webContents.send("showCloseDialog")})});e.app.on("window-all-closed",()=>{process.platform!=="darwin"&&e.app.quit()});