Prechádzať zdrojové kódy

新增消息通知功能

lufei 7 mesiacov pred
rodič
commit
83177c2261

+ 0 - 21
commitlint.config.js

@@ -11,27 +11,6 @@ module.exports = {
       "never",
       ["sentence-case", "start-case", "pascal-case", "upper-case"],
     ],
-    "subject-empty": [2, "never"],
-    "subject-full-stop": [2, "never", "."],
-    "type-case": [2, "always", "lower-case"],
-    "type-empty": [2, "never"],
-    "type-enum": [
-      2,
-      "always",
-      [
-        "build",
-        "chore",
-        "ci",
-        "docs",
-        "feat",
-        "fix",
-        "perf",
-        "refactor",
-        "revert",
-        "style",
-        "test",
-      ],
-    ],
   },
   prompt: {
   }

+ 16 - 1
electron/main/windowManage.ts

@@ -1,10 +1,14 @@
 import { join } from "node:path";
-import { BrowserWindow, shell } from "electron";
+import { BrowserWindow, globalShortcut, ipcMain, shell, Notification } from "electron";
 import { isLinux, isMac, isWin } from "../utils";
 import { destroyTray } from "./trayManage";
 import { getStore } from "./storeManage";
 import { getIsForceQuit } from "./appManage";
 import { registerShortcuts, unregisterShortcuts } from "./shortcutManage";
+interface NotificationData {
+  title: string;
+  body: string;
+}
 
 const url = process.env.VITE_DEV_SERVER_URL;
 let mainWindow: BrowserWindow | null = null;
@@ -52,6 +56,7 @@ export function createMainWindow() {
   if (process.env.VITE_DEV_SERVER_URL) {
     // Open devTool if the app is not packaged
     mainWindow.loadURL(url);
+    // mainWindow.webContents.openDevTools()
   } else {
     mainWindow.loadFile(global.pathConfig.indexHtml);
   }
@@ -87,6 +92,16 @@ export function createMainWindow() {
       mainWindow?.hide();
     }
   });
+
+  // globalShortcut.register('CommandOrControl+shift+l', () => {
+  //   mainWindow.webContents.openDevTools()
+  // })
+
+  ipcMain.handle('show-notification', (event, { title, body }: NotificationData) => {
+    const notification = new Notification({ title, body });
+    notification.show();
+  });
+
   return mainWindow;
 }
 

+ 12 - 0
electron/preload/index.ts

@@ -4,6 +4,10 @@ import os from "os";
 import { DataPath, IElectronAPI } from "./../../src/types/globalExpose.d";
 import { contextBridge, ipcRenderer, shell } from "electron";
 import { isProd } from "../utils";
+interface NotificationData {
+  title: string;
+  body: string;
+}
 
 const getPlatform = () => {
   if (process.platform === "darwin") {
@@ -78,6 +82,14 @@ const Api: IElectronAPI = {
   ipcInvoke,
   ipcSendSync,
   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
+    });
+  },
 };
 
 contextBridge.exposeInMainWorld("electronAPI", Api);

+ 3 - 0
src/layout/useGlobalEvents.tsx

@@ -277,6 +277,9 @@ 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[]>) => {

+ 1 - 1
src/types/globalExpose.d.ts

@@ -1,5 +1,4 @@
 import { Platform } from "@openim/wasm-client-sdk";
-
 export type DataPath = "public";
 
 export interface IElectronAPI {
@@ -17,6 +16,7 @@ export interface IElectronAPI {
     type: "fileCache" | "sentFileCache";
     sync?: boolean;
   }) => Promise<string>;
+  showNotification: (title: string, body: string) => Promise<void>;
 }
 
 declare global {