From 3007a0c00eae3712d9afbb52d4735bd72c8e8bde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Sat, 28 Sep 2024 23:00:47 +0800 Subject: [PATCH] feat: nativeNode --- src/native/index.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/native/index.ts b/src/native/index.ts index 873b0eae..25135994 100644 --- a/src/native/index.ts +++ b/src/native/index.ts @@ -1,6 +1,7 @@ import { constants } from "node:os"; import path from "path"; import { dlopen } from "process"; +import fs from "fs"; export class Native { platform: string; supportedPlatforms = ['win32']; @@ -11,13 +12,22 @@ export class Native { if (!this.supportedPlatforms.includes(this.platform)) { throw new Error(`Platform ${this.platform} is not supported`); } - dlopen(this.MoeHooExport, path.join(nodePath, './native/MoeHoo.win32.node'), constants.dlopen.RTLD_LAZY); + let nativeNode = path.join(nodePath, './native/MoeHoo.win32.node'); + if (fs.existsSync(nativeNode)) { + dlopen(this.MoeHooExport, nativeNode, constants.dlopen.RTLD_LAZY); + } } isSetReCallEnabled(): boolean { return this.recallHookEnabled; } registerRecallCallback(callback: (hex: string) => any): void { - this.recallHookEnabled = true; - return this.MoeHooExport.exports.registMsgPush(callback); + try { + if (this.MoeHooExport.exports?.registMsgPush) { + this.MoeHooExport.exports.registMsgPush(callback); + this.recallHookEnabled = true; + } + } catch (error) { + this.recallHookEnabled = false; + } } } \ No newline at end of file