Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the addon should update only when changes happens in the addons folder #21

Open
WhalesState opened this issue Jan 24, 2022 · 2 comments

Comments

@WhalesState
Copy link

WhalesState commented Jan 24, 2022

We are listing the addons directory and running a while loop to get each folder and we check if it has a plugin.cfg file and we update the options button and we save cfg file

the problem is, FileSystem emits filesystem_changed whenever any file changes like when you save your project or importing assets .. etc, we need to make it only check if the changes happens inside the addons folder.

i was thinking about many ways , to check if files size changed ? last modified date ?

then how ?

the only way i can find since directories don't have last modified date is that we list the addons directory and we check the names of the folders if it doesn't exist in our plugins dictionary then we refresh, if the folders are the same, then we return.

this will produce only one issue, if someone removed an addon folder from the OS filesystem and added another folder with the same name but different contents and returned back to godot. because godot will not emit the signal until the user focus the godot window. and the while loop will not recognize any changes so it will keep the old addon information.

if we made this enhancement then we should add this as a warning in the README file.

@WhalesState
Copy link
Author

WhalesState commented Jan 24, 2022

a better approach is to wait one frame when the filesystem signal emits and we get the plugins information from the project settings instead of listing the addons directory, since godot already do it in the same frame.

@willnationsdev
Copy link
Member

willnationsdev commented Dec 9, 2024

the problem is, FileSystem emits filesystem_changed whenever any file changes like when you save your project or importing assets .. etc, we need to make it only check if the changes happens inside the addons folder.

I agree that the work seems unnecessary, especially now that #33 is merged and we are effectively doing a recursive directory search for plugin.cfg files rather than just checking one directory.

we list the addons directory and we check the names of the folders if it doesn't exist in our plugins dictionary then we refresh, if the folders are the same, then we return.

This technically is an approach that runs the (extremely low, but still existing) risk of our data suddenly becoming out of sync with the editor's in-memory data if, say, someone decided to keep the directory around, but deleted the plugin.cfg file. Godot's API would recognize that the plugin no longer exists, but our "cached" state would imply that it's still there, error whenever you try to interact with it, and then not fix itself until you restarted the Godot editor or something. And ultimately, the File I/O being a necessary part anyway doesn't make it that much better to me.

a better approach is to wait one frame when the filesystem signal emits and we get the plugins information from the project settings

Aye! I agree heartily, and in truth, 'twas exactly my hope when I first wrote this plugin 6 years ago. Alas, the project.godot file only stores which plugins have been enabled, not which plugins exist 🙄 , and thus, all plugins that are currently disabled would suddenly cease to show up in our options list. Now, one might argue that is desirable, but I certainly prefer to have everything appear and just confirm with the user that "refreshing" it will in fact enable it. Thus far no one has reported any desire to make that configurable. So we're stuck with the not-so-fun task of re-scanning the filesystem in our own script code.

However you've got me thinking...it might be a simple enough ask to see if we can't add a virtual method callback to the EditorPlugin class that notifies plugins when the Editor's in-memory plugin list changes & reports on which ones were added/removed, enabled/disabled, etc. all in one go.

I'll open a proposal soon. I don't think it'd be all that hard to implement either if folks like the idea.

Edit: And here is the proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants