Skip to content

Commit

Permalink
In the clearDevice function, first determine whether there is a devic…
Browse files Browse the repository at this point in the history
…e loaded and then perform the cleanup
  • Loading branch information
zhengyangliu committed Jul 1, 2024
1 parent 5893039 commit 0ea387e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/extension-support/extension-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,19 +378,21 @@ class ExtensionManager {
* Clear curent device
*/
clearDevice () {
this.runtime.disconnectPeripheral(this.runtime.getDevice().deviceId);
if (this.runtime.getDevice().deviceId) {
this.runtime.disconnectPeripheral(this.runtime.getDevice().deviceId);

const deviceId = this.runtime.getDevice().deviceId;
const deviceId = this.runtime.getDevice().deviceId;

this.runtime.clearDevice();
this.runtime.clearMonitor();
this._loadedDevice.clear();
this.runtime.clearDevice();
this.runtime.clearMonitor();
this._loadedDevice.clear();

// Clear current extentions.
this.clearExtensions();
this.clearDeviceExtension();
// Clear current extentions.
this.clearExtensions();
this.clearDeviceExtension();

this.runtime.emit(this.runtime.constructor.SCRATCH_EXTENSION_REMOVED, {deviceId});
this.runtime.emit(this.runtime.constructor.SCRATCH_EXTENSION_REMOVED, {deviceId});
}
}

/**
Expand Down

0 comments on commit 0ea387e

Please # to comment.