更新名称和图标
This commit is contained in:
@@ -64,6 +64,7 @@ function createWindow() {
|
|||||||
height: 1920,
|
height: 1920,
|
||||||
fullscreen: true, // 全屏
|
fullscreen: true, // 全屏
|
||||||
frame: false, // 无边框
|
frame: false, // 无边框
|
||||||
|
icon: path.join(__dirname, "../resources/icon.ico"), // 设置窗口图标
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: path.join(__dirname, "preload.js"),
|
preload: path.join(__dirname, "preload.js"),
|
||||||
nodeIntegration: false,
|
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);
|
fs.writeFileSync(tempFilePath, buffer);
|
||||||
pdfFilePath = tempFilePath;
|
pdfFilePath = tempFilePath;
|
||||||
|
|
||||||
const fileSize = fs.statSync(tempFilePath).size;
|
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) {
|
if (fileSize < 1024) {
|
||||||
throw new Error(`PDF文件大小异常(${fileSize} bytes),可能数据不完整`);
|
throw new Error(
|
||||||
|
`PDF文件大小异常(${fileSize} bytes),可能数据不完整`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.error("Base64解码或文件写入失败:", err);
|
log.error("Base64解码或文件写入失败:", err);
|
||||||
@@ -211,32 +219,39 @@ ipcMain.handle("print-pdf", async (event, pdfDataOrUrl, printOptions = {}) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 如果是HTTP/HTTPS URL,先下载
|
// 如果是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);
|
log.info("Downloading PDF from URL:", pdfDataOrUrl);
|
||||||
const protocol = pdfDataOrUrl.startsWith("https") ? https : http;
|
const protocol = pdfDataOrUrl.startsWith("https") ? https : http;
|
||||||
|
|
||||||
const buffer = await new Promise((resolve, reject) => {
|
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;
|
if (response.statusCode === 301 || response.statusCode === 302) {
|
||||||
protocol.get(redirectUrl, (redirectResponse) => {
|
const redirectUrl = response.headers.location;
|
||||||
|
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);
|
||||||
|
} else {
|
||||||
const chunks = [];
|
const chunks = [];
|
||||||
redirectResponse.on("data", (chunk) => chunks.push(chunk));
|
response.on("data", (chunk) => chunks.push(chunk));
|
||||||
redirectResponse.on("end", () => {
|
response.on("end", () => {
|
||||||
resolve(Buffer.concat(chunks));
|
resolve(Buffer.concat(chunks));
|
||||||
});
|
});
|
||||||
redirectResponse.on("error", reject);
|
response.on("error", reject);
|
||||||
}).on("error", reject);
|
}
|
||||||
} else {
|
})
|
||||||
const chunks = [];
|
.on("error", reject);
|
||||||
response.on("data", (chunk) => chunks.push(chunk));
|
|
||||||
response.on("end", () => {
|
|
||||||
resolve(Buffer.concat(chunks));
|
|
||||||
});
|
|
||||||
response.on("error", reject);
|
|
||||||
}
|
|
||||||
}).on("error", reject);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 验证PDF文件头
|
// 验证PDF文件头
|
||||||
@@ -244,12 +259,17 @@ ipcMain.handle("print-pdf", async (event, pdfDataOrUrl, printOptions = {}) => {
|
|||||||
throw new Error("下载的文件不是有效的PDF");
|
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);
|
fs.writeFileSync(tempFilePath, buffer);
|
||||||
pdfFilePath = tempFilePath;
|
pdfFilePath = tempFilePath;
|
||||||
|
|
||||||
const fileSize = fs.statSync(tempFilePath).size;
|
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://")) {
|
else if (pdfDataOrUrl.startsWith("file://")) {
|
||||||
@@ -280,7 +300,11 @@ ipcMain.handle("print-pdf", async (event, pdfDataOrUrl, printOptions = {}) => {
|
|||||||
throw new Error(`PDF文件大小异常(${stats.size} bytes),可能文件损坏`);
|
throw new Error(`PDF文件大小异常(${stats.size} bytes),可能文件损坏`);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info(`准备打印PDF: ${pdfFilePath}, 打印机: ${targetPrinterName || "默认打印机"}`);
|
log.info(
|
||||||
|
`准备打印PDF: ${pdfFilePath}, 打印机: ${
|
||||||
|
targetPrinterName || "默认打印机"
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
|
||||||
// 使用 pdf-to-printer 打印
|
// 使用 pdf-to-printer 打印
|
||||||
const printOptions_ptp = {
|
const printOptions_ptp = {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Electron + React App</title>
|
<title>自助签到</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
"appId": "com.yuanhe.checkin",
|
"appId": "com.yuanhe.checkin",
|
||||||
"productName": "YuanheCheckin",
|
"productName": "自助签到",
|
||||||
"directories": {
|
"directories": {
|
||||||
"output": "release"
|
"output": "release"
|
||||||
},
|
},
|
||||||
@@ -55,6 +55,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"win": {
|
"win": {
|
||||||
|
"icon": "resources/icon.ico",
|
||||||
"target": [
|
"target": [
|
||||||
"nsis",
|
"nsis",
|
||||||
"portable"
|
"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