瀏覽代碼

修复通知多次提示问题

lufei 7 月之前
父節點
當前提交
121f67eef6
共有 2 個文件被更改,包括 7 次插入5 次删除
  1. 1 2
      electron/preload/index.ts
  2. 6 3
      src/layout/useGlobalEvents.tsx

+ 1 - 2
electron/preload/index.ts

@@ -84,10 +84,9 @@ const Api: IElectronAPI = {
   saveFileToDisk,
   showNotification: (title: string, body: string): Promise<void> => {
     const data: NotificationData = { title, body };
-    const content = JSON.parse(body)
     return ipcRenderer.invoke('show-notification', {
       title,
-      body: content.textElem.content
+      body
     });
   },
 };

+ 6 - 3
src/layout/useGlobalEvents.tsx

@@ -226,6 +226,12 @@ export function useGlobalEvent() {
   const notPushType = [MessageType.TypingMessage, MessageType.RevokeMessage];
 
   const newMessageHandler = ({ data }: WSEvent<MessageItem[]>) => {
+    if (window.electronAPI?.showNotification) {
+      window.electronAPI?.showNotification(
+        data[0].senderNickname,
+        data?.[0]?.textElem?.content ?? "",
+      );
+    }
     if (syncState === "loading") {
       return;
     }
@@ -277,9 +283,6 @@ export function useGlobalEvent() {
 
   // conversation
   const conversationChnageHandler = ({ data }: WSEvent<ConversationItem[]>) => {
-    if (window.electronAPI?.showNotification) {
-      window.electronAPI?.showNotification(data[0].showName, data[0].latestMsg);
-    }
     updateConversationList(data, "filter");
   };
   const newConversationHandler = ({ data }: WSEvent<ConversationItem[]>) => {