focus test

This commit is contained in:
pandadev 2024-07-16 17:40:33 +02:00
parent a11bc18143
commit bae359f1cf
No known key found for this signature in database
GPG key ID: C39629DACB8E762F
4 changed files with 14 additions and 36 deletions

View file

@ -248,7 +248,6 @@ onMounted(async () => {
}
});
await listen('tauri://blur', hideApp);
await listen('tauri://focus', focusSearchInput);
focusSearchInput();
@ -262,7 +261,7 @@ onMounted(async () => {
const hideApp = async () => {
await app.hide();
await window.getCurrent().hide();
await window.getCurrentWindow().hide();
};
const showApp = async () => {

16
src-tauri/Cargo.lock generated
View file

@ -3240,7 +3240,6 @@ dependencies = [
"tauri-plugin-global-shortcut",
"tauri-plugin-os",
"tauri-plugin-sql",
"tauri-plugin-window-state",
"tokio",
"url",
]
@ -4744,21 +4743,6 @@ dependencies = [
"tokio",
]
[[package]]
name = "tauri-plugin-window-state"
version = "2.0.0-beta.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbfc2be8b130fcba31930e862aa04cce60676a60417d76759a0607c917825a06"
dependencies = [
"bitflags 2.6.0",
"log",
"serde",
"serde_json",
"tauri",
"tauri-plugin",
"thiserror",
]
[[package]]
name = "tauri-runtime"
version = "2.0.0-beta.19"

View file

@ -11,7 +11,6 @@ tauri-build = { version = "2.0.0-beta.18", features = [] }
[dependencies]
tauri = { version = "2.0.0-beta.23", features = ["unstable", "tray-icon", "image-png"] }
tauri-plugin-window-state = "2.0.0-beta.10"
tauri-plugin-sql = {version = "2.0.0-beta.8", features = ["sqlite"] }
tauri-plugin-clipboard-manager = "2.1.0-beta.5"
tauri-plugin-global-shortcut = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }

View file

@ -11,7 +11,6 @@ mod tray;
use tauri::Manager;
use tauri::PhysicalPosition;
use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_window_state::{AppHandleExt, StateFlags, WindowExt};
fn center_window_on_current_monitor(window: &tauri::Window) {
if let Some(monitor) = window.current_monitor().unwrap() {
@ -33,7 +32,6 @@ fn main() {
.plugin(tauri_plugin_clipboard_manager::init())
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
.plugin(tauri_plugin_window_state::Builder::default().build())
.plugin(tauri_plugin_sql::Builder::default().build())
.plugin(tauri_plugin_autostart::init(
MacosLauncher::LaunchAgent,
@ -48,30 +46,28 @@ fn main() {
clipboard::setup(app_handle);
if let Some(window) = app.get_window("main") {
let _ = window.restore_state(StateFlags::POSITION);
center_window_on_current_monitor(&window);
window.hide().unwrap();
}
// #[cfg(dev)]
// {
// let window = app.get_webview_window("main").unwrap();
// window.open_devtools();
// window.close_devtools();
// }
#[cfg(dev)]
{
let window = app.get_webview_window("main").unwrap();
window.open_devtools();
window.close_devtools();
}
Ok(())
})
.on_window_event(|app, event| match event {
tauri::WindowEvent::CloseRequested { .. }
| tauri::WindowEvent::Destroyed
| tauri::WindowEvent::Focused(false) => {
let _ = AppHandleExt::save_window_state(app.app_handle(), StateFlags::POSITION);
tauri::WindowEvent::Focused(false) => {
println!("Window lost focus");
if let Some(window) = app.get_window("main") {
window.hide().unwrap();
}
}
tauri::WindowEvent::Focused(true) => {
if let Some(window) = app.get_window("main") {
center_window_on_current_monitor(&window);
}
println!("Window gained focus");
}
_ => {}
})