feat(desktop): add flash frame when receive message

test/ios-bundle
moonrailgun 2 years ago
parent 9eb9e9befb
commit bf5c040515

@ -5,7 +5,7 @@ on:
branches: branches:
- master - master
paths: paths:
- "client/desktop/**" - "client/desktop/release/app/package.json" # build when version upgrade
workflow_dispatch: workflow_dispatch:
jobs: jobs:

@ -1,11 +1,13 @@
import { generateInstallPluginScript } from '.'; import { generateInstallPluginScript } from '.';
import log from 'electron-log'; import log from 'electron-log';
import { startScreenshots } from '../screenshots'; import { startScreenshots } from '../screenshots';
import { BrowserWindow } from 'electron';
export function handleTailchatMessage( export function handleTailchatMessage(
type: string, type: string,
payload: any, payload: any,
webview: Electron.WebContents webview: Electron.WebContents,
win: BrowserWindow
) { ) {
log.info('onMessage receive:', type, payload); log.info('onMessage receive:', type, payload);
@ -18,4 +20,11 @@ export function handleTailchatMessage(
startScreenshots(); startScreenshots();
return; return;
} }
if (type === 'receiveUnmutedMessage') {
if (!win.isFocused) {
win.flashFrame(true);
}
return;
}
} }

@ -182,11 +182,20 @@ const createMainWindow = async (url: string) => {
if (channel === 'webview-message') { if (channel === 'webview-message') {
const obj = JSON.parse(data); const obj = JSON.parse(data);
if (typeof obj === 'object' && obj._isTailchat === true && mainWindow) { if (typeof obj === 'object' && obj._isTailchat === true && mainWindow) {
handleTailchatMessage(obj.type, obj.payload, mainWindow.webContents); handleTailchatMessage(
obj.type,
obj.payload,
mainWindow.webContents,
mainWindow
);
} }
} }
}); });
mainWindow.on('focus', () => {
mainWindow?.flashFrame(false);
});
mainWindow.on('ready-to-show', () => { mainWindow.on('ready-to-show', () => {
if (!mainWindow) { if (!mainWindow) {
throw new Error('"mainWindow" is not defined'); throw new Error('"mainWindow" is not defined');

@ -7,6 +7,7 @@ import { Icon } from '@capital/component';
import React from 'react'; import React from 'react';
import { DeviceInfoPanel } from './DeviceInfoPanel'; import { DeviceInfoPanel } from './DeviceInfoPanel';
import { Translate } from './translate'; import { Translate } from './translate';
import { forwardSharedEvent } from './utils';
const PLUGIN_NAME = 'Electron Support'; const PLUGIN_NAME = 'Electron Support';
@ -34,3 +35,5 @@ regChatInputButton({
); );
}, },
}); });
forwardSharedEvent('receiveUnmutedMessage');

@ -0,0 +1,25 @@
import { sharedEvent, postMessageEvent } from '@capital/common';
/**
*
*/
export function forwardSharedEvent(
eventName: string,
processPayload?: (payload: any) => Promise<{ type: string; payload: any }>
) {
sharedEvent.on(eventName, async (payload: any) => {
let type = eventName;
if (processPayload) {
const res = await processPayload(payload);
if (!res) {
// Skip if res is undefined
return;
}
payload = res.payload;
type = res.type;
}
postMessageEvent(type, payload);
});
}

@ -1,6 +1,5 @@
import { import {
getGlobalState, getGlobalState,
sharedEvent,
getCachedUserInfo, getCachedUserInfo,
getCachedBaseGroupInfo, getCachedBaseGroupInfo,
getMessageTextDecorators, getMessageTextDecorators,
@ -9,6 +8,7 @@ import {
} from '@capital/common'; } from '@capital/common';
import { DeviceInfoPanel } from './DeviceInfoPanel'; import { DeviceInfoPanel } from './DeviceInfoPanel';
import { Translate } from './translate'; import { Translate } from './translate';
import { forwardSharedEvent } from './utils';
const PLUGIN_NAME = 'ReactNative Support'; const PLUGIN_NAME = 'ReactNative Support';
@ -22,40 +22,6 @@ regCustomPanel({
render: DeviceInfoPanel, render: DeviceInfoPanel,
}); });
/**
*
*/
function forwardSharedEvent(
eventName: string,
processPayload?: (payload: any) => Promise<{ type: string; payload: any }>
) {
if (!(window as any).ReactNativeWebView) {
return;
}
sharedEvent.on(eventName, async (payload: any) => {
let type = eventName;
if (processPayload) {
const res = await processPayload(payload);
if (!res) {
// Skip if res is undefined
return;
}
payload = res.payload;
type = res.type;
}
(window as any).ReactNativeWebView.postMessage(
JSON.stringify({
_isTailchat: true,
type,
payload,
})
);
});
}
forwardSharedEvent('loadColorScheme'); forwardSharedEvent('loadColorScheme');
forwardSharedEvent('loginSuccess', async (payload) => { forwardSharedEvent('loginSuccess', async (payload) => {
let token = window.localStorage.getItem('jsonwebtoken'); let token = window.localStorage.getItem('jsonwebtoken');

@ -0,0 +1,35 @@
import { sharedEvent } from '@capital/common';
/**
*
*/
export function forwardSharedEvent(
eventName: string,
processPayload?: (payload: any) => Promise<{ type: string; payload: any }>
) {
if (!(window as any).ReactNativeWebView) {
return;
}
sharedEvent.on(eventName, async (payload: any) => {
let type = eventName;
if (processPayload) {
const res = await processPayload(payload);
if (!res) {
// Skip if res is undefined
return;
}
payload = res.payload;
type = res.type;
}
(window as any).ReactNativeWebView.postMessage(
JSON.stringify({
_isTailchat: true,
type,
payload,
})
);
});
}
Loading…
Cancel
Save