feat: try to send poke by context menu

This commit is contained in:
linyuchen 2024-10-30 21:32:03 +08:00
parent ff952956de
commit 99693abd06
6 changed files with 207 additions and 1 deletions

View File

@ -1,6 +1,10 @@
//LiteLoader需要提供部分IPC接口以便于其他插件调用
const { ipcMain } = require('electron');
const napcat = require('./napcat.cjs');
require('./poke/main.js');
ipcMain.handle('napcat_get_webtoken', async (event, arg) => {
return napcat.NCgetWebUiUrl();
});

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,20 @@
const { ipcMain } = require('electron');
const napcat = require('../napcat.cjs');
ipcMain.handle('napcat_group_poke', async (event, { messageId, groupName }) => {
const framework = await napcat.napcatFramework;
const groups = await framework.core.apis.getGroups();
for (const group of groups) {
if (groupName === group.groupName) {
const { msgList } = await framework.core.apis.getMsgsByMsgId({
peerUid: group.groupCode,
chatType: 2
}, [messageId]);
if (msgList) {
framework.core.apis.PacketApi.sendPokePacket(msgList[0].senderUin, +group.groupCode);
break;
}
}
}
});

View File

@ -0,0 +1,11 @@
function onLoad() {
document.getElementsByClassName("avatar").forEach(e => e.addEventListener("contextmenu", (ee) => {
let messageEle = ee.target.parentElement.parentElement.parentElement.parentElement;
let messageId = messageEle.getAttribute("id");
let groupName = document.getElementsByClassName("chat-header__contact-name")[0].firstElementChild.textContent.trim();
// todo: 右键菜单添加戳一戳
window.napcat.groupPoke(groupName, messageId);
}));
}
onLoad();

View File

@ -5,6 +5,9 @@ const napcat = {
getWebUiUrl: async () => {
return ipcRenderer.invoke('napcat_get_webtoken');
},
groupPoke: async (groupName, messageId) =>{
return ipcRenderer.invoke('napcat_group_poke', {groupName, messageId});
}
};
// 在window对象下导出只读对象
contextBridge.exposeInMainWorld('napcat', napcat);

View File

@ -1,3 +1,4 @@
require('./poke/renderer.js');
export const onSettingWindowCreated = async (view) => {
// view.style.width = "100%";