diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index c2c43e71..347908d6 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -12,7 +12,6 @@ dependencies = [ "tauri", "tauri-build", "window-shadows", - "windows 0.38.0", ] [[package]] @@ -3733,19 +3732,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "windows" -version = "0.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c47017195a790490df51a3e27f669a7d4f285920d90d03ef970c5d886ef0af1" -dependencies = [ - "windows_aarch64_msvc 0.38.0", - "windows_i686_gnu 0.38.0", - "windows_i686_msvc 0.38.0", - "windows_x86_64_gnu 0.38.0", - "windows_x86_64_msvc 0.38.0", -] - [[package]] name = "windows" version = "0.39.0" @@ -3910,12 +3896,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" -[[package]] -name = "windows_aarch64_msvc" -version = "0.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b12add87e2fb192fff3f4f7e4342b3694785d79f3a64e2c20d5ceb5ccbcfc3cd" - [[package]] name = "windows_aarch64_msvc" version = "0.39.0" @@ -3940,12 +3920,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" -[[package]] -name = "windows_i686_gnu" -version = "0.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c98f2db372c23965c5e0f43896a8f0316dc0fbe48d1aa65bea9bdd295d43c15" - [[package]] name = "windows_i686_gnu" version = "0.39.0" @@ -3976,12 +3950,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" -[[package]] -name = "windows_i686_msvc" -version = "0.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdf0569be0f2863ab6a12a6ba841fcfa7d107cbc7545a3ebd57685330db0a3ff" - [[package]] name = "windows_i686_msvc" version = "0.39.0" @@ -4006,12 +3974,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" -[[package]] -name = "windows_x86_64_gnu" -version = "0.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "905858262c8380a36f32cb8c1990d7e7c3b7a8170e58ed9a98ca6d940b7ea9f1" - [[package]] name = "windows_x86_64_gnu" version = "0.39.0" @@ -4054,12 +4016,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" -[[package]] -name = "windows_x86_64_msvc" -version = "0.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "890c3c6341d441ffb38f705f47196e3665dc6dd79f6d72fa185d937326730561" - [[package]] name = "windows_x86_64_msvc" version = "0.39.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 9fcce956..06160d79 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -16,7 +16,6 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" font-kit = "0.14.2" window-shadows = { git = "https://github.com/tauri-apps/window-shadows.git" } -windows = { version = "0.38", features = ["Win32_Foundation", "Win32_UI_WindowsAndMessaging", "Win32_System_Threading"] } [features] diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index b4950509..77e9ce0f 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,8 +1,9 @@ +// Prevents additional console window on Windows in release, DO NOT REMOVE!! +#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] + +// use tauri::command; use tauri::Manager; use window_shadows::set_shadow; -use windows::Win32::UI::WindowsAndMessaging::{GetForegroundWindow, GetWindowTextW}; -use std::collections::HashSet; - fn main() { tauri::Builder::default() .setup(|app| { @@ -12,16 +13,18 @@ fn main() { { main_window.open_devtools(); } #[cfg(any(windows, target_os = "macos"))] - set_shadow(main_window, true).unwrap() + set_shadow(main_window, true).unwrap(); Ok(()) }) - .invoke_handler(tauri::generate_handler![get_font_list, get_active_window_title]) + .invoke_handler(tauri::generate_handler![get_font_list]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } + use font_kit::{source::SystemSource}; +use std::collections::HashSet; #[tauri::command] async fn get_font_list() -> Vec { @@ -37,28 +40,4 @@ async fn get_font_list() -> Vec { } font_families.into_iter().collect() -} - -use windows::Win32::Foundation::HWND; -#[tauri::command] -fn get_active_window_title() -> String { - unsafe { - // Get the handle of the foreground (active) window - let hwnd = GetForegroundWindow(); - if hwnd == HWND(0) { // `HWND(0)` は null ハンドルを表します - return "No active window".to_string(); - } - - // Create a buffer to hold the window title - let mut buffer: [u16; 512] = [0; 512]; - - // Get the window title - let length = GetWindowTextW(hwnd, &mut buffer); - - if length > 0 { - // Convert the result to a Rust string - return String::from_utf16_lossy(&buffer[..length as usize]); - } - } - "Failed to retrieve window title".to_string() -} +} \ No newline at end of file diff --git a/src-ui/app/_app_controllers/GlobalHotKeyController.jsx b/src-ui/app/_app_controllers/GlobalHotKeyController.jsx index ae69f041..c28af2e1 100644 --- a/src-ui/app/_app_controllers/GlobalHotKeyController.jsx +++ b/src-ui/app/_app_controllers/GlobalHotKeyController.jsx @@ -1,31 +1,23 @@ 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."); - } + await register(shortcut, async () => { + console.log("Shortcut triggered, setFocus"); + appWindow.unminimize(); + await appWindow.setFocus(); + store.text_area_ref.current?.focus(); }); };