mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Merge branch 'dev'
This commit is contained in:
commit
e3dffa24f8
@ -4,16 +4,12 @@
|
|||||||
"name": "LLOneBot",
|
"name": "LLOneBot",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "实现 OneBot 11 和 Satori 协议,用于 QQ 机器人开发",
|
"description": "实现 OneBot 11 和 Satori 协议,用于 QQ 机器人开发",
|
||||||
"version": "4.1.3",
|
"version": "4.1.4",
|
||||||
"icon": "./icon.webp",
|
"icon": "./icon.webp",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "linyuchen",
|
"name": "linyuchen",
|
||||||
"link": "https://github.com/linyuchen"
|
"link": "https://github.com/linyuchen"
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "idranme",
|
|
||||||
"link": "https://github.com/idranme"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
@ -34,4 +30,4 @@
|
|||||||
"main": "./main/main.cjs",
|
"main": "./main/main.cjs",
|
||||||
"preload": "./preload/preload.cjs"
|
"preload": "./preload/preload.cjs"
|
||||||
}
|
}
|
||||||
}
|
}
|
9
src/common/utils/window.ts
Normal file
9
src/common/utils/window.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { BrowserWindow } from 'electron'
|
||||||
|
import { log } from '@/common/utils'
|
||||||
|
|
||||||
|
export function getAllWindowIds(): number[] {
|
||||||
|
const allWindows = BrowserWindow.getAllWindows();
|
||||||
|
const ids = allWindows.map(window => window.id);
|
||||||
|
log('getAllWindowIds', ids);
|
||||||
|
return ids;
|
||||||
|
}
|
@ -35,6 +35,7 @@ import {
|
|||||||
NTQQWindowApi
|
NTQQWindowApi
|
||||||
} from '../ntqqapi/api'
|
} from '../ntqqapi/api'
|
||||||
import { existsSync, mkdirSync } from 'node:fs'
|
import { existsSync, mkdirSync } from 'node:fs'
|
||||||
|
import { checkChanelId } from '@/ntqqapi/ntcall'
|
||||||
|
|
||||||
declare module 'cordis' {
|
declare module 'cordis' {
|
||||||
interface Events {
|
interface Events {
|
||||||
@ -180,18 +181,17 @@ function onLoad() {
|
|||||||
if (self.uin) {
|
if (self.uin) {
|
||||||
clearInterval(intervalId)
|
clearInterval(intervalId)
|
||||||
log('process pid', process.pid)
|
log('process pid', process.pid)
|
||||||
|
|
||||||
const config = getConfigUtil().getConfig()
|
const config = getConfigUtil().getConfig()
|
||||||
|
|
||||||
if (config.enableLLOB && (config.satori.enable || config.ob11.enable)) {
|
if (config.enableLLOB && (config.satori.enable || config.ob11.enable)) {
|
||||||
startHook()
|
startHook()
|
||||||
|
await checkChanelId()
|
||||||
await ctx.sleep(600)
|
await ctx.sleep(600)
|
||||||
} else {
|
} else {
|
||||||
llonebotError.otherError = 'LLOneBot 未启动'
|
llonebotError.otherError = 'LLOneBot 未启动'
|
||||||
log('LLOneBot 开关设置为关闭,不启动 LLOneBot')
|
log('LLOneBot 开关设置为关闭,不启动 LLOneBot')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.plugin(Log, {
|
ctx.plugin(Log, {
|
||||||
enable: config.log!,
|
enable: config.log!,
|
||||||
filename: logFileName
|
filename: logFileName
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { NTMethod } from './ntcall'
|
import { invoke, NTChannel, NTMethod } from './ntcall'
|
||||||
import { log } from '@/common/utils'
|
import { log } from '@/common/utils'
|
||||||
import { randomUUID } from 'node:crypto'
|
import { randomUUID } from 'node:crypto'
|
||||||
import { ipcMain } from 'electron'
|
import { ipcMain } from 'electron'
|
||||||
@ -40,6 +40,8 @@ const callHooks: Array<{
|
|||||||
}> = []
|
}> = []
|
||||||
|
|
||||||
export function startHook() {
|
export function startHook() {
|
||||||
|
log("start hook")
|
||||||
|
|
||||||
const senderExclude = Symbol()
|
const senderExclude = Symbol()
|
||||||
|
|
||||||
ipcMain.emit = new Proxy(ipcMain.emit, {
|
ipcMain.emit = new Proxy(ipcMain.emit, {
|
||||||
@ -50,7 +52,6 @@ export function startHook() {
|
|||||||
if (logHook) {
|
if (logHook) {
|
||||||
log('request', args)
|
log('request', args)
|
||||||
}
|
}
|
||||||
|
|
||||||
const event = args[1]
|
const event = args[1]
|
||||||
if (event.sender && !event.sender[senderExclude]) {
|
if (event.sender && !event.sender[senderExclude]) {
|
||||||
event.sender[senderExclude] = true
|
event.sender[senderExclude] = true
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ipcMain } from 'electron'
|
import { ipcMain } from 'electron'
|
||||||
import { hookApiCallbacks, registerReceiveHook, removeReceiveHook } from './hook'
|
import { hookApiCallbacks, ReceiveCmdS, registerReceiveHook, removeReceiveHook } from './hook'
|
||||||
import { getBuildVersion, log } from '../common/utils'
|
import { getBuildVersion, log } from '../common/utils'
|
||||||
import { randomUUID } from 'node:crypto'
|
import { randomUUID } from 'node:crypto'
|
||||||
import {
|
import {
|
||||||
@ -17,6 +17,8 @@ import {
|
|||||||
NodeIKernelRobotService,
|
NodeIKernelRobotService,
|
||||||
NodeIKernelNodeMiscService
|
NodeIKernelNodeMiscService
|
||||||
} from './services'
|
} from './services'
|
||||||
|
import { CategoryFriend, SimpleInfo, UserDetailInfoByUin } from '@/ntqqapi/types'
|
||||||
|
import { selfInfo } from '@/common/globalVars'
|
||||||
|
|
||||||
export enum NTClass {
|
export enum NTClass {
|
||||||
NT_API = 'ns-ntApi',
|
NT_API = 'ns-ntApi',
|
||||||
@ -108,13 +110,38 @@ interface InvokeOptions<ReturnType> {
|
|||||||
timeout?: number
|
timeout?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let availableChannel: NTChannel | undefined = undefined;
|
||||||
|
|
||||||
|
export async function checkChanelId(){
|
||||||
|
async function testChannel(channel: NTChannel) {
|
||||||
|
await invoke<UserDetailInfoByUin>(
|
||||||
|
'nodeIKernelProfileService/getUserDetailInfoByUin',
|
||||||
|
[{ uin: selfInfo.uin }],
|
||||||
|
{ timeout: 1000, 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
availableChannel = getBuildVersion() >= 28788 ? NTChannel.IPC_UP_3 : NTChannel.IPC_UP_2
|
||||||
|
}
|
||||||
export function invoke<
|
export function invoke<
|
||||||
R extends Awaited<ReturnType<Extract<NTService[S][M], (...args: any) => unknown>>>,
|
R extends Awaited<ReturnType<Extract<NTService[S][M], (...args: any) => unknown>>>,
|
||||||
S extends keyof NTService = any,
|
S extends keyof NTService = any,
|
||||||
M extends keyof NTService[S] & string = any
|
M extends keyof NTService[S] & string = any
|
||||||
>(method: Extract<unknown, `${S}/${M}`> | string, args: unknown[], options: InvokeOptions<R> = {}) {
|
>(method: Extract<unknown, `${S}/${M}`> | string, args: unknown[], options: InvokeOptions<R> = {}) {
|
||||||
const className = options.className ?? NTClass.NT_API
|
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 ?? getBuildVersion() >= 28788 ? NTChannel.IPC_UP_3 : NTChannel.IPC_UP_2
|
||||||
|
const channel = options.channel ?? availableChannel!
|
||||||
const timeout = options.timeout ?? 5000
|
const timeout = options.timeout ?? 5000
|
||||||
const afterFirstCmd = options.afterFirstCmd ?? true
|
const afterFirstCmd = options.afterFirstCmd ?? true
|
||||||
let eventName = className + '-' + channel[channel.length - 1]
|
let eventName = className + '-' + channel[channel.length - 1]
|
||||||
|
@ -1 +1 @@
|
|||||||
export const version = '4.1.3'
|
export const version = '4.1.4'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user