[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

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 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<String> {
@@ -37,28 +40,4 @@ async fn get_font_list() -> Vec<String> {
}
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()
}
}