更新名称和图标
This commit is contained in:
@@ -64,6 +64,7 @@ function createWindow() {
|
||||
height: 1920,
|
||||
fullscreen: true, // 全屏
|
||||
frame: false, // 无边框
|
||||
icon: path.join(__dirname, "../resources/icon.ico"), // 设置窗口图标
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, "preload.js"),
|
||||
nodeIntegration: false,
|
||||
@@ -195,15 +196,22 @@ ipcMain.handle("print-pdf", async (event, pdfDataOrUrl, printOptions = {}) => {
|
||||
}
|
||||
|
||||
// 创建临时文件
|
||||
tempFilePath = path.join(os.tmpdir(), `print_${Date.now()}_${Math.random().toString(36).substring(7)}.pdf`);
|
||||
tempFilePath = path.join(
|
||||
os.tmpdir(),
|
||||
`print_${Date.now()}_${Math.random().toString(36).substring(7)}.pdf`
|
||||
);
|
||||
fs.writeFileSync(tempFilePath, buffer);
|
||||
pdfFilePath = tempFilePath;
|
||||
|
||||
const fileSize = fs.statSync(tempFilePath).size;
|
||||
log.info(`PDF written to temp file: ${tempFilePath}, size: ${fileSize} bytes`);
|
||||
log.info(
|
||||
`PDF written to temp file: ${tempFilePath}, size: ${fileSize} bytes`
|
||||
);
|
||||
|
||||
if (fileSize < 1024) {
|
||||
throw new Error(`PDF文件大小异常(${fileSize} bytes),可能数据不完整`);
|
||||
throw new Error(
|
||||
`PDF文件大小异常(${fileSize} bytes),可能数据不完整`
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
log.error("Base64解码或文件写入失败:", err);
|
||||
@@ -211,23 +219,29 @@ ipcMain.handle("print-pdf", async (event, pdfDataOrUrl, printOptions = {}) => {
|
||||
}
|
||||
}
|
||||
// 如果是HTTP/HTTPS URL,先下载
|
||||
else if (pdfDataOrUrl.startsWith("http://") || pdfDataOrUrl.startsWith("https://")) {
|
||||
else if (
|
||||
pdfDataOrUrl.startsWith("http://") ||
|
||||
pdfDataOrUrl.startsWith("https://")
|
||||
) {
|
||||
log.info("Downloading PDF from URL:", pdfDataOrUrl);
|
||||
const protocol = pdfDataOrUrl.startsWith("https") ? https : http;
|
||||
|
||||
const buffer = await new Promise((resolve, reject) => {
|
||||
protocol.get(pdfDataOrUrl, (response) => {
|
||||
protocol
|
||||
.get(pdfDataOrUrl, (response) => {
|
||||
// 处理重定向
|
||||
if (response.statusCode === 301 || response.statusCode === 302) {
|
||||
const redirectUrl = response.headers.location;
|
||||
protocol.get(redirectUrl, (redirectResponse) => {
|
||||
protocol
|
||||
.get(redirectUrl, (redirectResponse) => {
|
||||
const chunks = [];
|
||||
redirectResponse.on("data", (chunk) => chunks.push(chunk));
|
||||
redirectResponse.on("end", () => {
|
||||
resolve(Buffer.concat(chunks));
|
||||
});
|
||||
redirectResponse.on("error", reject);
|
||||
}).on("error", reject);
|
||||
})
|
||||
.on("error", reject);
|
||||
} else {
|
||||
const chunks = [];
|
||||
response.on("data", (chunk) => chunks.push(chunk));
|
||||
@@ -236,7 +250,8 @@ ipcMain.handle("print-pdf", async (event, pdfDataOrUrl, printOptions = {}) => {
|
||||
});
|
||||
response.on("error", reject);
|
||||
}
|
||||
}).on("error", reject);
|
||||
})
|
||||
.on("error", reject);
|
||||
});
|
||||
|
||||
// 验证PDF文件头
|
||||
@@ -244,12 +259,17 @@ ipcMain.handle("print-pdf", async (event, pdfDataOrUrl, printOptions = {}) => {
|
||||
throw new Error("下载的文件不是有效的PDF");
|
||||
}
|
||||
|
||||
tempFilePath = path.join(os.tmpdir(), `print_${Date.now()}_${Math.random().toString(36).substring(7)}.pdf`);
|
||||
tempFilePath = path.join(
|
||||
os.tmpdir(),
|
||||
`print_${Date.now()}_${Math.random().toString(36).substring(7)}.pdf`
|
||||
);
|
||||
fs.writeFileSync(tempFilePath, buffer);
|
||||
pdfFilePath = tempFilePath;
|
||||
|
||||
const fileSize = fs.statSync(tempFilePath).size;
|
||||
log.info(`PDF downloaded to temp file: ${tempFilePath}, size: ${fileSize} bytes`);
|
||||
log.info(
|
||||
`PDF downloaded to temp file: ${tempFilePath}, size: ${fileSize} bytes`
|
||||
);
|
||||
}
|
||||
// 如果是本地文件路径
|
||||
else if (pdfDataOrUrl.startsWith("file://")) {
|
||||
@@ -280,7 +300,11 @@ ipcMain.handle("print-pdf", async (event, pdfDataOrUrl, printOptions = {}) => {
|
||||
throw new Error(`PDF文件大小异常(${stats.size} bytes),可能文件损坏`);
|
||||
}
|
||||
|
||||
log.info(`准备打印PDF: ${pdfFilePath}, 打印机: ${targetPrinterName || "默认打印机"}`);
|
||||
log.info(
|
||||
`准备打印PDF: ${pdfFilePath}, 打印机: ${
|
||||
targetPrinterName || "默认打印机"
|
||||
}`
|
||||
);
|
||||
|
||||
// 使用 pdf-to-printer 打印
|
||||
const printOptions_ptp = {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Electron + React App</title>
|
||||
<title>自助签到</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
},
|
||||
"build": {
|
||||
"appId": "com.yuanhe.checkin",
|
||||
"productName": "YuanheCheckin",
|
||||
"productName": "自助签到",
|
||||
"directories": {
|
||||
"output": "release"
|
||||
},
|
||||
@@ -55,6 +55,7 @@
|
||||
}
|
||||
],
|
||||
"win": {
|
||||
"icon": "resources/icon.ico",
|
||||
"target": [
|
||||
"nsis",
|
||||
"portable"
|
||||
|
||||
BIN
resources/icon.ico
Normal file
BIN
resources/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
Reference in New Issue
Block a user