fix(api): fix invoke

This commit is contained in:
Il Harper 2024-03-05 23:31:05 +08:00
parent b3589da439
commit 62030ddf7f
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC
3 changed files with 13 additions and 13 deletions

View File

@ -1,16 +1,10 @@
import type {
Group,
Profile,
RedIpcData,
RedIpcEvent,
RedMessage,
} from '@chronocat/red'
import type { Group, Profile, RedIpcData, RedMessage } from '@chronocat/red'
import { ChronoEventEmitter } from './emitter'
export const requestMethodMap: Record<string, string> = {}
export const requestCallbackMap: Record<
string,
(this: RedIpcEvent, detail: RedIpcData) => void
(/* this: RedIpcEvent, */ detail: RedIpcData) => void
> = {}
export const groupMap: Record<string, Group> = {}

View File

@ -23,6 +23,7 @@ import {
chronoEventEmitter,
friendMap,
groupMap,
requestCallbackMap,
requestMethodMap,
richMediaDownloadMap,
sendCallbackMap,
@ -192,10 +193,15 @@ export const apply = async (ctx: ChronocatContext) => {
}
case 'wrapped-response': {
const res = requestCallbackMap[data.id]
if (res) res(data.args[1] /* RedIpcDataResponse */)
const method = requestMethodMap[data.id]
if (!method) return
delete requestMethodMap[data.id]
void dispatcher(method, data.args[1] /* RedIpcDataResponse */)
if (method) {
delete requestMethodMap[data.id]
void dispatcher(method, data.args[1] /* RedIpcDataResponse */)
}
return
}
}

View File

@ -18,8 +18,8 @@ export const invoke = async (
channel,
{
sender: {
send: (...args: unknown[]) => {
resolve(args)
send: (..._args: unknown[]) => {
// resolve(args)
},
},
},