mirror of
https://github.com/0PandaDEV/Qopy.git
synced 2025-04-21 13:14:04 +02:00
focus test
This commit is contained in:
parent
a11bc18143
commit
bae359f1cf
4 changed files with 14 additions and 36 deletions
3
app.vue
3
app.vue
|
@ -248,7 +248,6 @@ onMounted(async () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await listen('tauri://blur', hideApp);
|
|
||||||
await listen('tauri://focus', focusSearchInput);
|
await listen('tauri://focus', focusSearchInput);
|
||||||
focusSearchInput();
|
focusSearchInput();
|
||||||
|
|
||||||
|
@ -262,7 +261,7 @@ onMounted(async () => {
|
||||||
|
|
||||||
const hideApp = async () => {
|
const hideApp = async () => {
|
||||||
await app.hide();
|
await app.hide();
|
||||||
await window.getCurrent().hide();
|
await window.getCurrentWindow().hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
const showApp = async () => {
|
const showApp = async () => {
|
||||||
|
|
16
src-tauri/Cargo.lock
generated
16
src-tauri/Cargo.lock
generated
|
@ -3240,7 +3240,6 @@ dependencies = [
|
||||||
"tauri-plugin-global-shortcut",
|
"tauri-plugin-global-shortcut",
|
||||||
"tauri-plugin-os",
|
"tauri-plugin-os",
|
||||||
"tauri-plugin-sql",
|
"tauri-plugin-sql",
|
||||||
"tauri-plugin-window-state",
|
|
||||||
"tokio",
|
"tokio",
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
@ -4744,21 +4743,6 @@ dependencies = [
|
||||||
"tokio",
|
"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]]
|
[[package]]
|
||||||
name = "tauri-runtime"
|
name = "tauri-runtime"
|
||||||
version = "2.0.0-beta.19"
|
version = "2.0.0-beta.19"
|
||||||
|
|
|
@ -11,7 +11,6 @@ tauri-build = { version = "2.0.0-beta.18", features = [] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tauri = { version = "2.0.0-beta.23", features = ["unstable", "tray-icon", "image-png"] }
|
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-sql = {version = "2.0.0-beta.8", features = ["sqlite"] }
|
||||||
tauri-plugin-clipboard-manager = "2.1.0-beta.5"
|
tauri-plugin-clipboard-manager = "2.1.0-beta.5"
|
||||||
tauri-plugin-global-shortcut = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
tauri-plugin-global-shortcut = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
||||||
|
|
|
@ -11,7 +11,6 @@ mod tray;
|
||||||
use tauri::Manager;
|
use tauri::Manager;
|
||||||
use tauri::PhysicalPosition;
|
use tauri::PhysicalPosition;
|
||||||
use tauri_plugin_autostart::MacosLauncher;
|
use tauri_plugin_autostart::MacosLauncher;
|
||||||
use tauri_plugin_window_state::{AppHandleExt, StateFlags, WindowExt};
|
|
||||||
|
|
||||||
fn center_window_on_current_monitor(window: &tauri::Window) {
|
fn center_window_on_current_monitor(window: &tauri::Window) {
|
||||||
if let Some(monitor) = window.current_monitor().unwrap() {
|
if let Some(monitor) = window.current_monitor().unwrap() {
|
||||||
|
@ -33,7 +32,6 @@ fn main() {
|
||||||
.plugin(tauri_plugin_clipboard_manager::init())
|
.plugin(tauri_plugin_clipboard_manager::init())
|
||||||
.plugin(tauri_plugin_os::init())
|
.plugin(tauri_plugin_os::init())
|
||||||
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
|
.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_sql::Builder::default().build())
|
||||||
.plugin(tauri_plugin_autostart::init(
|
.plugin(tauri_plugin_autostart::init(
|
||||||
MacosLauncher::LaunchAgent,
|
MacosLauncher::LaunchAgent,
|
||||||
|
@ -48,30 +46,28 @@ fn main() {
|
||||||
clipboard::setup(app_handle);
|
clipboard::setup(app_handle);
|
||||||
|
|
||||||
if let Some(window) = app.get_window("main") {
|
if let Some(window) = app.get_window("main") {
|
||||||
let _ = window.restore_state(StateFlags::POSITION);
|
|
||||||
center_window_on_current_monitor(&window);
|
center_window_on_current_monitor(&window);
|
||||||
window.hide().unwrap();
|
window.hide().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[cfg(dev)]
|
#[cfg(dev)]
|
||||||
// {
|
{
|
||||||
// let window = app.get_webview_window("main").unwrap();
|
let window = app.get_webview_window("main").unwrap();
|
||||||
// window.open_devtools();
|
window.open_devtools();
|
||||||
// window.close_devtools();
|
window.close_devtools();
|
||||||
// }
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.on_window_event(|app, event| match event {
|
.on_window_event(|app, event| match event {
|
||||||
tauri::WindowEvent::CloseRequested { .. }
|
tauri::WindowEvent::Focused(false) => {
|
||||||
| tauri::WindowEvent::Destroyed
|
println!("Window lost focus");
|
||||||
| tauri::WindowEvent::Focused(false) => {
|
if let Some(window) = app.get_window("main") {
|
||||||
let _ = AppHandleExt::save_window_state(app.app_handle(), StateFlags::POSITION);
|
window.hide().unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tauri::WindowEvent::Focused(true) => {
|
tauri::WindowEvent::Focused(true) => {
|
||||||
if let Some(window) = app.get_window("main") {
|
println!("Window gained focus");
|
||||||
center_window_on_current_monitor(&window);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue