Add omeToken

This commit is contained in:
Ted
2025-02-18 14:26:20 +08:00
parent b966107117
commit 3754160407
4 changed files with 39 additions and 13 deletions

View File

@@ -239,6 +239,8 @@ export function Home() {
useLoadData();
useHtmlLang();
const appConfig = useAppConfig();
useEffect(() => {
console.log("[Config] got config from build time", getClientConfig());
useAccessStore.getState().fetch();
@@ -258,6 +260,29 @@ export function Home() {
initMcp();
}, []);
useEffect(() => {
window.parent.postMessage("omemetis is ready", "*");
const handleMessage = (event: any) => {
// 确保消息来自信任的源
if (!event.origin.includes("omeoffice")) {
return; // 如果不是信任的源,忽略消息
}
// 处理消息
if (event?.data?.omeToken !== null || event?.data?.omeToken !== undefined)
appConfig.setOmeToken(event.data.omeToken);
};
// 添加事件监听器
window.addEventListener("message", handleMessage);
// 清理事件监听器:组件卸载时移除事件监听
return () => {
window.removeEventListener("message", handleMessage);
};
}, []);
if (!useHasHydrated()) {
return <Loading />;
}

View File

@@ -4,7 +4,6 @@ import styles from "./home.module.scss";
import { IconButton } from "./button";
import SettingsIcon from "../icons/settings.svg";
import GithubIcon from "../icons/github.svg";
import ChatGptIcon from "../icons/chatgpt.svg";
import AddIcon from "../icons/add.svg";
import DeleteIcon from "../icons/delete.svg";
@@ -23,7 +22,6 @@ import {
MIN_SIDEBAR_WIDTH,
NARROW_SIDEBAR_WIDTH,
Path,
REPO_URL,
} from "../constant";
import { Link, useNavigate } from "react-router-dom";
@@ -336,15 +334,6 @@ export function SideBar(props: { className?: string }) {
/>
</Link>
</div>
<div className={styles["sidebar-action"]}>
<a href={REPO_URL} target="_blank" rel="noopener noreferrer">
<IconButton
aria={Locale.Export.MessageFromChatGPT}
icon={<GithubIcon />}
shadow
/>
</a>
</div>
</>
}
secondaryAction={