优化window.ReactNativeWebView逻辑
This commit is contained in:
parent
7874632d52
commit
edf6489b50
|
@ -30,7 +30,7 @@ import { type ClientApi, getClientApi } from "../client/api";
|
||||||
import { useAccessStore } from "../store";
|
import { useAccessStore } from "../store";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { initializeMcpSystem, isMcpEnabled } from "../mcp/actions";
|
import { initializeMcpSystem, isMcpEnabled } from "../mcp/actions";
|
||||||
import { isEmpty, isString } from "lodash-es";
|
import { isEmpty } from "lodash-es";
|
||||||
|
|
||||||
export function Loading(props: { noLogo?: boolean }) {
|
export function Loading(props: { noLogo?: boolean }) {
|
||||||
return (
|
return (
|
||||||
|
@ -293,7 +293,7 @@ export function Home() {
|
||||||
|
|
||||||
if (isEmpty(data) || (typeof data === "string" && data === "")) return;
|
if (isEmpty(data) || (typeof data === "string" && data === "")) return;
|
||||||
|
|
||||||
if (isString(data)) {
|
if (window.ReactNativeWebView) {
|
||||||
try {
|
try {
|
||||||
window.ReactNativeWebView.postMessage(`${data} 从App获取的数据`);
|
window.ReactNativeWebView.postMessage(`${data} 从App获取的数据`);
|
||||||
|
|
||||||
|
@ -319,19 +319,57 @@ export function Home() {
|
||||||
);
|
);
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (
|
||||||
|
!event.origin.includes("omeoffice") &&
|
||||||
|
!event.origin.includes("localhost")
|
||||||
|
) {
|
||||||
|
return; // 如果不是信任的源,忽略消息
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
if (!isEmpty(event?.data?.ometoken))
|
||||||
|
appConfig.setOmeToken(event.data.ometoken);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
// if (isString(data)) {
|
||||||
!event.origin.includes("omeoffice") &&
|
// try {
|
||||||
!event.origin.includes("localhost")
|
// window.ReactNativeWebView.postMessage(`${data} 从App获取的数据`);
|
||||||
) {
|
|
||||||
return; // 如果不是信任的源,忽略消息
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isEmpty(event?.data?.ometoken))
|
// const params = JSON.parse(data);
|
||||||
appConfig.setOmeToken(event.data.ometoken);
|
|
||||||
|
// if (!isEmpty(params?.ometoken) && params?.from === "OmeOfficeApp") {
|
||||||
|
// appConfig.setOmeToken(params?.ometoken ?? "");
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// const message = "收到消息";
|
||||||
|
|
||||||
|
// window.ReactNativeWebView.postMessage(message);
|
||||||
|
// } catch {
|
||||||
|
// window.ReactNativeWebView.postMessage("err 失败");
|
||||||
|
|
||||||
|
// console.log("window.ReactNativeWebView Err");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } catch (err) {
|
||||||
|
// try {
|
||||||
|
// window.ReactNativeWebView.postMessage(
|
||||||
|
// `${(err as Error).message} -- try catch 失败`,
|
||||||
|
// );
|
||||||
|
// } catch {}
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (
|
||||||
|
// !event.origin.includes("omeoffice") &&
|
||||||
|
// !event.origin.includes("localhost")
|
||||||
|
// ) {
|
||||||
|
// return; // 如果不是信任的源,忽略消息
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (!isEmpty(event?.data?.ometoken))
|
||||||
|
// appConfig.setOmeToken(event.data.ometoken);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("message", handleMessage);
|
window.addEventListener("message", handleMessage);
|
||||||
|
|
Loading…
Reference in New Issue