Funciona con el lector, logs por todos lados

This commit is contained in:
2026-03-17 13:52:33 +01:00
parent af0f283926
commit 6ef2477a49
5 changed files with 55 additions and 14 deletions

View File

@@ -11,6 +11,7 @@ files:
- "!{tsconfig.json,tsconfig.node.json,tsconfig.web.json}" - "!{tsconfig.json,tsconfig.node.json,tsconfig.web.json}"
asarUnpack: asarUnpack:
- resources/** - resources/**
- "**/node_modules/@tockawa/nfc-pcsc/**/*"
win: win:
executableName: nfc-app-desktop executableName: nfc-app-desktop
nsis: nsis:
@@ -18,6 +19,7 @@ nsis:
shortcutName: ${productName} shortcutName: ${productName}
uninstallDisplayName: ${productName} uninstallDisplayName: ${productName}
createDesktopShortcut: always createDesktopShortcut: always
oneClick: true
mac: mac:
entitlementsInherit: build/entitlements.mac.plist entitlementsInherit: build/entitlements.mac.plist
extendInfo: extendInfo:
@@ -37,7 +39,8 @@ linux:
category: Utility category: Utility
appImage: appImage:
artifactName: ${name}-${version}.${ext} artifactName: ${name}-${version}.${ext}
npmRebuild: false npmRebuild: true
asar: true
publish: publish:
provider: generic provider: generic
url: https://example.com/auto-updates url: https://example.com/auto-updates

View File

