tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
85.53k stars 2.58k forks source link

[bug] Specifying `focus` window config to false in Tauri config cannot disable focus on startup under Windows #11566

Closed geezmolycos closed 3 weeks ago

geezmolycos commented 3 weeks ago

Describe the bug

In Tauri config file, there is a focus option in window configuration, which supposedly specifies the focus state when the window is initially created. However, the current behaviour is no matter it's set to true or false in the config file, when the dev server starts, the program always gain focus. Setting this to false is the same as true.

If instead, remove the windows object from config file and use Rust to create window with WebviewWindowBuilder, the window can be set to not focus when created with .focused(false), and setting config file should have the same effect, which is not the case.

Reproduction

  1. Create a test project with pnpm create tauri-app
  2. Choose some sane defaults
  3. Install dependencies with pnpm install, run the dev server. The default config should focus the window when launched
  4. Change the windows config as follows:
      "windows": [
      {
        "title": "tauri-app",
        "width": 800,
        "height": 600,
        "focus": false
      }
    ],
  5. Restart the server, the app window still get focused despite the config is set to false

Expected behavior

Window should not be focused when focused is set to false.

It should be the same as created manually with:

    tauri::Builder::default()
        .plugin(tauri_plugin_shell::init())
        .invoke_handler(tauri::generate_handler![greet])
        .setup(|app| {
            let 
            _webview_window = tauri::WebviewWindowBuilder::new(app, "label", tauri::WebviewUrl::App("index.html".into())).focused(false)
            .build()?;
            Ok(())
        })
        .run(tauri::generate_context!())
        .expect("error while running tauri application");

Full tauri info output

> tauri-app@0.1.0 tauri D:\work\tauri-app
> tauri "info"

[✔] Environment
    - OS: Windows 10.0.19045 x86_64 (X64)
    ✔ WebView2: 130.0.2849.56
    ✔ MSVC: Visual Studio Build Tools 2019
    ✔ rustc: 1.82.0 (f6e511eec 2024-10-15)
    ✔ cargo: 1.82.0 (8f40fc59f 2024-08-21)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 22.6.0
    - pnpm: 9.12.2
    - npm: 10.8.0

[-] Packages
    - tauri 🦀: 2.0.6
    - tauri-build 🦀: 2.0.2   
    - wry 🦀: 0.46.3
    - tao 🦀: 0.30.5
    - @tauri-apps/api : 2.0.3
    - @tauri-apps/cli : 2.0.5

[-] Plugins
    - tauri-plugin-shell 🦀: 2.0.2     
    - @tauri-apps/plugin-shell : 2.0.1

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - bundler: Vite

Stack trace

(none)

Additional context

No response

amrbashir commented 3 weeks ago

fixed by #11569