[Update/TMP] The shortcut will trigger whenever.(Remove the checking whether the window is VRChat or not)

This commit is contained in:
Sakamoto Shiina
2025-01-05 14:23:10 +09:00
parent 47126bf5c8
commit 9e5af73ccb
4 changed files with 14 additions and 88 deletions

44
src-tauri/Cargo.lock generated
View File

@@ -12,7 +12,6 @@ dependencies = [
"tauri", "tauri",
"tauri-build", "tauri-build",
"window-shadows", "window-shadows",
"windows 0.38.0",
] ]
[[package]] [[package]]
@@ -3733,19 +3732,6 @@ dependencies = [
"windows-sys 0.52.0", "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]] [[package]]
name = "windows" name = "windows"
version = "0.39.0" version = "0.39.0"
@@ -3910,12 +3896,6 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.38.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b12add87e2fb192fff3f4f7e4342b3694785d79f3a64e2c20d5ceb5ccbcfc3cd"
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
version = "0.39.0" version = "0.39.0"
@@ -3940,12 +3920,6 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.38.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c98f2db372c23965c5e0f43896a8f0316dc0fbe48d1aa65bea9bdd295d43c15"
[[package]] [[package]]
name = "windows_i686_gnu" name = "windows_i686_gnu"
version = "0.39.0" version = "0.39.0"
@@ -3976,12 +3950,6 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.38.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdf0569be0f2863ab6a12a6ba841fcfa7d107cbc7545a3ebd57685330db0a3ff"
[[package]] [[package]]
name = "windows_i686_msvc" name = "windows_i686_msvc"
version = "0.39.0" version = "0.39.0"
@@ -4006,12 +3974,6 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" 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]] [[package]]
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
version = "0.39.0" version = "0.39.0"
@@ -4054,12 +4016,6 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" 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]] [[package]]
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
version = "0.39.0" version = "0.39.0"

View File

@@ -16,7 +16,6 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1" serde_json = "1"
font-kit = "0.14.2" font-kit = "0.14.2"
window-shadows = { git = "https://github.com/tauri-apps/window-shadows.git" } 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] [features]

View File

@@ -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 tauri::Manager;
use window_shadows::set_shadow; use window_shadows::set_shadow;
use windows::Win32::UI::WindowsAndMessaging::{GetForegroundWindow, GetWindowTextW};
use std::collections::HashSet;
fn main() { fn main() {
tauri::Builder::default() tauri::Builder::default()
.setup(|app| { .setup(|app| {
@@ -12,16 +13,18 @@ fn main() {
{ main_window.open_devtools(); } { main_window.open_devtools(); }
#[cfg(any(windows, target_os = "macos"))] #[cfg(any(windows, target_os = "macos"))]
set_shadow(main_window, true).unwrap() set_shadow(main_window, true).unwrap();
Ok(()) 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!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");
} }
use font_kit::{source::SystemSource}; use font_kit::{source::SystemSource};
use std::collections::HashSet;
#[tauri::command] #[tauri::command]
async fn get_font_list() -> Vec<String> { async fn get_font_list() -> Vec<String> {
@@ -37,28 +40,4 @@ async fn get_font_list() -> Vec<String> {
} }
font_families.into_iter().collect() 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()
}

View File

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