mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
fix
This commit is contained in:
@@ -1,26 +1,31 @@
|
||||
import path from 'node:path'
|
||||
import fs from 'node:fs'
|
||||
import { qqPkgInfo } from '../common/utils/QQBasicInfo'
|
||||
import { NodeIKernelBuddyService } from './services/NodeIKernelBuddyService'
|
||||
import os from 'node:os'
|
||||
const Process = require('node:process')
|
||||
|
||||
export interface NodeIQQNTWrapperSession {
|
||||
[key: string]: any
|
||||
new(): NodeIQQNTWrapperSession
|
||||
getBuddyService(): NodeIKernelBuddyService
|
||||
}
|
||||
|
||||
export interface WrapperNodeApi {
|
||||
[key: string]: any
|
||||
NodeIQQNTWrapperSession: NodeIQQNTWrapperSession
|
||||
NodeIQQNTWrapperSession?: NodeIQQNTWrapperSession
|
||||
}
|
||||
|
||||
let wrapperNodePath = path.resolve(path.dirname(process.execPath), './resources/app/wrapper.node')
|
||||
if (!fs.existsSync(wrapperNodePath)) {
|
||||
wrapperNodePath = path.join(path.dirname(process.execPath), `resources/app/versions/${qqPkgInfo.version}/wrapper.node`)
|
||||
}
|
||||
const nativemodule: any = { exports: {} }
|
||||
process.dlopen(nativemodule, wrapperNodePath)
|
||||
const wrapperApi: WrapperNodeApi = nativemodule.exports
|
||||
export const wrapperApi: WrapperNodeApi = {}
|
||||
|
||||
export { wrapperApi }
|
||||
export default wrapperApi
|
||||
Process.dlopenOrig = Process.dlopen
|
||||
|
||||
Process.dlopen = function (module, filename, flags = os.constants.dlopen.RTLD_LAZY) {
|
||||
const dlopenRet = this.dlopenOrig(module, filename, flags)
|
||||
for (let export_name in module.exports) {
|
||||
module.exports[export_name] = new Proxy(module.exports[export_name], {
|
||||
construct: (target, args, _newTarget) => {
|
||||
const ret = new target(...args)
|
||||
if (export_name === 'NodeIQQNTWrapperSession') wrapperApi.NodeIQQNTWrapperSession = ret
|
||||
return ret
|
||||
},
|
||||
})
|
||||
}
|
||||
return dlopenRet
|
||||
}
|
Reference in New Issue
Block a user