You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[updater] doesn't shutdown app gracefully on Windows #1014
Wait, cleanup_before_exit only cleans up tray icon and resources, it doesn't run the functions listening on Exit event, so things like other plugin's on exit cleanup will not get ran
I'll take a look tomorrow, maybe we just need to also send an Exit event
I guess they will need to also expose a cleanup method that users can call
or maybe change the spec of a tauri plugin to have a cleanup hook so they run cleanup there instead of on Exit event and so tauri cleanup_befor_exit can run that hook
I feel like the clean up hook shouldn't be on the Exit event listener, when you run cleanup_before_exit, you would expect it runs all plugin clean up functions
devs are expected to call app.restart() on macos and linux, right? If so, then this will trigger Exit and ExitRequest so why don't we just call app.exit() on windows which does the same? Maybe we can set some tauri::State so that users can check in ExitRequested why it restarts instead of another clean up hook.
that will make the updater dependent on storing an AppHandle which is not something I am quite fan of, maybe we could instead remove before_exit and replace it with exit_function and fallback to std::process::exit if was not provided.
this is tricky indeed, we can't wait for the installer to send a signal, we should already exit before the installer runs.
I think I am leaning towards keeping the new before_exit hook and recommending users that they should ensure all intermediate work for their app has been saved or cleaned up before calling install or download_and_install, this could include running cleanup methods of plugins (if they provide one).
In addition to that we should look into adding a on_destroy hook for plugins to run their cleanup there and modify app.cleanup_before_exit to run these destroy hooks.
Migrate plugin clean up code (and maybe even app clean up) to a standalone hook would be great
An alternative would be making cleanup_before_exit to send an Exit event
Just took a look on how electron handles it, they seem to be sending a before-quit-for-update event and followed by closing all windows and that triggers a before-quit event
Another popular updater package electron updater will detect running app, and wait for it to exit gracefully for 1 second, and if the app is still running, it just kills it, and the spawning code is similar to
An alternative would be making cleanup_before_exit to send an Exit event
That's not its purpose though
Just took a look on how electron handles it, they seem to be sending a before-quit-for-update event and followed by closing all windows and that triggers a before-quit event
This is similar to the new cleanup_before_exist hook, just as an event
To be honest, I don't know how Chrome and Firefox can apply new updates without closing the app first (they're the most seamless updates I know about), most other programs on Windows can't, even programs like PowerToys, vscode from Microsoft
The focus of that PR itself seems to be on killing the side car tree which I'm not sure a hook on App::cleanup_before_exit would really help, we currently only skip the Exit event in updater plugin's install on Windows which I think it's more of a problem there
I feel like this might be what we would want, if the worry here was mainly about storing AppHandle in the Updater, we could do
maybe we could instead remove before_exit and replace it with exit_function and fallback to std::process::exit if was not provided.
A quick summary of the options here:
Use app.exit here, 2 sub options (no matter the options, this function will return instead of the current behavior which I think it's fine since it matches other platforms here, one thing to note is that if the user's using request_restart here, it might conflict with us as that makes the next exit request spawns a restart instance...):
Spawns the updater before we run app.exit and let the updater wait for the app to exit
Or store the update data in a state, and run it on Exit event (this is hard, since we must ensure we're the last one to run)
Introduce a new method/hook cleanup_before_exit
Good:
We don't have to worry about the Exit event handling
Bad:
We need to ensure the hook to not run plugins that didn't reach initialize yet
Migrate all the plugins and let users know that they should move the clean up code to the new hook
The new hook will run in the thread that calls it, this is not always on main thread nor not on main thread, not sure if it's going to cause problems
Activity
[-]Updater doesn't shutdown app gracefully on Windows[/-][+][updater] doesn't shutdown app gracefully on Windows[/+]Legend-Master commentedon Mar 7, 2024
We probably need to have an API like "on post exit" for it to let the app clean up first and then run the installer/updater
A quick dirty fix would be run
app.exitand run updater on exit event, and make sure we're the last registered plugin...By the way, the updater still shows a powershell window, maybe we should migrate to use
ShellExecuteinsteadamrbashir commentedon Mar 12, 2024
I think we just need to use https://docs.rs/tauri/2.0.0-beta.11/tauri/struct.AppHandle.html#method.cleanup_before_exit
Legend-Master commentedon Mar 12, 2024
Totally forgot it, that should do the job
Legend-Master commentedon Mar 13, 2024
Wait,
cleanup_before_exitonly cleans up tray icon and resources, it doesn't run the functions listening on Exit event, so things like other plugin's on exit cleanup will not get ranI'll take a look tomorrow, maybe we just need to also send an Exit event
amrbashir commentedon Mar 13, 2024
We can't send an exit event, this can only be sent by tauri.
amrbashir commentedon Mar 13, 2024
you should use the new before_exit callback to run your own cleanup
Legend-Master commentedon Mar 13, 2024
So how one could run other plugin's clean up functions?
amrbashir commentedon Mar 13, 2024
I guess they will need to also expose a cleanup method that users can call
or maybe change the spec of a tauri plugin to have a cleanup hook so they run cleanup there instead of on Exit event and so tauri cleanup_befor_exit can run that hook
Legend-Master commentedon Mar 13, 2024
I feel like the clean up hook shouldn't be on the Exit event listener, when you run cleanup_before_exit, you would expect it runs all plugin clean up functions
Legend-Master commentedon Mar 13, 2024
I like the clean up hook idea, if we need to make it, it's better to do it before going stable
FabianLars commentedon Mar 13, 2024
devs are expected to call app.restart() on macos and linux, right? If so, then this will trigger Exit and ExitRequest so why don't we just call app.exit() on windows which does the same? Maybe we can set some tauri::State so that users can check in ExitRequested why it restarts instead of another clean up hook.
amrbashir commentedon Mar 13, 2024
that will make the updater dependent on storing an
AppHandlewhich is not something I am quite fan of, maybe we could instead removebefore_exitand replace it withexit_functionand fallback tostd::process::exitif was not provided.Legend-Master commentedon Mar 14, 2024
Note that the clean up hook need to be run before we run the installer or the installer will kill the app
Maybe we could try to make installer send a signal to the running app and request it to shutdown instead?
Legend-Master commentedon Mar 14, 2024
I'm not sure what triggers an Exit event, I think log out / shutdown Windows doesn't even do it (tested on an app with tray icon and hidden window)
Legend-Master commentedon Mar 14, 2024
Or maybe we do app.exit and wait for it to shutdown itself in the installer?
amrbashir commentedon Mar 14, 2024
this is tricky indeed, we can't wait for the installer to send a signal, we should already exit before the installer runs.
I think I am leaning towards keeping the new
before_exithook and recommending users that they should ensure all intermediate work for their app has been saved or cleaned up before callinginstallordownload_and_install, this could include running cleanup methods of plugins (if they provide one).In addition to that we should look into adding a
on_destroyhook for plugins to run their cleanup there and modifyapp.cleanup_before_exitto run these destroy hooks.Legend-Master commentedon Mar 14, 2024
Migrate plugin clean up code (and maybe even app clean up) to a standalone hook would be great
An alternative would be making
cleanup_before_exitto send anExiteventJust took a look on how electron handles it, they seem to be sending a
before-quit-for-updateevent and followed by closing all windows and that triggers abefore-quiteventAnother popular updater package electron updater will detect running app, and wait for it to exit gracefully for 1 second, and if the app is still running, it just kills it, and the spawning code is similar to
So another alternative would be we call
app.exit(0), and wait for it to shutdown in the installer, similar to #1014 (comment)amrbashir commentedon Mar 14, 2024
That's not its purpose though
This is similar to the new
cleanup_before_existhook, just as an eventLegend-Master commentedon Mar 14, 2024
Migrate to clean up hook
Run
app.exit(0)and make the installer waitSo what do you think?
Legend-Master commentedon Mar 14, 2024
To be honest, I don't know how Chrome and Firefox can apply new updates without closing the app first (they're the most seamless updates I know about), most other programs on Windows can't, even programs like PowerToys, vscode from Microsoft
Legend-Master commentedon Nov 16, 2025
Seeing tauri-apps/tauri#14443 really made me rethink about this again now
The focus of that PR itself seems to be on killing the side car tree which I'm not sure a hook on
App::cleanup_before_exitwould really help, we currently only skip theExitevent in updater plugin'sinstallon Windows which I think it's more of a problem thereI feel like this might be what we would want, if the worry here was mainly about storing
AppHandlein theUpdater, we could doA quick summary of the options here:
app.exithere, 2 sub options (no matter the options, this function will return instead of the current behavior which I think it's fine since it matches other platforms here, one thing to note is that if the user's usingrequest_restarthere, it might conflict with us as that makes the next exit request spawns a restart instance...):app.exitand let the updater wait for the app to exitExitevent (this is hard, since we must ensure we're the last one to run)cleanup_before_exitExitevent handling