I am building a small application with Tauri (React). I am unable to open the application when it is minimized.
const handleKeyPress = useCallback(async (event: any) => {
if (event.ctrlKey && event.key === "t") {
// Minimize the window
await appWindow.minimize();
} else if (event.ctrlKey && event.key === "w") {
await appWindow.hide();
}
}, []);
useEffect(() => {
document.addEventListener("keydown", handleKeyPress);
return () => {
document.removeEventListener("keydown", handleKeyPress);
};
}, [handleKeyPress]);
This is how I can minimize with a shortcut. But unable to setFocus to the minimized app and reopen it again.
Since the document no longer has focus when it's minimized, it's unable to listen for
KeyDownevents. Luckily Tauri has the means to register global shortcuts via its globalShortcut API. Your code may look something like this:You may want to make your shortcuts more complex so that they do not interfere with the normal use of other applications.