Skip to content

Commit

Permalink
Merge pull request #2 from Snail-IDE-Dev/develop
Browse files Browse the repository at this point in the history
removeextension
  • Loading branch information
dumorando authored Apr 28, 2024
2 parents 17f0fc8 + c083eb7 commit dad671f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,23 @@ class Runtime extends EventEmitter {
}
}

_removeExtensionPrimitive(extensionId) {
const extIdx = this._blockInfo.findIndex(ext => ext.id === extensionId);
const info = this._blockInfo[extIdx];
this._blockInfo.splice(extIdx, 1);
this.emit(Runtime.EXTENSION_REMOVED);
// cleanup blocks
for (const target of this.targets) {
for (const blockId in target.blocks._blocks) {
const {opcode} = target.blocks.getBlock(blockId);
if (info.blocks.find(block => block.json?.type === opcode)) {
target.blocks.deleteBlock(blockId, true);
}
}
}
this.emit(Runtime.BLOCKS_NEED_UPDATE);
}

/**
* Read extension information, convert menus, blocks and custom field types
* and store the results in the provided category object.
Expand Down
13 changes: 13 additions & 0 deletions src/extension-support/extension-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,19 @@ class ExtensionManager {
}).catch(error => this._failedLoadingExtensionScript(error));
}

removeExtension(id) {
const serviceName = this._loadedExtensions.get(id);
dispatch.call(serviceName, 'dispose');
delete dispatch.services[serviceName];
delete this.runtime[`ext_${id}`];

this._loadedExtensions.delete(id);
const workerId = +serviceName.split('.')[1];
delete this.workerURLs[workerId];
dispatch.call('runtime', '_removeExtensionPrimitive', id);
this.refreshBlocks();
}

/**
* Wait until all async extensions have loaded
* @returns {Promise} resolved when all async extensions have loaded
Expand Down
1 change: 1 addition & 0 deletions src/virtual-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const createRuntimeService = runtime => {
const service = {};
service._refreshExtensionPrimitives = runtime._refreshExtensionPrimitives.bind(runtime);
service._registerExtensionPrimitives = runtime._registerExtensionPrimitives.bind(runtime);
service._removeExtensionPrimitive = runtime._removeExtensionPrimitive.bind(runtime);
return service;
};

Expand Down

0 comments on commit dad671f

Please sign in to comment.