|
1 | | -import { useEffect } from "react"; |
| 1 | +import { useCallback, useEffect } from "react"; |
2 | 2 |
|
3 | 3 | import platformAdapter from "@/utils/platformAdapter"; |
| 4 | +import { useSearchStore } from "@/stores/searchStore"; |
4 | 5 |
|
5 | 6 | const useEscape = () => { |
6 | | - const handleEscape = async (event: KeyboardEvent) => { |
7 | | - if (event.key === "Escape") { |
8 | | - console.log("Escape key pressed."); |
| 7 | + const visibleContextMenu = useSearchStore((state) => { |
| 8 | + return state.visibleContextMenu; |
| 9 | + }); |
| 10 | + const setVisibleContextMenu = useSearchStore((state) => { |
| 11 | + return state.setVisibleContextMenu; |
| 12 | + }); |
9 | 13 |
|
10 | | - event.preventDefault(); |
| 14 | + const handleEscape = useCallback(() => { |
| 15 | + async (event: KeyboardEvent) => { |
| 16 | + if (event.key === "Escape") { |
| 17 | + console.log("Escape key pressed."); |
11 | 18 |
|
12 | | - // Hide the Tauri app window when 'Esc' is pressed |
13 | | - await platformAdapter.invokeBackend("hide_coco"); |
| 19 | + event.preventDefault(); |
14 | 20 |
|
15 | | - console.log("App window hidden successfully."); |
16 | | - } |
17 | | - }; |
| 21 | + if (visibleContextMenu) { |
| 22 | + return setVisibleContextMenu(false); |
| 23 | + } |
| 24 | + |
| 25 | + // Hide the Tauri app window when 'Esc' is pressed |
| 26 | + await platformAdapter.invokeBackend("hide_coco"); |
| 27 | + |
| 28 | + console.log("App window hidden successfully."); |
| 29 | + } |
| 30 | + }; |
| 31 | + }, [visibleContextMenu]); |
18 | 32 |
|
19 | 33 | useEffect(() => { |
20 | 34 | const unlisten = platformAdapter.listenEvent("tauri://focus", () => { |
|
0 commit comments