Add timeout when flashing from the app takes too long (#1070)

This commit is contained in:
Guillaume Jenkins 2018-08-09 18:30:37 -04:00 committed by GitHub
parent f0d14c918e
commit 7537c7561f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -652,7 +652,28 @@ namespace pxt.editor {
}])
if (canHID())
pxt.commands.deployCoreAsync = deployCoreAsync;
pxt.commands.deployCoreAsync = (r: pxtc.CompileResult, d: pxt.commands.DeployOptions): Promise<void> => {
return deployCoreAsync(r)
.timeout(18000)
.catch((e) => {
return previousDapWrapper.reconnectAsync(true)
.catch((e) => {
// Best effort disconnect; at this point we don't even know the state of the device
pxt.reportException(e);
})
.then(() => {
return r.confirmAsync({
header: lf("Something went wrong..."),
body: lf("Flashing your {0} took too long. Please disconnect your {0} from your computer and try reconnecting it.", pxt.appTarget.appTheme.boardName || lf("device")),
disagreeLbl: lf("Ok"),
hideAgree: true
});
})
.then(() => {
return pxt.commands.saveOnlyAsync(r);
});
});
}
res.blocklyPatch = patchBlocks;
return Promise.resolve<pxt.editor.ExtensionResult>(res);