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.91k stars 2.6k forks source link

[bug] Background mode does not work in full screen mode #10580

Open gusxodnjs opened 3 months ago

gusxodnjs commented 3 months ago

Describe the bug

After operating the window in full screen mode, hide the window, and run app.prevent_close(), a black screen appears to exit the window.

https://github.com/user-attachments/assets/f18099e2-c735-483d-aeb5-f871e8e73c1b

Reproduction

https://github.com/gusxodnjs/tauri-issues/tree/bug/background

// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

fn main() {
    tauri::Builder::default().on_window_event(|window, event| match event {
        tauri::WindowEvent::CloseRequested { api, .. } => {
          window.hide().unwrap();
          api.prevent_close();
        }
        _ => {}
      })
      .run(tauri::generate_context!())
      .expect("error while running tauri application");
}

Expected behavior

The window should be hidden and the desktop should be displayed.

Full tauri info output

[✔] Environment
    - OS: Mac OS 13.5.2 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.80.1 (3f5fd8dd4 2024-08-06)
    ✔ cargo: 1.80.1 (376290515 2024-07-16)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 18.18.2
    - yarn: 1.22.21
    - npm: 9.8.1

[-] Packages
    - tauri [RUST]: 2.0.0-rc.2
    - tauri-build [RUST]: 2.0.0-rc.2
    - wry [RUST]: 0.41.0
    - tao [RUST]: 0.28.1
    - tauri-cli [RUST]: 2.0.0-alpha.18
    - @tauri-apps/api [NPM]: 2.0.0-rc.0
    - @tauri-apps/cli [NPM]: 2.0.0-rc.3

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: React
    - bundler: Vite
✨  Done in 6.84s.

Stack trace

No response

Additional context

No response

gusxodnjs commented 3 months ago

@amrbashir I'm sorry, but could you please let me know the progress on this issue? I have an important release coming up next month, and I don't even know if this issue is a bug or not. If it's not a bug, I want to know how to bypass it.

pewsheen commented 3 months ago

Hi, can you try if this works by handling the ExitRequest event like in the example:

https://github.com/tauri-apps/tauri/blob/762cf31a113f33cd524c8f6fa52ca47db8ea3705/examples/api/src-tauri/src/lib.rs#L155-L162

gusxodnjs commented 3 months ago

@pewsheen thanks for your comment. I've tried it and it's the same. Even in the example, it seems to be reproduced if you do the hide() instead of the destory() in the CloseRequested event. https://github.com/tauri-apps/tauri/blob/762cf31a113f33cd524c8f6fa52ca47db8ea3705/examples/api/src-tauri/src/lib.rs#L175

pewsheen commented 3 months ago

Usually, we'll just let the window close and recreate a new window when the user clicks the icon on the dock. Or do you have any particular use case? Otherwise, I think the code of the project may suit the scenario https://github.com/thewh1teagle/RustDuck/blob/main/src-tauri/src/runtime.rs

gusxodnjs commented 3 months ago

When I close the main window, I have to run it in the background, so I can't destroy it. When I close the main window, there's no way I can go back from background mode to foreground mode. Doesn't the tray menu disappear when I close the window? Also, since I log in from the main window, I need to stay in the window state.

So hide the main window without closing it.

In my case, when I exit the main window, the only way is turn off full screen mode is . How about this?