[Update/TMP] Hotkey Alt+Y will active VRCT when VRChat is the active window.
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
// 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| {
|
||||
@@ -13,18 +12,16 @@ 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])
|
||||
.invoke_handler(tauri::generate_handler![get_font_list, get_active_window_title])
|
||||
.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> {
|
||||
@@ -41,3 +38,27 @@ 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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user