[Update/TMP] Hotkey Alt+Y will active VRCT when VRChat is the active window.

This commit is contained in:
Sakamoto Shiina
2025-01-05 14:10:48 +09:00
parent ffa1319b5b
commit 47126bf5c8
10 changed files with 830 additions and 426 deletions

View File

@@ -0,0 +1,43 @@
import { appWindow } from "@tauri-apps/api/window";
import { register, unregisterAll, isRegistered } from "@tauri-apps/api/globalShortcut";
import { invoke } from "@tauri-apps/api/tauri";
import { useEffect, useRef } from "react";
import { store } from "@store";
export const GlobalHotKeyController = () => {
const is_initialized = useRef(false);
useEffect(() => {
if (is_initialized.current) return;
const registerShortcuts = async () => {
const shortcut = "Alt+Y";
const is_already_registered = await isRegistered(shortcut);
if (is_already_registered) return;
await register(shortcut, async () => {
const activeWindowTitle = await invoke("get_active_window_title");
if (activeWindowTitle.includes("VRChat")) {
console.log("Shortcut triggered, setFocus");
appWindow.unminimize();
await appWindow.setFocus();
store.text_area_ref.current?.focus();
} else {
console.log("Active window is not VRChat.");
}
});
};
registerShortcuts();
is_initialized.current = true;
return () => {
unregisterAll().catch((error) => {
console.error("Failed to unregister shortcuts:", error);
});
};
}, []);
return null;
};