mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-16 11:37:47 +01:00
fix: fix the focusing problem of the input box in windows (#481)
This commit is contained in:
46
src-tauri/Cargo.lock
generated
46
src-tauri/Cargo.lock
generated
@@ -790,6 +790,7 @@ dependencies = [
|
|||||||
"base64 0.13.1",
|
"base64 0.13.1",
|
||||||
"chinese-number",
|
"chinese-number",
|
||||||
"dirs 5.0.1",
|
"dirs 5.0.1",
|
||||||
|
"enigo",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"futures",
|
"futures",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
@@ -1497,6 +1498,25 @@ version = "1.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a3d8a32ae18130a3c84dd492d4215c3d913c3b07c6b63c2eb3eb7ff1101ab7bf"
|
checksum = "a3d8a32ae18130a3c84dd492d4215c3d913c3b07c6b63c2eb3eb7ff1101ab7bf"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "enigo"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0cf6f550bbbdd5fe66f39d429cb2604bcdacbf00dca0f5bbe2e9306a0009b7c6"
|
||||||
|
dependencies = [
|
||||||
|
"core-foundation 0.10.0",
|
||||||
|
"core-graphics 0.24.0",
|
||||||
|
"foreign-types-shared 0.3.1",
|
||||||
|
"libc",
|
||||||
|
"log",
|
||||||
|
"objc2 0.5.2",
|
||||||
|
"objc2-app-kit 0.2.2",
|
||||||
|
"objc2-foundation 0.2.2",
|
||||||
|
"windows 0.58.0",
|
||||||
|
"xkbcommon",
|
||||||
|
"xkeysym",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "enum-ordinalize"
|
name = "enum-ordinalize"
|
||||||
version = "4.3.0"
|
version = "4.3.0"
|
||||||
@@ -3304,6 +3324,15 @@ version = "2.7.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memmap2"
|
||||||
|
version = "0.9.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memoffset"
|
name = "memoffset"
|
||||||
version = "0.9.1"
|
version = "0.9.1"
|
||||||
@@ -8047,6 +8076,23 @@ dependencies = [
|
|||||||
"tini",
|
"tini",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "xkbcommon"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8d66ca9352cbd4eecbbc40871d8a11b4ac8107cfc528a6e14d7c19c69d0e1ac9"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"memmap2",
|
||||||
|
"xkeysym",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "xkeysym"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yaml-rust"
|
name = "yaml-rust"
|
||||||
version = "0.4.5"
|
version = "0.4.5"
|
||||||
|
|||||||
@@ -81,7 +81,6 @@ tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", branch = "v2"
|
|||||||
[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\"))".dependencies]
|
[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\"))".dependencies]
|
||||||
tauri-plugin-single-instance = { version = "2.0.0", features = ["deep-link"] }
|
tauri-plugin-single-instance = { version = "2.0.0", features = ["deep-link"] }
|
||||||
|
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
incremental = true # Compile your binary in smaller steps.
|
incremental = true # Compile your binary in smaller steps.
|
||||||
|
|
||||||
@@ -96,3 +95,6 @@ strip = true # Ensures debug symbols are removed.
|
|||||||
tauri-plugin-autostart = "^2.2"
|
tauri-plugin-autostart = "^2.2"
|
||||||
tauri-plugin-global-shortcut = "2"
|
tauri-plugin-global-shortcut = "2"
|
||||||
tauri-plugin-updater = { git = "https://github.com/infinilabs/plugins-workspace", branch = "v2" }
|
tauri-plugin-updater = { git = "https://github.com/infinilabs/plugins-workspace", branch = "v2" }
|
||||||
|
|
||||||
|
[target."cfg(target_os = \"windows\")".dependencies]
|
||||||
|
enigo="0.3"
|
||||||
|
|||||||
@@ -137,7 +137,8 @@ pub fn run() {
|
|||||||
local::application::get_default_search_paths,
|
local::application::get_default_search_paths,
|
||||||
local::application::list_app_with_metadata_in,
|
local::application::list_app_with_metadata_in,
|
||||||
util::open,
|
util::open,
|
||||||
server::system_settings::get_system_settings
|
server::system_settings::get_system_settings,
|
||||||
|
simulate_mouse_click
|
||||||
])
|
])
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
let registry = SearchSourceRegistry::default();
|
let registry = SearchSourceRegistry::default();
|
||||||
@@ -251,13 +252,13 @@ async fn init_app_search_source<R: Runtime>(app_handle: &AppHandle<R>) -> Result
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn show_coco<R: Runtime>(app_handle: AppHandle<R>) {
|
async fn show_coco<R: Runtime>(app_handle: AppHandle<R>) {
|
||||||
if let Some(window) = app_handle.get_window(MAIN_WINDOW_LABEL) {
|
if let Some(window) = app_handle.get_window(MAIN_WINDOW_LABEL) {
|
||||||
let _ = app_handle.emit("show-coco", ());
|
|
||||||
|
|
||||||
move_window_to_active_monitor(&window);
|
move_window_to_active_monitor(&window);
|
||||||
|
|
||||||
let _ = window.show();
|
let _ = window.show();
|
||||||
let _ = window.unminimize();
|
let _ = window.unminimize();
|
||||||
let _ = window.set_focus();
|
let _ = window.set_focus();
|
||||||
|
|
||||||
|
let _ = app_handle.emit("show-coco", ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,3 +413,49 @@ async fn get_app_search_source<R: Runtime>(app_handle: AppHandle<R>) -> Result<(
|
|||||||
async fn show_settings(app_handle: AppHandle) {
|
async fn show_settings(app_handle: AppHandle) {
|
||||||
open_settings(&app_handle);
|
open_settings(&app_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn simulate_mouse_click<R: Runtime>(window: WebviewWindow<R>, is_chat_mode: bool) {
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
use enigo::{Button, Coordinate, Direction, Enigo, Mouse, Settings};
|
||||||
|
use std::{thread, time::Duration};
|
||||||
|
|
||||||
|
if let Ok(mut enigo) = Enigo::new(&Settings::default()) {
|
||||||
|
// Save the current mouse position
|
||||||
|
if let Ok((original_x, original_y)) = enigo.location() {
|
||||||
|
// Retrieve the window's outer position (top-left corner)
|
||||||
|
if let Ok(position) = window.outer_position() {
|
||||||
|
// Retrieve the window's inner size (client area)
|
||||||
|
if let Ok(size) = window.inner_size() {
|
||||||
|
// Calculate the center position of the title bar
|
||||||
|
let x = position.x + (size.width as i32 / 2);
|
||||||
|
let y = if is_chat_mode {
|
||||||
|
position.y + size.height as i32 - 50
|
||||||
|
} else {
|
||||||
|
position.y + 30
|
||||||
|
};
|
||||||
|
|
||||||
|
// Move the mouse cursor to the calculated position
|
||||||
|
if enigo.move_mouse(x, y, Coordinate::Abs).is_ok() {
|
||||||
|
// // Simulate a left mouse click
|
||||||
|
let _ = enigo.button(Button::Left, Direction::Click);
|
||||||
|
// let _ = enigo.button(Button::Left, Direction::Release);
|
||||||
|
|
||||||
|
thread::sleep(Duration::from_millis(100));
|
||||||
|
|
||||||
|
// Move the mouse cursor back to the original position
|
||||||
|
let _ = enigo.move_mouse(original_x, original_y, Coordinate::Abs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
{
|
||||||
|
let _ = window;
|
||||||
|
let _ = is_chat_mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -90,10 +90,23 @@ function SearchChat({
|
|||||||
|
|
||||||
const setTheme = useThemeStore((state) => state.setTheme);
|
const setTheme = useThemeStore((state) => state.setTheme);
|
||||||
|
|
||||||
|
const isChatModeRef = useRef(false);
|
||||||
|
useEffect(() => {
|
||||||
|
isChatModeRef.current = isChatMode;
|
||||||
|
}, [isChatMode]);
|
||||||
|
|
||||||
useMount(async () => {
|
useMount(async () => {
|
||||||
const isWin10 = await platformAdapter.isWindows10();
|
const isWin10 = await platformAdapter.isWindows10();
|
||||||
|
|
||||||
setIsWin10(isWin10);
|
setIsWin10(isWin10);
|
||||||
|
|
||||||
|
platformAdapter.listenEvent("show-coco", () => {
|
||||||
|
console.log("show-coco");
|
||||||
|
|
||||||
|
platformAdapter.invokeBackend("simulate_mouse_click", {
|
||||||
|
isChatMode: isChatModeRef.current,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user