add context menus: open tranbox

This commit is contained in:
Gabe Yuan
2023-11-22 11:02:48 +08:00
parent f8bfcba317
commit 5bff84ace1
7 changed files with 37 additions and 2 deletions

View File

@@ -3,7 +3,11 @@ import TranBtn from "./TranBtn";
import TranBox from "./TranBox";
import { shortcutRegister } from "../../libs/shortcut";
import { sleep } from "../../libs/utils";
import { MSG_TRANSLATE_SELECTED, DEFAULT_TRANSEL_SHORTCUT } from "../../config";
import {
MSG_TRANSLATE_SELECTED,
MSG_OPEN_TRANBOX,
DEFAULT_TRANSEL_SHORTCUT,
} from "../../config";
export default function Slection({ tranboxSetting, transApis }) {
const [showBox, setShowBox] = useState(false);
@@ -90,6 +94,16 @@ export default function Slection({ tranboxSetting, transApis }) {
};
}, [handleTranSelected]);
useEffect(() => {
const handleOpenTranbox = () => {
setShowBox((pre) => !pre);
};
window.addEventListener(MSG_OPEN_TRANBOX, handleOpenTranbox);
return () => {
window.removeEventListener(MSG_OPEN_TRANBOX, handleOpenTranbox);
};
}, []);
return (
<>
{showBox && (