Cleanup when Obsidian is closed

Hi !

I’m writing a plugin that needs to do some cleanup when Obsidian is closed by the user. I thought onunload would do the trick, but apparently it is not called when Obsidian is closed?

Is there any event or hook my plugin can subscribe to for cleaning up before Obsidian is closed?

Thanks !

But be careful with that, it’s not guaranteed to actually run, and not all of your tasks might be executed.
They might even be killed by the OS.

1 Like

Thank you very much for this !

If it does not run entirely, is it because of some particular exit scenario, like task manager kill?

Or won’t it necessarily be run even if the user simply closes the Obsidian window normally? In this last case would there be more chances to run completely?

Thank you for your time !

Depends on the OS, some automatically kill if the program does not close fast enough on its own.
There is no way to guarantee code being ran on exit.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.