This commit is contained in:
idranme 2024-08-21 23:36:35 +08:00
parent 75d3fc27f0
commit eabe891838
No known key found for this signature in database
GPG Key ID: 926F7B5B668E495F
10 changed files with 83 additions and 82 deletions

View File

@ -1,4 +1,5 @@
import { callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod } from '../ntcall'
import { invoke, NTClass, NTMethod } from '../ntcall'
import { GeneralCallResult } from '../services'
import {
CacheFileList,
CacheFileListItem,
@ -144,9 +145,9 @@ export class NTQQFileApi {
}
static async getImageSize(filePath: string) {
return await callNTQQApi<{ width: number; height: number }>({
className: NTQQApiClass.FS_API,
methodName: NTQQApiMethod.IMAGE_SIZE,
return await invoke<{ width: number; height: number }>({
className: NTClass.FS_API,
methodName: NTMethod.IMAGE_SIZE,
args: [filePath],
})
}
@ -186,8 +187,8 @@ export class NTQQFileApi {
export class NTQQFileCacheApi {
static async setCacheSilentScan(isSilent: boolean = true) {
return await callNTQQApi<GeneralCallResult>({
methodName: NTQQApiMethod.CACHE_SET_SILENCE,
return await invoke<GeneralCallResult>({
methodName: NTMethod.CACHE_SET_SILENCE,
args: [
{
isSilent,
@ -198,21 +199,21 @@ export class NTQQFileCacheApi {
}
static getCacheSessionPathList() {
return callNTQQApi<
return invoke<
{
key: string
value: string
}[]
>({
className: NTQQApiClass.OS_API,
methodName: NTQQApiMethod.CACHE_PATH_SESSION,
className: NTClass.OS_API,
methodName: NTMethod.CACHE_PATH_SESSION,
})
}
static clearCache(cacheKeys: Array<string> = ['tmp', 'hotUpdate']) {
return callNTQQApi<any>({
return invoke<any>({
// TODO: 目前还不知道真正的返回值是什么
methodName: NTQQApiMethod.CACHE_CLEAR,
methodName: NTMethod.CACHE_CLEAR,
args: [
{
keys: cacheKeys,
@ -223,8 +224,8 @@ export class NTQQFileCacheApi {
}
static addCacheScannedPaths(pathMap: object = {}) {
return callNTQQApi<GeneralCallResult>({
methodName: NTQQApiMethod.CACHE_ADD_SCANNED_PATH,
return invoke<GeneralCallResult>({
methodName: NTMethod.CACHE_ADD_SCANNED_PATH,
args: [
{
pathMap: { ...pathMap },
@ -235,35 +236,35 @@ export class NTQQFileCacheApi {
}
static scanCache() {
callNTQQApi<GeneralCallResult>({
invoke<GeneralCallResult>({
methodName: ReceiveCmdS.CACHE_SCAN_FINISH,
classNameIsRegister: true,
}).then()
return callNTQQApi<CacheScanResult>({
methodName: NTQQApiMethod.CACHE_SCAN,
return invoke<CacheScanResult>({
methodName: NTMethod.CACHE_SCAN,
args: [null, null],
timeout: 300 * Time.second,
})
}
static getHotUpdateCachePath() {
return callNTQQApi<string>({
className: NTQQApiClass.HOTUPDATE_API,
methodName: NTQQApiMethod.CACHE_PATH_HOT_UPDATE,
return invoke<string>({
className: NTClass.HOTUPDATE_API,
methodName: NTMethod.CACHE_PATH_HOT_UPDATE,
})
}
static getDesktopTmpPath() {
return callNTQQApi<string>({
className: NTQQApiClass.BUSINESS_API,
methodName: NTQQApiMethod.CACHE_PATH_DESKTOP_TEMP,
return invoke<string>({
className: NTClass.BUSINESS_API,
methodName: NTMethod.CACHE_PATH_DESKTOP_TEMP,
})
}
static getChatCacheList(type: ChatType, pageSize: number = 1000, pageIndex: number = 0) {
return new Promise<ChatCacheList>((res, rej) => {
callNTQQApi<ChatCacheList>({
methodName: NTQQApiMethod.CACHE_CHAT_GET,
invoke<ChatCacheList>({
methodName: NTMethod.CACHE_CHAT_GET,
args: [
{
chatType: type,
@ -282,8 +283,8 @@ export class NTQQFileCacheApi {
static getFileCacheInfo(fileType: CacheFileType, pageSize: number = 1000, lastRecord?: CacheFileListItem) {
const _lastRecord = lastRecord ? lastRecord : { fileType: fileType }
return callNTQQApi<CacheFileList>({
methodName: NTQQApiMethod.CACHE_FILE_GET,
return invoke<CacheFileList>({
methodName: NTMethod.CACHE_FILE_GET,
args: [
{
fileType: fileType,
@ -298,8 +299,8 @@ export class NTQQFileCacheApi {
}
static async clearChatCache(chats: ChatCacheListItemBasic[] = [], fileKeys: string[] = []) {
return await callNTQQApi<GeneralCallResult>({
methodName: NTQQApiMethod.CACHE_CHAT_CLEAR,
return await invoke<GeneralCallResult>({
methodName: NTMethod.CACHE_CHAT_CLEAR,
args: [
{
chats,

View File

@ -1,6 +1,6 @@
import { Friend, FriendV2 } from '../types'
import { ReceiveCmdS } from '../hook'
import { callNTQQApi, NTQQApiMethod } from '../ntcall'
import { invoke, NTMethod } from '../ntcall'
import { getSession } from '@/ntqqapi/wrapper'
import { BuddyListReqType, NodeIKernelProfileService } from '../services'
import { NTEventDispatch } from '@/common/utils/EventTask'
@ -9,7 +9,7 @@ import { LimitedHashTable } from '@/common/utils/table'
export class NTQQFriendApi {
/** 大于或等于 26702 应使用 getBuddyV2 */
static async getFriends(forced = false) {
const data = await callNTQQApi<{
const data = await invoke<{
data: {
categoryId: number
categroyName: string
@ -17,7 +17,7 @@ export class NTQQFriendApi {
buddyList: Friend[]
}[]
}>({
methodName: NTQQApiMethod.FRIENDS,
methodName: NTMethod.FRIENDS,
args: [{ force_update: forced }, undefined],
cbCmd: ReceiveCmdS.FRIENDS,
afterFirstCmd: false,
@ -101,7 +101,7 @@ export class NTQQFriendApi {
if (session) {
return session.getBuddyService().isBuddy(uid)
} else {
return await callNTQQApi<boolean>({
return await invoke<boolean>({
methodName: 'nodeIKernelBuddyService/isBuddy',
args: [
{ uid },

View File

@ -1,6 +1,7 @@
import { ReceiveCmdS } from '../hook'
import { Group, GroupMember, GroupMemberRole, GroupNotifies, GroupRequestOperateTypes, GroupNotify } from '../types'
import { callNTQQApi, GeneralCallResult, NTQQApiMethod } from '../ntcall'
import { invoke, NTMethod } from '../ntcall'
import { GeneralCallResult } from '../services'
import { NTQQWindowApi, NTQQWindows } from './window'
import { getSession } from '../wrapper'
import { NTEventDispatch } from '@/common/utils/EventTask'
@ -31,8 +32,8 @@ export class NTQQGroupApi {
const sceneId = groupService.createMemberListScene(groupQQ, 'groupMemberList_MainWindow')
result = await groupService.getNextMemberList(sceneId, undefined, num)
} else {
const sceneId = await callNTQQApi<string>({
methodName: NTQQApiMethod.GROUP_MEMBER_SCENE,
const sceneId = await invoke<string>({
methodName: NTMethod.GROUP_MEMBER_SCENE,
args: [
{
groupCode: groupQQ,
@ -40,10 +41,10 @@ export class NTQQGroupApi {
},
],
})
result = await callNTQQApi<
result = await invoke<
ReturnType<NodeIKernelGroupService['getNextMemberList']>
>({
methodName: NTQQApiMethod.GROUP_MEMBERS,
methodName: NTMethod.GROUP_MEMBERS,
args: [
{
sceneId,
@ -62,12 +63,12 @@ export class NTQQGroupApi {
static async getGroupNotifies() {
// 获取管理员变更
// 加群通知,退出通知,需要管理员权限
callNTQQApi<GeneralCallResult>({
invoke<GeneralCallResult>({
methodName: ReceiveCmdS.GROUP_NOTIFY,
classNameIsRegister: true,
}).then()
return await callNTQQApi<GroupNotifies>({
methodName: NTQQApiMethod.GET_GROUP_NOTICE,
return await invoke<GroupNotifies>({
methodName: NTMethod.GET_GROUP_NOTICE,
cbCmd: ReceiveCmdS.GROUP_NOTIFY,
afterFirstCmd: false,
args: [{ doubt: false, startSeq: '', number: 14 }, null],
@ -167,7 +168,7 @@ export class NTQQGroupApi {
}
static async getGroupAtAllRemainCount(groupCode: string) {
return await callNTQQApi<
return await invoke<
GeneralCallResult & {
atInfo: {
canAtAll: boolean
@ -178,7 +179,7 @@ export class NTQQGroupApi {
}
}
>({
methodName: NTQQApiMethod.GROUP_AT_ALL_REMAIN_COUNT,
methodName: NTMethod.GROUP_AT_ALL_REMAIN_COUNT,
args: [
{
groupCode,

View File

@ -1,4 +1,5 @@
import { callNTQQApi, GeneralCallResult, NTQQApiMethod } from '../ntcall'
import { invoke, NTMethod } from '../ntcall'
import { GeneralCallResult } from '../services'
import { RawMessage, SendMessageElement, Peer, ChatType2 } from '../types'
import { getSelfNick, getSelfUid } from '../../common/data'
import { getBuildVersion } from '../../common/utils'
@ -28,8 +29,8 @@ export class NTQQMsgApi {
static async activateChat(peer: Peer) {
// await this.fetchRecentContact();
// await sleep(500);
return await callNTQQApi<GeneralCallResult>({
methodName: NTQQApiMethod.ACTIVE_CHAT_PREVIEW,
return await invoke<GeneralCallResult>({
methodName: NTMethod.ACTIVE_CHAT_PREVIEW,
args: [{ peer, cnt: 20 }, null],
})
}
@ -37,8 +38,8 @@ export class NTQQMsgApi {
static async activateChatAndGetHistory(peer: Peer) {
// await this.fetchRecentContact();
// await sleep(500);
return await callNTQQApi<GeneralCallResult>({
methodName: NTQQApiMethod.ACTIVE_CHAT_HISTORY,
return await invoke<GeneralCallResult>({
methodName: NTMethod.ACTIVE_CHAT_HISTORY,
// 参数似乎不是这样
args: [{ peer, cnt: 20 }, null],
})

View File

@ -1,5 +1,3 @@
//远端rkey获取
import { log } from '@/common/utils'
interface ServerRkeyData {

View File

@ -1,4 +1,5 @@
import { callNTQQApi, GeneralCallResult, NTQQApiMethod } from '../ntcall'
import { invoke, NTMethod } from '../ntcall'
import { GeneralCallResult } from '../services'
import { User, UserDetailInfoByUin, UserDetailInfoByUinV2, UserDetailInfoListenerArg } from '../types'
import { friends, groupMembers, getSelfUin } from '@/common/data'
import { CacheClassFuncAsync, getBuildVersion } from '@/common/utils'
@ -12,8 +13,8 @@ import { Time } from 'cosmokit'
export class NTQQUserApi {
static async setQQAvatar(filePath: string) {
return await callNTQQApi<GeneralCallResult>({
methodName: NTQQApiMethod.SET_QQ_AVATAR,
return await invoke<GeneralCallResult>({
methodName: NTMethod.SET_QQ_AVATAR,
args: [
{
path: filePath,
@ -44,7 +45,7 @@ export class NTQQUserApi {
)
info = profile
} else {
const result = await callNTQQApi<{ info: UserDetailInfoListenerArg }>({
const result = await invoke<{ info: UserDetailInfoListenerArg }>({
methodName: 'nodeIKernelProfileService/fetchUserDetailInfo',
cbCmd: 'nodeIKernelProfileListener/onUserDetailInfoChanged',
afterFirstCmd: false,

View File

@ -1,4 +1,5 @@
import { callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod } from '../ntcall'
import { invoke, NTClass, NTMethod } from '../ntcall'
import { GeneralCallResult } from '../services'
import { ReceiveCmd } from '../hook'
import { BrowserWindow } from 'electron'
@ -27,12 +28,12 @@ export class NTQQWindowApi {
static async openWindow<R = GeneralCallResult>(
ntQQWindow: NTQQWindow,
args: any[],
cbCmd: ReceiveCmd | null = null,
cbCmd: ReceiveCmd | undefined,
autoCloseSeconds: number = 2,
) {
const result = await callNTQQApi<R>({
className: NTQQApiClass.WINDOW_API,
methodName: NTQQApiMethod.OPEN_EXTRA_WINDOW,
const result = await invoke<R>({
className: NTClass.WINDOW_API,
methodName: NTMethod.OPEN_EXTRA_WINDOW,
cbCmd,
afterFirstCmd: false,
args: [ntQQWindow.windowName, ...args],

View File

@ -1,5 +1,5 @@
import type { BrowserWindow } from 'electron'
import { NTQQApiClass, NTQQApiMethod } from './ntcall'
import { NTClass, NTMethod } from './ntcall'
import { NTQQMsgApi } from './api/msg'
import {
CategoryFriend,
@ -53,16 +53,16 @@ export let ReceiveCmdS = {
export type ReceiveCmd = (typeof ReceiveCmdS)[keyof typeof ReceiveCmdS]
interface NTQQApiReturnData<PayloadType = unknown> extends Array<any> {
interface NTQQApiReturnData<Payload = unknown> extends Array<any> {
0: {
type: 'request'
eventName: NTQQApiClass
eventName: NTClass
callbackId?: string
}
1: {
cmdName: ReceiveCmd
cmdType: 'event'
payload: PayloadType
payload: Payload
}[]
}
@ -73,7 +73,7 @@ let receiveHooks: Array<{
}> = []
let callHooks: Array<{
method: NTQQApiMethod[]
method: NTMethod[]
hookFunc: (callParams: unknown[]) => void | Promise<void>
}> = []
@ -141,7 +141,7 @@ export function hookNTQQApiCall(window: BrowserWindow) {
} catch (e) { }
try {
const _args: unknown[] = args[3][1]
const cmdName: NTQQApiMethod = _args[0] as NTQQApiMethod
const cmdName: NTMethod = _args[0] as NTMethod
const callParams = _args.slice(1)
callHooks.forEach((hook) => {
if (hook.method.includes(cmdName)) {
@ -207,7 +207,7 @@ export function registerReceiveHook<PayloadType>(
}
export function registerCallHook(
method: NTQQApiMethod | NTQQApiMethod[],
method: NTMethod | NTMethod[],
hookFunc: (callParams: unknown[]) => void | Promise<void>,
): void {
if (!Array.isArray(method)) {
@ -499,7 +499,7 @@ export async function startHook() {
}
})
registerCallHook(NTQQApiMethod.DELETE_ACTIVE_CHAT, async (payload) => {
registerCallHook(NTMethod.DELETE_ACTIVE_CHAT, async (payload) => {
const peerUid = payload[0] as string
log('激活的聊天窗口被删除,准备重新激活', peerUid)
let chatType = ChatType.friend

View File

@ -2,9 +2,9 @@ import { ipcMain } from 'electron'
import { hookApiCallbacks, ReceiveCmd, registerReceiveHook, removeReceiveHook } from './hook'
import { log } from '../common/utils/log'
import { randomUUID } from 'node:crypto'
import { GeneralCallResult } from './services/common'
import { GeneralCallResult } from './services'
export enum NTQQApiClass {
export enum NTClass {
NT_API = 'ns-ntApi',
FS_API = 'ns-FsApi',
OS_API = 'ns-OsApi',
@ -18,8 +18,7 @@ export enum NTQQApiClass {
NODE_STORE_API = 'ns-NodeStoreApi'
}
export enum NTQQApiMethod {
TEST = 'NodeIKernelTipOffService/getPskey',
export enum NTMethod {
RECENT_CONTACT = 'nodeIKernelRecentContactService/fetchAndSubscribeABatchOfRecentContact',
ACTIVE_CHAT_PREVIEW = 'nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat', // 激活聊天窗口,有时候必须这样才能收到消息, 并返回最新预览消息
ACTIVE_CHAT_HISTORY = 'nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat', // 激活聊天窗口,有时候必须这样才能收到消息, 并返回历史消息
@ -94,27 +93,27 @@ export enum NTQQApiMethod {
FETCH_UNITED_COMMEND_CONFIG = 'nodeIKernelUnitedConfigService/fetchUnitedCommendConfig', // 发包需要调用的
}
enum NTQQApiChannel {
export enum NTChannel {
IPC_UP_2 = 'IPC_UP_2',
IPC_UP_3 = 'IPC_UP_3',
IPC_UP_1 = 'IPC_UP_1',
}
interface NTQQApiParams {
methodName: NTQQApiMethod | string
className?: NTQQApiClass
channel?: NTQQApiChannel
interface InvokeParams {
methodName: string
className?: NTClass
channel?: NTChannel
classNameIsRegister?: boolean
args?: unknown[]
cbCmd?: ReceiveCmd | ReceiveCmd[] | null
cbCmd?: string | string[]
cmdCB?: (payload: any) => boolean
afterFirstCmd?: boolean // 是否在methodName调用完之后再去hook cbCmd
timeout?: number
}
export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
const className = params.className ?? NTQQApiClass.NT_API
const channel = params.channel ?? NTQQApiChannel.IPC_UP_2
export function invoke<ReturnType>(params: InvokeParams) {
const className = params.className ?? NTClass.NT_API
const channel = params.channel ?? NTChannel.IPC_UP_2
const timeout = params.timeout ?? 5000
const afterFirstCmd = params.afterFirstCmd ?? true
const uuid = randomUUID()
@ -184,6 +183,4 @@ export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
apiArgs,
)
})
}
export { GeneralCallResult }
}

View File

@ -1,3 +1,4 @@
export * from './common'
export * from './NodeIKernelBuddyService'
export * from './NodeIKernelProfileService'
export * from './NodeIKernelGroupService'