-
Notifications
You must be signed in to change notification settings - Fork 1.6k
E16N: move extension manager from VM to Runtime #2243
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
base: e16n
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ const JSZip = require('jszip'); | |
|
||
const Buffer = require('buffer').Buffer; | ||
const centralDispatch = require('./dispatch/central-dispatch'); | ||
const ExtensionManager = require('./extension-support/extension-manager'); | ||
const log = require('./util/log'); | ||
const MathUtil = require('./util/math-util'); | ||
const Runtime = require('./engine/runtime'); | ||
|
@@ -129,7 +128,7 @@ class VirtualMachine extends EventEmitter { | |
this.emit(Runtime.BLOCK_UPDATE, blockId, blockInfo); | ||
}); | ||
this.runtime.on(Runtime.TOOLBOX_EXTENSIONS_NEED_UPDATE, () => { | ||
this.extensionManager.refreshBlocks(); | ||
this.runtime.extensionManager.refreshBlocks(); | ||
}); | ||
this.runtime.on(Runtime.PERIPHERAL_LIST_UPDATE, info => { | ||
this.emit(Runtime.PERIPHERAL_LIST_UPDATE, info); | ||
|
@@ -159,11 +158,9 @@ class VirtualMachine extends EventEmitter { | |
this.emit(Runtime.HAS_CLOUD_DATA_UPDATE, hasCloudData); | ||
}); | ||
|
||
this.extensionManager = new ExtensionManager(this.runtime); | ||
|
||
// Load core extensions | ||
for (const id of CORE_EXTENSIONS) { | ||
this.extensionManager.loadExtensionIdSync(id); | ||
this.runtime.extensionManager.loadExtensionIdSync(id); | ||
} | ||
|
||
this.blockListener = this.blockListener.bind(this); | ||
|
@@ -172,6 +169,14 @@ class VirtualMachine extends EventEmitter { | |
this.variableListener = this.variableListener.bind(this); | ||
} | ||
|
||
/** | ||
* @returns {ExtensionManager} the extension manager, now owned by the runtime. | ||
* @deprecated Please access the extension manager through the runtime instead. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could also log this warning if it's accessed this way so we can find places we've missed in our own code. Although I wonder if we care/want that? Seems like accessing via VM from the outside could be seen as the right thing to do — the VM is the external interface. But internally we refer to the actual location? |
||
*/ | ||
get extensionManager () { | ||
return this.runtime.extensionManager; | ||
} | ||
|
||
/** | ||
* Start running the VM - do this before anything else. | ||
*/ | ||
|
@@ -509,9 +514,9 @@ class VirtualMachine extends EventEmitter { | |
const extensionPromises = []; | ||
|
||
extensions.extensionIDs.forEach(extensionID => { | ||
if (!this.extensionManager.isExtensionLoaded(extensionID)) { | ||
if (!this.runtime.extensionManager.isExtensionLoaded(extensionID)) { | ||
const extensionURL = extensions.extensionURLs.get(extensionID) || extensionID; | ||
extensionPromises.push(this.extensionManager.loadExtensionURL(extensionURL)); | ||
extensionPromises.push(this.runtime.extensionManager.loadExtensionURL(extensionURL)); | ||
} | ||
}); | ||
|
||
|
@@ -1128,7 +1133,7 @@ class VirtualMachine extends EventEmitter { | |
if (locale !== formatMessage.setup().locale) { | ||
formatMessage.setup({locale: locale, translations: {[locale]: messages}}); | ||
} | ||
return this.extensionManager.refreshBlocks(); | ||
return this.runtime.extensionManager.refreshBlocks(); | ||
} | ||
|
||
/** | ||
|
@@ -1231,12 +1236,12 @@ class VirtualMachine extends EventEmitter { | |
const extensionIDs = new Set(copiedBlocks | ||
.map(b => sb3.getExtensionIdForOpcode(b.opcode)) | ||
.filter(id => !!id) // Remove ids that do not exist | ||
.filter(id => !this.extensionManager.isExtensionLoaded(id)) // and remove loaded extensions | ||
.filter(id => !this.runtime.extensionManager.isExtensionLoaded(id)) // and remove loaded extensions | ||
); | ||
|
||
// Create an array promises for extensions to load | ||
const extensionPromises = Array.from(extensionIDs, | ||
id => this.extensionManager.loadExtensionURL(id) | ||
id => this.runtime.extensionManager.loadExtensionURL(id) | ||
); | ||
|
||
return Promise.all(extensionPromises).then(() => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's no longer to bubble this event all the way up to the VM anymore. We could either remove the event all together or just have the runtime listen and handle its own event since it also owns the extensionManager.