Open vemonet opened 3 weeks ago
I can reproduce this bug. Actually, the App is focused. So, for vanilla JS template, I performed the following steps:
greet();
in JS file, inside the window.addEventListener("DOMContentLoaded")
like this, so that greet()
is called as soon as DOM is loaded. Also, add Escape
keypress event.window.addEventListener("DOMContentLoaded", () => {
greetInputEl = document.querySelector("#greet-input");
greetMsgEl = document.querySelector("#greet-msg");
greet();
});
document.addEventListener('keypress', (event) => {
if (event.code === 'Escape'){
greet()
}
})
greet()
in main.rs
to print is_focused()
for each webview_window()
.#[tauri::command]
fn greet(app: tauri::AppHandle ,name: &str) -> String {
for i in app.webview_windows() {
println!("{:?}", i.1.is_focused());
}
format!("Hello, {}! You've been greeted from Rust!", name)
}
Result: It printed Ok(true)
, and App is indeed in focus. However, nothing happens on pressing Escape
, till I click inside the window.
Describe the bug
Hi, I upgraded from v1 to the latest v2 RC, and the window is not focused anymore on creation, even though I have set
focus: true
in thetauri.conf.json
I also added those permissions to the
capabilities/main.json
:Note that tauri v2 docs still mention
focus
in the window config: https://v2.tauri.app/reference/config/#windowconfigReproduction
Relevant project where I use tauri: https://github.com/vemonet/EmojiMart
Minimal repro:
npm create tauri-app@latest -- --rc
tauri.conf.json
src-tauri/capabilities/default.json
src/App.tsx
function App() { // ... onMount(() => { document.addEventListener('keypress', (event: any) => { if (event.code === 'Escape') getCurrentWindow().close() }) }) // ... }
Stack trace
No response
Additional context
No response