Fix automatic creation and removal of the Firebase autoload singleton
Automatic creation and deletion of the Firebase autoload singleton should not be done on every Godot engine restart; instead, it should be done whenever the plugin is enabled or disabled, which this fix does.
I've tested that _exit_tree() of plugin.gd will always fire when the Godot engine is exited. However, remove_autoload_singleton() does not always fire, which causes some unexpected behavior leading to #270 and https://github.com/AlexDarigan/WAT/issues/314. Ultimately, the singleton should be created when the plugin is enabled, and cleaned up when it is disabled, not on every restart which can interfere with the user's Autoload order.
Hm. Considering we are following what the docs said by using enter and exit tree, I'm wondering if there should be a pull request opened on Godot itself to fix that there as well, or if perhaps this is even a bug in Godot itself. I'll look closer shortly, but this fix seems reasonable, just can't approve yet since I just woke up and am on my phone. 😁
Okay, I've talked to the Godot team briefly about this and they suggest opening an issue against Godot itself and linking to this PR and the related places. I'm going to go ahead and do that, so don't worry about that - and will be leaving this open. I'm worried that the change suggested here will cause memory leaks, but in general something just looks off about the change. It might be correct! I just can't tell, so I figure it's best to go to the experts. It should link back here I think when I do make it, so stay tuned for that.
Just wanted to say, thank you both wonderful people to chatting across plugins and chatting with the Godot team! Much appreciated.
It's a sufficiently weird bug that deserves attention! Plus I think @AlexDarigan and especially the WAT plugin are amazing, so it's good to have bugs get fixed and the entire community improved as a result.