This commit is contained in:
gyq
2024-07-12 16:36:28 +08:00
parent bb554a28d2
commit 8c1e1d3fbc
12 changed files with 304 additions and 342 deletions

View File

@@ -1,5 +1,6 @@
import path from "path";
import { app, BrowserWindow, ipcMain } from "electron";
import { app, BrowserWindow, ipcMain, net } from "electron";
import os from "os";
// const SerialPort = require("serialport");
let win;
@@ -40,6 +41,16 @@ app.whenReady().then(() => {
app.quit();
});
// 监听网络在线事件
// net.on("online", () => {
// console.log("网络连接恢复");
// });
// // 监听网络离线事件
// net.on("offline", () => {
// console.log("网络连接断开");
// });
// 给渲染进程返回打印机列表
ipcMain.on("getPrintList", () => {
win.webContents.getPrintersAsync().then((res) => {
@@ -47,6 +58,19 @@ app.whenReady().then(() => {
});
});
// 获取本机mac
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);
});
// ipcMain.on("getSerialPort", () => {
// SerialPort.SerialPort.list().then(
// (ports) => {
@@ -165,7 +189,7 @@ app.whenReady().then(() => {
// 标签小票的窗口
const tagPrintWin = new BrowserWindow({
show: false,
width: 320,
width: 360,
height: 240,
webPreferences: {
nodeIntegration: true,
@@ -196,7 +220,7 @@ app.whenReady().then(() => {
silent: true,
deviceName: name,
pageSize: {
width: 40000,
width: 45000,
height: 30000,
},
scaleFactor: 80,
@@ -214,8 +238,21 @@ app.whenReady().then(() => {
},
});
});
});
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
app.on("second-instance", (event, commandLine, workingDirectory) => {
// 当运行第二个实例时,将会聚焦到mainWindow这个窗口
if (win) {
if (win.isMinimized()) win.restore();
win.focus();
win.show();
}
});
}
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") app.quit();
});