This commit is contained in:
idranme
2024-11-09 22:21:04 +08:00
parent 30b8793ee1
commit 479e8c9d25
4 changed files with 18 additions and 34 deletions

View File

@@ -35,7 +35,6 @@ import {
NTQQWindowApi
} from '../ntqqapi/api'
import { existsSync, mkdirSync } from 'node:fs'
import { checkChanelId } from '@/ntqqapi/ntcall'
declare module 'cordis' {
interface Events {
@@ -185,7 +184,6 @@ function onLoad() {
if (config.enableLLOB && (config.satori.enable || config.ob11.enable)) {
startHook()
await checkChanelId()
await ctx.sleep(600)
} else {
llonebotError.otherError = 'LLOneBot 未启动'

View File

@@ -1,4 +1,4 @@
import { invoke, NTChannel, NTMethod } from './ntcall'
import { NTMethod } from './ntcall'
import { log } from '@/common/utils'
import { randomUUID } from 'node:crypto'
import { ipcMain } from 'electron'
@@ -40,7 +40,7 @@ const callHooks: Array<{
}> = []
export function startHook() {
log("start hook")
log('start hook')
const senderExclude = Symbol()

View File

@@ -1,6 +1,6 @@
import { ipcMain } from 'electron'
import { hookApiCallbacks, ReceiveCmdS, registerReceiveHook, removeReceiveHook } from './hook'
import { getBuildVersion, log } from '../common/utils'
import { hookApiCallbacks, registerReceiveHook, removeReceiveHook } from './hook'
import { log } from '../common/utils'
import { randomUUID } from 'node:crypto'
import {
GeneralCallResult,
@@ -17,8 +17,6 @@ import {
NodeIKernelRobotService,
NodeIKernelNodeMiscService
} from './services'
import { CategoryFriend, SimpleInfo, UserDetailInfoByUin } from '@/ntqqapi/types'
import { selfInfo } from '@/common/globalVars'
export enum NTClass {
NT_API = 'ns-ntApi',
@@ -110,38 +108,26 @@ interface InvokeOptions<ReturnType> {
timeout?: number
}
let availableChannel: NTChannel | undefined = undefined;
let channel: NTChannel
export async function checkChanelId(){
async function testChannel(channel: NTChannel) {
await invoke<UserDetailInfoByUin>(
'nodeIKernelProfileService/getUserDetailInfoByUin',
[{ uin: selfInfo.uin }],
{ timeout: 1000, channel }
)
function getChannel() {
if (channel) {
return channel
}
for (const channel of [NTChannel.IPC_UP_2, NTChannel.IPC_UP_3]) {
// const channel = `IPC_UP_${windowId}` as NTChannel
try {
await testChannel(channel)
log(`check channel ${channel} success`)
availableChannel = channel
return
} catch (e) {
log(`check channel ${channel} failed`, e)
}
if (ipcMain.eventNames().includes(NTChannel.IPC_UP_2)) {
return channel = NTChannel.IPC_UP_2
} else {
return channel = NTChannel.IPC_UP_3
}
availableChannel = getBuildVersion() >= 28788 ? NTChannel.IPC_UP_3 : NTChannel.IPC_UP_2
}
export function invoke<
R extends Awaited<ReturnType<Extract<NTService[S][M], (...args: any) => unknown>>>,
S extends keyof NTService = any,
M extends keyof NTService[S] & string = any
>(method: Extract<unknown, `${S}/${M}`> | string, args: unknown[], options: InvokeOptions<R> = {}) {
const className = options.className ?? NTClass.NT_API
// const channel = options.channel ?? getBuildVersion() >= 28788 ? NTChannel.IPC_UP_3 : NTChannel.IPC_UP_2
const channel = options.channel ?? availableChannel!
const channel = options.channel ?? getChannel()
const timeout = options.timeout ?? 5000
const afterFirstCmd = options.afterFirstCmd ?? true
let eventName = className + '-' + channel[channel.length - 1]