优化新增串口

This commit is contained in:
gyq
2024-03-07 18:29:19 +08:00
parent fc810fd02f
commit 58993e00ee
9 changed files with 186 additions and 188 deletions

View File

@@ -1,8 +1,14 @@
import path from "path";
import { app, BrowserWindow, ipcMain } from "electron";
import path from 'path'
const { SerialPort } = require("serialport");
SerialPort.list().then(res => {
console.log(res);
});
let win;
app.whenReady().then(() => {
const win = new BrowserWindow({
win = new BrowserWindow({
title: "银收客",
width: 1024,
height: 768,
@@ -23,15 +29,15 @@ app.whenReady().then(() => {
// 使用vite开发服务的url路径访问应用
// win.webContents.openDevTools();
} else {
win.loadFile(path.resolve(__dirname, '../dist/index.html')); // 打包后使用文件路径访问应用
win.loadFile(path.resolve(__dirname, "../dist/index.html")); // 打包后使用文件路径访问应用
}
app.on("activate", () => {
// 在 macOS 系统内, 如果没有已开启的应用窗口
// 点击托盘图标时通常会重新创建一个新窗口
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
};
createWindow();
}
});
ipcMain.on("quitHandler", (_, msg) => {
@@ -46,37 +52,28 @@ app.whenReady().then(() => {
// 集成网页和 Node.js也就是在渲染进程中可以调用 Node.js 方法
nodeIntegration: true,
contextIsolation: false,
}
})
},
});
if (process.env.VITE_DEV_SERVER_URL) {
// 加载打印的html文件
printWin.loadFile(path.join(__dirname, "../public/print.html"));
} else {
printWin.loadFile(path.resolve(__dirname, '../dist/print.html')); // 打包后使用文件路径访问应用
printWin.loadFile(path.resolve(__dirname, "../dist/print.html")); // 打包后使用文件路径访问应用
}
ipcMain.on('printerInfoSync', (event, params) => {
ipcMain.on("printerInfoSync", (event, params) => {
// console.log(JSON.parse(params))
printWin.webContents.send('getParams', params)
})
printWin.webContents.send("getParams", params);
});
// 执行打印操作
ipcMain.on('printStart', () => {
// console.log('开始打印')
printWin.webContents.printToPDF({}, (error, data) => {
if (!error && data) {
console.log("成功生成PDF")
} else {
console.error("无法生成PDF", error)
}
})
// printWin.webContents.print({
// silent: true
// })
})
// ipcMain.on('printStart', () => {
// console.log('开始打印')
// printWin.webContents.print({
// silent: true
// })
// })
});
app.on("window-all-closed", () => {