diff --git a/apps/web/src/App/index.tsx b/apps/web/src/App/index.tsx index 8c3e67d..c174789 100644 --- a/apps/web/src/App/index.tsx +++ b/apps/web/src/App/index.tsx @@ -1,100 +1,75 @@ -import { ChatPage, EndpointCategory, WKApp, Menus } from "@tsdaodao/base"; -import { ContactsList } from "@tsdaodao/contacts"; -import React from "react"; -import "./index.css"; -import AppLayout from "../Layout"; -import { WKSDK } from "wukongimjssdk"; +import { ChatPage, EndpointCategory, WKApp, Menus } from '@tsdaodao/base'; +import { ContactsList } from '@tsdaodao/contacts'; +import React from 'react'; +import './index.css'; +import AppLayout from '../Layout'; +import { WKSDK } from 'wukongimjssdk'; function App() { - registerMenus(); - return ; + registerMenus() + return ( + + ); } -function registerMenus() { +async function registerMenus() { + WKSDK.shared().conversationManager.addConversationListener(() => { - WKApp.menus.refresh(); - }); + WKApp.menus.refresh() + }) - WKApp.endpointManager.setMethod( - "menus.friendapply.change", - () => { - WKApp.menus.refresh(); - }, - { - category: EndpointCategory.friendApplyDataChange, + WKApp.endpointManager.setMethod("menus.friendapply.change", () => { + WKApp.menus.refresh() + }, { + category: EndpointCategory.friendApplyDataChange, + }) + + WKApp.menus.register("chat", (_context) => { + const m = new Menus("chat", "/", "会话", + 会话, + 会话) + let badge = 0; + + for (const conversation of WKSDK.shared().conversationManager.conversations) { + badge += conversation.unread } - ); - WKApp.menus.register( - "chat", - (context) => { - const m = new Menus( - "chat", - "/", - "会话", - 会话, - ( - 会话 - ) - ); - let badge = 0; - for (const conversation of WKSDK.shared().conversationManager - .conversations) { - if (!conversation.channelInfo?.mute) { - badge += conversation.unread; - } - } - m.badge = badge; - return m; - }, - 1000 - ); + m.badge = badge; + + if ((window as any).__POWERED_ELECTRON__) { + (window as any).ipc.send("conversation-anager-unread-count", badge); + } + + return m + }, 1000) // 获取好友未申请添加数量 - let unreadCount = 0; + // let unreadCount = 0; if (WKApp.loginInfo.isLogined()) { - WKApp.apiClient.get(`/user/reddot/friendApply`).then((res) => { - unreadCount = res.count; + WKApp.apiClient.get(`/user/reddot/friendApply`).then(res => { + // unreadCount = res.count; + WKApp.mittBus.emit('friend-applys-unread-count', res.count) + WKApp.loginInfo.setStorageItem(`${WKApp.loginInfo.uid}-friend-applys-unread-count`, res.count) WKApp.menus.refresh(); - }); + }) } - WKApp.menus.register( - "contacts", - (param) => { - const m = new Menus( - "contacts", - "/contacts", - "通讯录", - ( - 通讯录 - ), - ( - 通讯录 - ) - ); - - m.badge = unreadCount; - return m; - }, - 2000 - ); + WKApp.menus.register("contacts", (param) => { + const m = new Menus("contacts", "/contacts", "通讯录", + 通讯录, + 通讯录) + m.badge = WKApp.shared.getFriendApplysUnreadCount(); + return m + }, 4000) WKApp.route.register("/", () => { - return ; - }); + return + }) WKApp.route.register("/contacts", () => { - return ; - }); + return + }) + } export default App; +