浏览代码

增加app内通知选项
增加聚焦窗口功能

lufei 6 月之前
父节点
当前提交
d927618c15

+ 22 - 3
electron/main/windowManage.ts

@@ -37,8 +37,8 @@ export function createMainWindow() {
     icon: join(global.pathConfig.publicPath, "favicon.ico"),
     frame: false,
     show: false,
-    minWidth: 680,
-    minHeight: 550,
+    minWidth: 960,
+    minHeight: 760,
     titleBarStyle: "hiddenInset",
     webPreferences: {
       preload: global.pathConfig.preload,
@@ -56,7 +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()
+    mainWindow.webContents.openDevTools()
   } else {
     mainWindow.loadFile(global.pathConfig.indexHtml);
   }
@@ -99,9 +99,24 @@ export function createMainWindow() {
 
   ipcMain.handle('show-notification', (event, { title, body }: NotificationData) => {
     const notification = new Notification({ title, body });
+    if (mainWindow.isFocused()) {
+      return
+    }
     notification.show();
   });
 
+  // 语音视频通话 聚焦窗口
+  ipcMain.handle('window:focus', (event, data) => {
+    console.log('execute window focus');
+    console.log('execute window focus');
+    console.log('execute window focus');
+    console.log('execute window focus');
+    console.log('execute window focus');
+    console.log('execute window focus');
+
+    showWindow()
+  })
+
   return mainWindow;
 }
 
@@ -166,6 +181,10 @@ export const showWindow = () => {
   } else {
     mainWindow.show();
   }
+  mainWindow.focus();
+  console.log(mainWindow.isMinimized());
+  console.log(mainWindow.isVisible());
+
 };
 export const hideWindow = () => {
   if (!mainWindow) return;

+ 11 - 0
electron/preload/index.ts

@@ -89,6 +89,17 @@ const Api: IElectronAPI = {
       body
     });
   },
+  focusWindow: () => {
+    console.log("----------------- focusWindow");
+    console.log("----------------- focusWindow");
+    console.log("----------------- focusWindow");
+    console.log("----------------- focusWindow");
+    console.log("----------------- focusWindow");
+    console.log("----------------- focusWindow");
+    console.log("----------------- focusWindow");
+
+    return ipcRenderer.invoke('window:focus');
+  }
 };
 
 contextBridge.exposeInMainWorld("electronAPI", Api);

+ 1 - 0
src/api/login.ts

@@ -165,6 +165,7 @@ export interface BusinessUserInfo {
   allowBeep: BusinessAllowType;
   allowVibration: BusinessAllowType;
   globalRecvMsgOpt: MessageReceiveOptType;
+  allowNotificationInApp: BusinessAllowType;
 }
 
 export enum BusinessAllowType {

+ 1 - 0
src/i18n/resources/en.json

@@ -249,6 +249,7 @@
     "minimize": "Minimize to Tray",
     "messageToast": "Message Alert",
     "messageAllowBeep": "New Message Sound Alert",
+    "allowNotificationInApp": "Allow notification in App",
     "messageNotNotify": "Do Not Disturb Mode",
     "addFriends": "Add Friends",
     "verifyAdd": "Add",

+ 1 - 0
src/i18n/resources/zh.json

@@ -249,6 +249,7 @@
     "minimize": "最小化托盘",
     "messageToast": "消息提示",
     "messageAllowBeep": "新消息提示音",
+    "allowNotificationInApp": "App内是否允许通知",
     "messageNotNotify": "勿扰模式",
     "addFriends": "添加好友",
     "verifyAdd": "验证添加",

+ 13 - 0
src/layout/LeftNavBar/PersonalSettings.tsx

@@ -109,6 +109,9 @@ export const PersonalSettingsContent = ({
         ? MessageReceiveOptType.NotNotify
         : MessageReceiveOptType.Normal;
     }
+    if (key === "allowNotificationInApp") {
+      updateInfo[key] = vaule ? BusinessAllowType.Allow : BusinessAllowType.NotAllow;
+    }
 
     updateBusinessSetting(updateInfo, {
       onSuccess: () => {
@@ -196,6 +199,16 @@ export const PersonalSettingsContent = ({
                   >
                     {t("placeholder.messageNotNotify")}
                   </Checkbox>
+                  <Checkbox
+                    checked={
+                      selfInfo.allowNotificationInApp === BusinessAllowType.Allow
+                    }
+                    onChange={(e) =>
+                      businessSettingsUpdate(e.target.checked, "allowNotificationInApp")
+                    }
+                  >
+                    {t("placeholder.allowNotificationInApp")}
+                  </Checkbox>
                 </div>
               </Spin>
             </div>

+ 17 - 2
src/layout/useGlobalEvents.tsx

@@ -226,12 +226,27 @@ export function useGlobalEvent() {
   const notPushType = [MessageType.TypingMessage, MessageType.RevokeMessage];
 
   const newMessageHandler = ({ data }: WSEvent<MessageItem[]>) => {
+    const message = data?.[0];
     if (window.electronAPI?.showNotification) {
       window.electronAPI?.showNotification(
-        data[0].senderNickname,
-        data?.[0]?.textElem?.content ?? "",
+        message.senderNickname,
+        message?.textElem?.content ?? "",
       );
     }
+    if (message.contentType === MessageType.CustomMessage) {
+      window.electronAPI?.focusWindow();
+    }
+    console.log("push new message ---------------", message.contentType);
+    console.log("push new message ---------------", message.contentType);
+    console.log("push new message ---------------", message.contentType);
+    console.log("push new message ---------------", message.contentType);
+    console.log("push new message ---------------", message.contentType);
+    console.log("push new message ---------------", message.contentType);
+    console.log("push new message ---------------");
+    console.log("push new message ---------------");
+    console.log("push new message ---------------");
+    console.log("push new message ---------------");
+    console.log("push new message ---------------");
     if (syncState === "loading") {
       return;
     }

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

@@ -17,6 +17,7 @@ export interface IElectronAPI {
     sync?: boolean;
   }) => Promise<string>;
   showNotification: (title: string, body: string) => Promise<void>;
+  focusWindow: () => void;
 }
 
 declare global {