tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] msi installer hangs not being able to close running application

Open fogine opened this issue 2 years ago • 1 comments

Describe the bug

Builded msi installer gives the users option to Close applications and attempt to restart them (usually the conflicting application is the one the user is reinstalling/updating).

MSI installer has been able to close the application up until recently when I started to subscribe to app close request events. I'm aware that unlisten should be called after component is unmouted but still, when I call appWindow.onCloseRequested in the running application and execute msi installer, it hangs on not being able to close the running application, at that point it is neither possible to close msi installer nor the running application (only option is to kill them in process manager).

    import { appWindow } from "@tauri-apps/api/window";

    //component hooks
    async mounted() {
  
        this.unlisten = await appWindow.onCloseRequested(async (event) => {
           
                    //In addition to unlistening in unmounted hook,
                    //I tried calling unlisten just before application is about to be closed as well
                    if (this.unlisten) {
                        this.unlisten();
                    }

        });
    },
    async unmounted() {
        if (this.unlisten) {
            this.unlisten();
        }
    },

On the rust side, I initialize the app like this

fn main() {
    tauri::Builder::default()
        .manage(GuiState::new())
        .invoke_handler(tauri::generate_handler![
            //commands
        ])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

bds_install image

Reproduction

No response

Expected behavior

No response

Platform and versions

Environment › OS: Windows 10.0.19043 X64 › Webview2: 104.0.1293.63 › MSVC: - Visual Studio Build Tools 2019 › Node.js: 16.11.0 › npm: 8.0.0 › pnpm: Not installed! › yarn: 1.22.19 › rustup: 1.25.1 › rustc: 1.63.0 › cargo: 1.63.0 › Rust toolchain: stable-x86_64-pc-windows-msvc Packages › @tauri-apps/cli [NPM]: 1.0.5 › @tauri-apps/api [NPM]: 1.0.2 › tauri [RUST]: 1.0.5, › tauri-build [RUST]: 1.0.4, › tao [RUST]: 0.12.1, › wry [RUST]: 0.19.0, App › build-type: bundle › CSP: unset › distDir: Set automatically by Vue CLI plugin › devPath: Set automatically by Vue CLI plugin › framework: Vue.js (Vue CLI) › bundler: Webpack App directory structure ├─ .git ├─ bds ├─ node_modules ├─ public ├─ src └─ src-tauri Done in 10.30s.

Stack trace

No response

Additional context

No response

fogine avatar Aug 24 '22 13:08 fogine

I've just run into something similar - if I listen for tauri::WindowEvent::CloseRequested in rust, and call api.prevent_close(), it prevents the installer from closing the app. As far as I can tell there's no real way for me to know that the CloseRequested came from an external process vs. the user closing the window (which is supposed to just hide it).

I believe this is because Tauri (and Tao underneath it), is not handling the Windows RestartManager's WM_ENDSESSION: https://learn.microsoft.com/en-us/windows/win32/rstmgr/guidelines-for-applications

It's possible to test this without building/running the installer with this C++ app from MS: https://github.com/microsoft/Windows-classic-samples/tree/main/Samples/Win7Samples/winbase/restartmanager/rmfilterapp You just replace these lines in https://github.com/microsoft/Windows-classic-samples/blob/main/Samples/Win7Samples/winbase/restartmanager/rmfilterapp/RmFilterApp/rmfilterapp.cpp:

LR"(C:\Windows\explorer.exe)",
LR"(C:\Windows\notepad.exe)",
LR"(C:\Windows\system32\notepad.exe)",
LR"(C:\Windows\SysWow64\notepad.exe)",

with a single line that has the full path to the executable.

jfaust avatar Feb 14 '24 04:02 jfaust