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

Automatically enable newly-installed plugins #94481

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions editor/editor_asset_installer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ void EditorAssetInstaller::ok_pressed() {
}

void EditorAssetInstaller::_install_asset() {
Vector<String> plugins;
Ref<FileAccess> io_fa;
zlib_filefunc_def io = zipio_create_io(&io_fa);

Expand Down Expand Up @@ -553,6 +554,12 @@ void EditorAssetInstaller::_install_asset() {
Ref<FileAccess> f = FileAccess::open(target_path, FileAccess::WRITE);
if (f.is_valid()) {
f->store_buffer(uncomp_data.ptr(), uncomp_data.size());
if (target_path.begins_with("res://addons/")) {
Vector<String> separated = target_path.substr(13).split("/");
if (separated.size() == 2 && separated[1] == "plugin.cfg") {
Copy link
Member

@KoBeWi KoBeWi Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this won't work for addons inside subfolders. Check #91337 to see how it can be done more reliably.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this pointer! I'm happy to see an existing use of the magic number 13 :)

plugins.push_back(target_path);
}
}
} else {
failed_files.push_back(target_path);
}
Expand Down Expand Up @@ -582,9 +589,21 @@ void EditorAssetInstaller::_install_asset() {
}
}

if (failed_files.is_empty() && !plugins.is_empty()) {
Callable sources_changed = callable_mp_static(&EditorAssetInstaller::_script_classes_updated).bind(plugins);

EditorFileSystem::get_singleton()->connect(SNAME("script_classes_updated"), sources_changed, CONNECT_ONE_SHOT);
}

EditorFileSystem::get_singleton()->scan_changes();
}

void EditorAssetInstaller::_script_classes_updated(Vector<String> plugins) {
for (const String &plugin : plugins) {
EditorNode::get_singleton()->set_addon_plugin_enabled(plugin, true, true);
}
}

void EditorAssetInstaller::set_asset_name(const String &p_asset_name) {
asset_name = p_asset_name;
}
Expand Down
1 change: 1 addition & 0 deletions editor/editor_asset_installer.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class EditorAssetInstaller : public ConfirmationDialog {
bool _is_item_checked(const String &p_source_path) const;

void _install_asset();
static void _script_classes_updated(Vector<String> plugins);
virtual void ok_pressed() override;

protected:
Expand Down
Loading