88 lines
2.4 KiB
JavaScript
88 lines
2.4 KiB
JavaScript
"use strict";
|
||
const path = require("path");
|
||
const electron = require("electron");
|
||
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) => {
|
||
electron.app.quit();
|
||
});
|
||
electron.ipcMain.on("getPrintList", () => {
|
||
win.webContents.getPrintersAsync().then((res) => {
|
||
win.webContents.send("printList", res);
|
||
});
|
||
});
|
||
const printWin = new electron.BrowserWindow({
|
||
show: false,
|
||
width: 464,
|
||
height: 2206,
|
||
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"));
|
||
}
|
||
electron.ipcMain.on("printerInfoSync", (event, arg) => {
|
||
printWin.webContents.send("getParams", arg);
|
||
});
|
||
electron.ipcMain.on("printStart", (event, arg) => {
|
||
console.log(arg);
|
||
const _parmas = JSON.parse(arg);
|
||
console.log(_parmas);
|
||
let name = _parmas.deviceName;
|
||
printWin.webContents.print({
|
||
silent: true,
|
||
deviceName: name,
|
||
pageSize: {
|
||
width: 58e3,
|
||
height: 276e3
|
||
},
|
||
scaleFactor: 80,
|
||
landscape: false,
|
||
margins: {
|
||
marginType: "none",
|
||
top: 0,
|
||
bottom: 0,
|
||
left: 0,
|
||
right: 0
|
||
},
|
||
dpi: {
|
||
horizontal: 203,
|
||
vertical: 203
|
||
}
|
||
});
|
||
});
|
||
});
|
||
electron.app.on("window-all-closed", () => {
|
||
if (process.platform !== "darwin")
|
||
electron.app.quit();
|
||
});
|