[UWP] Fix infinite spin when downloading without device plugged (#1500)

* [UWP] Fix infinite spin when downloading without device plugged

* Undo format changes

* Undo format changes
This commit is contained in:
Guillaume Jenkins 2018-10-23 12:40:24 -04:00 committed by GitHub
parent a7e613c237
commit 52bd7bd146
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -117,16 +117,18 @@ namespace pxt.editor {
reconnectAsync(first: boolean) { reconnectAsync(first: boolean) {
// configure serial at 115200 // configure serial at 115200
if (!first) let p = Promise.resolve();
return this.packetIo.reconnectAsync() if (!first) {
.then(() => this.allocDAP()) p = this.packetIo.reconnectAsync()
.then(() => this.allocDAP());
}
return p
.then(() => this.cortexM.init()) .then(() => this.cortexM.init())
.then(() => this.cmsisdap.cmdNums(0x82, [0x00, 0xC2, 0x01, 0x00])) .then(() => {
.then(() => { }, err => { this.useSerial = false }) return this.cmsisdap.cmdNums(0x82, [0x00, 0xC2, 0x01, 0x00])
else .then(() => { this.useSerial = true }, (err: any) => { this.useSerial = false; });
return this.cortexM.init() });
.then(() => this.cmsisdap.cmdNums(0x82, [0x00, 0xC2, 0x01, 0x00]))
.then(() => { }, err => { this.useSerial = false })
} }
disconnectAsync() { disconnectAsync() {
@ -157,7 +159,8 @@ namespace pxt.editor {
let previousDapWrapper: DAPWrapper; let previousDapWrapper: DAPWrapper;
function dapAsync() { function dapAsync() {
if (previousDapWrapper) if (previousDapWrapper)
return Promise.resolve(previousDapWrapper) return previousDapWrapper.reconnectAsync(false) // Always fully reconnect to handle device unplugged mid-session
.then(() => previousDapWrapper);
return Promise.resolve() return Promise.resolve()
.then(() => { .then(() => {
if (previousDapWrapper) { if (previousDapWrapper) {