添加32位打包和日志

This commit is contained in:
yuchenglong
2025-11-20 11:20:10 +08:00
parent 2406d600ef
commit 5bdcc7f303
91 changed files with 113 additions and 121774 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
node_modules
release

File diff suppressed because one or more lines are too long

2
dist/index.html vendored
View File

@@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Electron + React App</title>
<script type="module" crossorigin src="./assets/index-3360d21b.js"></script>
<script type="module" crossorigin src="./assets/index-cab5b0f8.js"></script>
<link rel="stylesheet" href="./assets/index-0c3a5195.css">
</head>
<body>

View File

@@ -65,6 +65,10 @@ function loadDll() {
throw new Error(`DLL not found in ${dllDir}`);
}
parentPort.postMessage({
type: "log",
payload: `Loading DLL from: ${dllPath}`,
});
lib = koffi.load(dllPath);
return {

View File

@@ -1,6 +1,22 @@
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const { Worker } = require('worker_threads');
const { app, BrowserWindow, ipcMain } = require("electron");
const path = require("path");
const { Worker } = require("worker_threads");
const log = require("electron-log");
// 配置日志输出
log.transports.file.level = "info";
log.transports.file.resolvePath = () =>
path.join(path.dirname(app.getPath("exe")), "logs", "main.log");
log.info("App starting...");
// 监听渲染进程日志
ipcMain.on("log-message", (event, { level, message }) => {
if (log[level]) {
log[level](`[Renderer] ${message}`);
} else {
log.info(`[Renderer] ${message}`);
}
});
let idCardWorker = null;
let mainWindow = null;
@@ -8,24 +24,30 @@ let mainWindow = null;
function createIdCardWorker() {
if (idCardWorker) return;
idCardWorker = new Worker(path.join(__dirname, 'idcard-worker.js'));
log.info("Creating IDCard Worker...");
idCardWorker = new Worker(path.join(__dirname, "idcard-worker.js"));
idCardWorker.on('message', (msg) => {
idCardWorker.on("message", (msg) => {
if (!mainWindow) return;
if (msg.type === 'data') {
mainWindow.webContents.send('idcard-data', { payload: msg.payload });
} else if (msg.type === 'error') {
mainWindow.webContents.send('idcard-error', { payload: msg.payload });
if (msg.type === "data") {
log.info("IDCard data received");
mainWindow.webContents.send("idcard-data", { payload: msg.payload });
} else if (msg.type === "error") {
log.error("IDCard worker error message:", msg.payload);
mainWindow.webContents.send("idcard-error", { payload: msg.payload });
} else if (msg.type === "log") {
log.info("[Worker]", msg.payload);
}
});
idCardWorker.on('error', (err) => {
console.error('Worker error:', err);
idCardWorker.on("error", (err) => {
log.error("Worker thread error:", err);
});
idCardWorker.on('exit', (code) => {
if (code !== 0) console.error(`Worker stopped with exit code ${code}`);
idCardWorker.on("exit", (code) => {
if (code !== 0) log.error(`Worker stopped with exit code ${code}`);
else log.info("Worker stopped gracefully");
idCardWorker = null;
});
}
@@ -35,7 +57,7 @@ function createWindow() {
width: 1080,
height: 1920,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
preload: path.join(__dirname, "preload.js"),
nodeIntegration: false,
contextIsolation: true,
},
@@ -48,11 +70,11 @@ function createWindow() {
const isDev = !app.isPackaged;
if (isDev) {
win.loadURL('http://localhost:5173');
win.loadURL("http://localhost:5173");
// <20>򿪿<EFBFBD><F2BFAABF><EFBFBD><EFBFBD>߹<EFBFBD><DFB9><EFBFBD>
win.webContents.openDevTools();
} else {
win.loadFile(path.join(__dirname, '../dist/index.html'));
win.loadFile(path.join(__dirname, "../dist/index.html"));
}
}
@@ -61,35 +83,35 @@ app.whenReady().then(() => {
createIdCardWorker();
// IPC <20><><EFBFBD><EFBFBD>
ipcMain.handle('start_idcard_listen', () => {
ipcMain.handle("start_idcard_listen", () => {
if (idCardWorker) {
idCardWorker.postMessage('start');
idCardWorker.postMessage("start");
} else {
createIdCardWorker();
idCardWorker.postMessage('start');
idCardWorker.postMessage("start");
}
return 'started';
return "started";
});
ipcMain.handle('stop_idcard_listen', () => {
ipcMain.handle("stop_idcard_listen", () => {
if (idCardWorker) {
idCardWorker.postMessage('stop');
idCardWorker.postMessage("stop");
}
return 'stopped';
return "stopped";
});
app.on('activate', () => {
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on('window-all-closed', () => {
app.on("window-all-closed", () => {
if (idCardWorker) {
idCardWorker.terminate();
}
if (process.platform !== 'darwin') {
if (process.platform !== "darwin") {
app.quit();
}
});

View File

@@ -1,12 +1,15 @@
const { contextBridge, ipcRenderer } = require('electron');
const { contextBridge, ipcRenderer } = require("electron");
contextBridge.exposeInMainWorld('electronAPI', {
startIdCardListen: () => ipcRenderer.invoke('start_idcard_listen'),
stopIdCardListen: () => ipcRenderer.invoke('stop_idcard_listen'),
onIdCardData: (callback) => ipcRenderer.on('idcard-data', (event, value) => callback(value)),
onIdCardError: (callback) => ipcRenderer.on('idcard-error', (event, value) => callback(value)),
contextBridge.exposeInMainWorld("electronAPI", {
startIdCardListen: () => ipcRenderer.invoke("start_idcard_listen"),
stopIdCardListen: () => ipcRenderer.invoke("stop_idcard_listen"),
onIdCardData: (callback) =>
ipcRenderer.on("idcard-data", (event, value) => callback(value)),
onIdCardError: (callback) =>
ipcRenderer.on("idcard-error", (event, value) => callback(value)),
log: (level, message) => ipcRenderer.send("log-message", { level, message }),
removeIdCardListeners: () => {
ipcRenderer.removeAllListeners('idcard-data');
ipcRenderer.removeAllListeners('idcard-error');
}
ipcRenderer.removeAllListeners("idcard-data");
ipcRenderer.removeAllListeners("idcard-error");
},
});

14
package-lock.json generated
View File

@@ -9,6 +9,7 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"electron-log": "^5.4.3",
"iconv-lite": "^0.7.0",
"koffi": "^2.14.1",
"react": "^18.2.0",
@@ -2774,6 +2775,14 @@
"node": ">= 10.0.0"
}
},
"node_modules/electron-log": {
"version": "5.4.3",
"resolved": "https://registry.npmjs.org/electron-log/-/electron-log-5.4.3.tgz",
"integrity": "sha512-sOUsM3LjZdugatazSQ/XTyNcw8dfvH1SYhXWiJyfYodAAKOZdHs0txPiLDXFzOZbhXgAgshQkshH2ccq0feyLQ==",
"engines": {
"node": ">= 14"
}
},
"node_modules/electron-publish": {
"version": "24.13.1",
"resolved": "https://registry.npmjs.org/electron-publish/-/electron-publish-24.13.1.tgz",
@@ -7244,6 +7253,11 @@
}
}
},
"electron-log": {
"version": "5.4.3",
"resolved": "https://registry.npmjs.org/electron-log/-/electron-log-5.4.3.tgz",
"integrity": "sha512-sOUsM3LjZdugatazSQ/XTyNcw8dfvH1SYhXWiJyfYodAAKOZdHs0txPiLDXFzOZbhXgAgshQkshH2ccq0feyLQ=="
},
"electron-publish": {
"version": "24.13.1",
"resolved": "https://registry.npmjs.org/electron-publish/-/electron-publish-24.13.1.tgz",

View File

@@ -7,13 +7,16 @@
"dev": "concurrently \"vite\" \"wait-on tcp:5173 && electron .\"",
"build": "vite build",
"pack": "npm run build && electron-builder --dir",
"pack:ia32": "npm run build && electron-builder --dir --ia32",
"dist": "npm run build && electron-builder",
"dist:ia32": "npm run build && electron-builder --ia32",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"electron-log": "^5.4.3",
"iconv-lite": "^0.7.0",
"koffi": "^2.14.1",
"react": "^18.2.0",

File diff suppressed because one or more lines are too long

View File

@@ -1,21 +0,0 @@
Copyright (c) Electron contributors
Copyright (c) 2013-2020 GitHub Inc.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1 +0,0 @@
d8838bccad0c19e847b9e73f4432b951b6f035fd8c19f5474e30db5a0e4fa4c99b57c01af79161850b95d3f99a6b0b6074f18224ec7c44f28bc243be06f8f2b96e370f5ca724c01f1bd0e289afdd9eeef7e33d42a5113ddd4818a47b33449487baec2099a50d5e3dde32bdf66d979982a68d0d60a1200990ebf8a4827b7db3d1e83f9ad9d9946267fe830c48bbe025a5ebb99b85c7f1cf93de2beb22c8e9766e5ef526242b01f5251d8a768780026add2d2d8fb9ffccb86f8779221b01d206e586d96b83839b30006910a4bca6438fb5d5b2900431f8ecab50a9f18d0e7e8abec7b212fdc9ab667f08dd3eef14ecbdb24910466f45be92d0a085ff81d7362b828847c29be579942b63b9eb26b2441b5ef20f5a012431d263ded3f5fe434111b833612464bf4df18ae06c536b6895d240387774c3b438d5f0745c7a0d3ce963e82fc8df603f6fa526e8bd1fc51e2509e0840f3bbbde7bc3fec9e837b5aa744a9ae4449c974e26d787e475f73dbc3ee9c73cc258f38b79c413453fd4fe732bed57ba9d0312d2bcaf333a5c82d92a269a7ccaf27273a178feb95028f8f0805675a6199abbd8b47756b4543269a35025438794cd32410ac19c77526c4b94b93d091069056df1dda0f49298d753a317850c7104f94067ac9cc4d5b3d377f10627d21c12a4c066347eb05370fbe9e0658c1ec1803d43ed71509f5cdb25d60f505ef7527c405d3ea05bb381436dd3622484a1ff7263e4d93f275493332af3f77d28a13a0fa0eb810b7d25a378f6b8313ab3bcb44131ca3500670b0321aa95b077cef85d348e13315c2d2d42795e41569162986755709d099b59ee320e6caf422497234251d07d697bb3f3e5ad6d15d80fd85da016e7075bf84522aa6339e8b66ecd4b71d02fd01f4f57a0147ceaddbf9e5f32e7ec60ae35ff73d2f386d9d0133cb697731773b55fc2615c584e9f4013253d3fc53fa13a9e982a2493e1145861759c30cf9064d333bb184e378b52e7dd8bbbd0c17774549fabb44014dab2e0a903c53d0da1c9d3a223c69f3b9bcc7925ba21a464fc9fa43e20574ffedb7a27f2cd7ae7b6b46c5cb4e0b176ece7d59ff199b74b3436ead185df5c79d74b35d644bb02315130131772db21fcd1d535014b10c4cbbb8e1f847cd00be52992ab94a7b5a7b1c27d87abe3fc605972ceb3463a07924c816a04642adcabbc7b18a40a24a3af217d0390c1102cb5b4573b1816c76667f50d33631a97e986255644e8e0c26d63cd1f29f501ff51673509822c1bf8158ceee752024dcbe0e24941803ebd8afc0bded3598012ba5431060f0db7fad7fd4960972da9a6cfaa0850c43470498236ef7b22fbf79d491e054cf142815e6c04e573a52e22ccaa2d406167c6442db40456cd93752349b2968132388b51edbe13aa349abc34696453d1a4b39f8311284f8afbae

View File

@@ -1 +0,0 @@
{"file_format_version": "1.0.0", "ICD": {"library_path": ".\\vk_swiftshader.dll", "api_version": "1.0.5"}}

Binary file not shown.

View File

@@ -18,17 +18,27 @@ const U1: React.FC = () => {
const handleStart = () => {
if (reading) return; // 避免重复点击
setReading(true);
// 启动后端监听
// 启动后端监听;如果启动失败立即恢复 UI 状态
window.electronAPI.startIdCardListen().catch((e: any) => {
console.error("start_idcard_listen failed", e);
window.electronAPI.log("error", `start_idcard_listen failed: ${e}`);
setReading(false);
});
// 6 秒超时恢复
if (timerRef.current) {
clearTimeout(timerRef.current);
timerRef.current = null;
}
timerRef.current = window.setTimeout(() => {
if (reading) {
console.warn("未在 6 秒内读取到身份证信息,恢复初始状态");
window.electronAPI.log(
"warn",
"未在 6 秒内读取到身份证信息,恢复初始状态"
);
setReading(false);
window.electronAPI.stopIdCardListen().catch(() => {});
}
timerRef.current = null;
}, 6000);
};
@@ -39,6 +49,7 @@ const U1: React.FC = () => {
window.electronAPI.onIdCardData((e: any) => {
const payload = e.payload;
console.log("[idcard-data]", payload);
window.electronAPI.log("info", `[idcard-data] received`);
// 成功:清理定时器,停止监听,跳转并传递身份证号
if (timerRef.current) {
clearTimeout(timerRef.current);
@@ -54,6 +65,7 @@ const U1: React.FC = () => {
// 监听错误 (可选)
window.electronAPI.onIdCardError((e: any) => {
console.error("[idcard-error]", e.payload);
window.electronAPI.log("error", `[idcard-error] ${e.payload}`);
});
return () => {

1
src/vite-env.d.ts vendored
View File

@@ -6,6 +6,7 @@ interface Window {
stopIdCardListen: () => Promise<any>;
onIdCardData: (callback: (data: any) => void) => void;
onIdCardError: (callback: (error: any) => void) => void;
log: (level: string, message: any) => void;
removeIdCardListeners: () => void;
};
}