Funciona con el lector, logs por todos lados
This commit is contained in:
@@ -11,6 +11,7 @@ files:
|
||||
- "!{tsconfig.json,tsconfig.node.json,tsconfig.web.json}"
|
||||
asarUnpack:
|
||||
- resources/**
|
||||
- "**/node_modules/@tockawa/nfc-pcsc/**/*"
|
||||
win:
|
||||
executableName: nfc-app-desktop
|
||||
nsis:
|
||||
@@ -18,6 +19,7 @@ nsis:
|
||||
shortcutName: ${productName}
|
||||
uninstallDisplayName: ${productName}
|
||||
createDesktopShortcut: always
|
||||
oneClick: true
|
||||
mac:
|
||||
entitlementsInherit: build/entitlements.mac.plist
|
||||
extendInfo:
|
||||
@@ -37,7 +39,8 @@ linux:
|
||||
category: Utility
|
||||
appImage:
|
||||
artifactName: ${name}-${version}.${ext}
|
||||
npmRebuild: false
|
||||
npmRebuild: true
|
||||
asar: true
|
||||
publish:
|
||||
provider: generic
|
||||
url: https://example.com/auto-updates
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nfc-app-desktop",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"description": "An Electron application with Vue and TypeScript",
|
||||
"main": "./out/main/index.js",
|
||||
"author": "example.com",
|
||||
@@ -26,9 +26,7 @@
|
||||
"@electron-toolkit/preload": "^3.0.2",
|
||||
"@electron-toolkit/utils": "^4.0.0",
|
||||
"@tockawa/nfc-pcsc": "latest",
|
||||
"axios": "^1.13.6",
|
||||
"electron-updater": "^6.3.9",
|
||||
"nfc-pcsc": "latest"
|
||||
"electron-updater": "^6.3.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@electron-toolkit/eslint-config-prettier": "3.0.0",
|
||||
|
||||
@@ -11,6 +11,7 @@ import { logger } from "./LogService";
|
||||
* @returns
|
||||
*/
|
||||
export async function labelReqHandler(
|
||||
//@ts-ignore: event no usado
|
||||
event: IpcMainInvokeEvent,
|
||||
data: CodeRequest,
|
||||
): Promise<Result<string, CodeResponse>> {
|
||||
|
||||
@@ -7,7 +7,24 @@ import { labelReqHandler, printReqHandler } from "./handlers";
|
||||
import { logger } from "./LogService";
|
||||
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 {
|
||||
logger.info("Creating main window...");
|
||||
// Create the browser window.
|
||||
const mainWindow = new BrowserWindow({
|
||||
width: 900,
|
||||
@@ -21,18 +38,27 @@ function createWindow(): void {
|
||||
},
|
||||
});
|
||||
|
||||
const nfcService = new NfcService((event) => {
|
||||
if (!mainWindow.isDestroyed()) {
|
||||
mainWindow.webContents.send(`nfc:${event.type}`, event);
|
||||
}
|
||||
});
|
||||
let nfcService: NfcService | null = null;
|
||||
|
||||
ipcMain.handle("nfc:getReaderName", () => {
|
||||
return nfcService.getReaderName();
|
||||
return nfcService ? nfcService.getReaderName() : "OFFLINE";
|
||||
});
|
||||
|
||||
mainWindow.on("ready-to-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) => {
|
||||
@@ -106,14 +132,14 @@ app.whenReady().then(() => {
|
||||
req(true);
|
||||
});
|
||||
|
||||
socket.on("timeout", (err) => {
|
||||
socket.on("timeout", (_) => {
|
||||
if (finished) return;
|
||||
finished = true;
|
||||
socket.destroy();
|
||||
rej(false);
|
||||
});
|
||||
|
||||
socket.on("error", (err) => {
|
||||
socket.on("error", (_) => {
|
||||
if (finished) return;
|
||||
finished = true;
|
||||
socket.destroy();
|
||||
@@ -123,7 +149,9 @@ app.whenReady().then(() => {
|
||||
},
|
||||
);
|
||||
|
||||
logger.info("App Ready. Creating main window...");
|
||||
createWindow();
|
||||
logger.info("Main window creation triggered.");
|
||||
|
||||
app.on("activate", function () {
|
||||
// On macOS it's common to re-create a window in the app when the
|
||||
|
||||
@@ -13,9 +13,18 @@ export class NfcService {
|
||||
private currentReaderName: string = "OFFLINE";
|
||||
|
||||
constructor(onEvent?: (event: NfcEvent) => void) {
|
||||
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.init();
|
||||
logger.info("NfcService: Constructor end");
|
||||
}
|
||||
|
||||
public getReaderName(): string {
|
||||
@@ -23,6 +32,7 @@ export class NfcService {
|
||||
}
|
||||
|
||||
private init(): void {
|
||||
logger.info("NfcService: Starting initialization and attaching listeners...");
|
||||
this.nfc.on("reader", (reader: Reader) => {
|
||||
console.log(`Lector detectado: ${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 {
|
||||
|
||||
Reference in New Issue
Block a user