Closed thesamim closed 7 months ago
The difference between ctrl-r and hot reload is that hot reload unloads the existing plugin before loading it again. So any plugin shutdown code runs. When you use ctrl-r, your shutdown code does not run, but (almost) everything is shut down forcibly, including many (but not all) electron resources.
(In my own experience with browserwindow and Obsidian, I found I needed to have my plugin unload code explicitly close any custom browserwindows I created that are still open.)
In general, to work with hot-reload, your plugin needs to have proper unload handling, which means that it should shut down or undo everything that it is doing at the time it's unloaded, or it runs the risk of leaving Obsidian in a corrupted state. If you're using the electron API directly, that usually means being sure to unregister things, close them, etc. when the plugin as a whole is shut down.
You can confirm this for yourself by manually disabling and enabling your plugin instead of using hot-reload -- you will get the same error, unless of course you have to close your extra window in order to do the manual disable/enable. Hot reload just automates flicking on and off the toggle switch for your plugin in the community plugins list.
Thanks for the explanation.
I'm probably doing something wrong.
I have a modal in my window. Launched from my settings. When the plugin reloads after changes, and I try to launch the modal again I get:
I instantiate with:
const window = new BrowserWindow({ show: false,{ show: false,[...]});
In the on close method I end with:
window.destroy();
What should I be doing to reload correctly? (Incidentally: if I force a reload with Ctrl-R in the console window, it works fine.)