@@ -1,6 +1,6 @@
{ {
"name": "nfc-app-desktop", "name": "nfc-app-desktop",
"version": "1.0.0", "version": "1.1.0",
"description": "An Electron application with Vue and TypeScript", "description": "An Electron application with Vue and TypeScript",
"main": "./out/main/index.js", "main": "./out/main/index.js",
"author": "example.com", "author": "example.com",
@@ -26,9 +26,7 @@
"@electron-toolkit/preload": "^3.0.2", "@electron-toolkit/preload": "^3.0.2",
"@electron-toolkit/utils": "^4.0.0", "@electron-toolkit/utils": "^4.0.0",
"@tockawa/nfc-pcsc": "latest", "@tockawa/nfc-pcsc": "latest",
"axios": "^1.13.6", "electron-updater": "^6.3.9"
"electron-updater": "^6.3.9",
"nfc-pcsc": "latest"
}, },
"devDependencies": { "devDependencies": {
"@electron-toolkit/eslint-config-prettier": "3.0.0", "@electron-toolkit/eslint-config-prettier": "3.0.0",

View File

@@ -11,6 +11,7 @@ import { logger } from "./LogService";
* @returns * @returns
*/ */
export async function labelReqHandler( export async function labelReqHandler(
//@ts-ignore: event no usado
event: IpcMainInvokeEvent, event: IpcMainInvokeEvent,
data: CodeRequest, data: CodeRequest,
): Promise<Result<string, CodeResponse>> { ): Promise<Result<string, CodeResponse>> {

View File

@@ -7,7 +7,24 @@ import { labelReqHandler, printReqHandler } from "./handlers";
import { logger } from "./LogService"; import { logger } from "./LogService";
import { createConnection } from "net"; import { createConnection } from "net";
// 1. Global Error Handling (CRITICAL: As early as possible)
process.on("uncaughtException", (error) => {
logger.error("!!! UNCAUGHT EXCEPTION !!!", error);
console.error("Uncaught Exception:", error);
// Give some time for log to write before exit
setTimeout(() => app.quit(), 1000);
});
process.on("unhandledRejection", (reason) => {
logger.error("!!! UNHANDLED REJECTION !!!", reason);
console.error("Unhandled Rejection:", reason);
});
logger.info(">>> MAIN PROCESS BOOTSTRAP START <<<");
logger.info(`Platform: ${process.platform} | Arch: ${process.arch} | Version: ${app.getVersion()}`);
function createWindow(): void { function createWindow(): void {
logger.info("Creating main window...");
// Create the browser window. // Create the browser window.
const mainWindow = new BrowserWindow({ const mainWindow = new BrowserWindow({
width: 900, width: 900,
@@ -21,18 +38,27 @@ function createWindow(): void {
}, },
}); });
const nfcService = new NfcService((event) => { let nfcService: NfcService | null = null;
if (!mainWindow.isDestroyed()) {
mainWindow.webContents.send(`nfc:${event.type}`, event);
}
});
ipcMain.handle("nfc:getReaderName", () => { ipcMain.handle("nfc:getReaderName", () => {
return nfcService.getReaderName(); return nfcService ? nfcService.getReaderName() : "OFFLINE";
}); });
mainWindow.on("ready-to-show", () => { mainWindow.on("ready-to-show", () => {
mainWindow.show(); mainWindow.show();
// 2. Initialize NFC AFTER window is ready to show (DEFERRED INIT)
logger.info("Deferred: Initializing NfcService...");
try {
nfcService = new NfcService((event) => {
if (!mainWindow.isDestroyed()) {
mainWindow.webContents.send(`nfc:${event.type}`, event);
}
});
logger.info("Deferred: NfcService initialization finished.");
} catch (error) {
logger.error("Deferred: Failed to initialize NfcService", error);
}
}); });
mainWindow.webContents.setWindowOpenHandler((details) => { mainWindow.webContents.setWindowOpenHandler((details) => {
@@ -106,14 +132,14 @@ app.whenReady().then(() => {
req(true); req(true);
}); });
socket.on("timeout", (err) => { socket.on("timeout", (_) => {
if (finished) return; if (finished) return;
finished = true; finished = true;
socket.destroy(); socket.destroy();
rej(false); rej(false);
}); });
socket.on("error", (err) => { socket.on("error", (_) => {
if (finished) return; if (finished) return;
finished = true; finished = true;
socket.destroy(); socket.destroy();
@@ -123,7 +149,9 @@ app.whenReady().then(() => {
}, },
); );
logger.info("App Ready. Creating main window...");
createWindow(); createWindow();
logger.info("Main window creation triggered.");
app.on("activate", function () { app.on("activate", function () {
// On macOS it's common to re-create a window in the app when the // On macOS it's common to re-create a window in the app when the

View File

@@ -13,9 +13,18 @@ export class NfcService {
private currentReaderName: string = "OFFLINE"; private currentReaderName: string = "OFFLINE";
constructor(onEvent?: (event: NfcEvent) => void) { constructor(onEvent?: (event: NfcEvent) => void) {
this.nfc = new PCSC.default(); logger.info("NfcService: Constructor start");
try {
logger.info("NfcService: Creating PCSC instance...");
this.nfc = new PCSC.default();
logger.info("NfcService: PCSC instance created.");
} catch (err) {
logger.error("NfcService: Failed to create PCSC instance", err);
throw err;
}
this.onEvent = onEvent; this.onEvent = onEvent;
this.init(); this.init();
logger.info("NfcService: Constructor end");
} }
public getReaderName(): string { public getReaderName(): string {
@@ -23,6 +32,7 @@ export class NfcService {
} }
private init(): void { private init(): void {
logger.info("NfcService: Starting initialization and attaching listeners...");
this.nfc.on("reader", (reader: Reader) => { this.nfc.on("reader", (reader: Reader) => {
console.log(`Lector detectado: ${reader.name}`); console.log(`Lector detectado: ${reader.name}`);
logger.info(`NFC Reader detected: ${reader.name}`); logger.info(`NFC Reader detected: ${reader.name}`);
@@ -76,6 +86,7 @@ export class NfcService {
}); });
} }
}); });
logger.info("NfcService: Initialization sequence complete.");
} }
public stop(): void { public stop(): void {