mirror of https://github.com/msgbyte/tailchat
feat(desktop): add flash frame when receive message
parent
9eb9e9befb
commit
bf5c040515
@ -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);
|
||||||
|
});
|
||||||
|
}
|
@ -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…
Reference in New Issue