diff --git a/src/native/external/MoeHoo.win32.node b/src/native/external/MoeHoo.win32.node new file mode 100644 index 00000000..2b293431 Binary files /dev/null and b/src/native/external/MoeHoo.win32.node differ diff --git a/src/native/index.ts b/src/native/index.ts new file mode 100644 index 00000000..5c387d84 --- /dev/null +++ b/src/native/index.ts @@ -0,0 +1,15 @@ +import { constants } from "node:os"; +import path from "path"; +import { dlopen } from "process"; +export class Native { + platform: string; + supportedPlatforms = ['win32']; + MoeHooExport: any = { exports: {} }; + constructor(nodePath: string, platform: string = process.platform) { + this.platform = platform; + 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); + } +} \ No newline at end of file diff --git a/src/shell/napcat.ts b/src/shell/napcat.ts index d48c725c..18e89b6e 100644 --- a/src/shell/napcat.ts +++ b/src/shell/napcat.ts @@ -29,6 +29,7 @@ import { InitWebUi } from '@/webui'; import { WebUiDataRuntime } from '@/webui/src/helper/Data'; import { napCatVersion } from '@/common/version'; import { NodeIO3MiscListener } from '@/core/listeners/NodeIO3MiscListener'; +import { Native } from '@/native'; program.option('-q, --qq [number]', 'QQ号').parse(process.argv); const cmdOptions = program.opts(); @@ -55,6 +56,11 @@ export async function NCoreInitShell() { const session = wrapper.NodeIQQNTWrapperSession.create(); + let appNative = new Native(pathWrapper.binaryPath); + appNative.MoeHooExport.exports.registMsgPush((...args: any[]) => { + console.log(args); + }); + console.log(appNative); // from get dataPath const [dataPath, dataPathGlobal] = (() => { if (os.platform() === 'darwin') { diff --git a/vite.config.ts b/vite.config.ts index f5a4a17e..d52133c2 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -41,6 +41,7 @@ const FrameworkBaseConfigPlugin: PluginOption[] = [ const ShellBaseConfigPlugin: PluginOption[] = [ cp({ targets: [ + { src: './src/native/external', dest: 'dist/native', flatten: false }, { src: './static/', dest: 'dist/static/', flatten: false }, { src: './src/core/external/napcat.json', dest: 'dist/config/' }, { src: './src/onebot/config/onebot11.json', dest: 'dist/config/' },