-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: paulober <[email protected]>
- Loading branch information
Showing
5 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { CommandWithResult } from "./command.mjs"; | ||
import Logger from "../logger.mjs"; | ||
import { tasks, window } from "vscode"; | ||
import { EventEmitter } from "stream"; | ||
|
||
export default class FlashProjectSWDCommand extends CommandWithResult<boolean> { | ||
private _logger: Logger = new Logger("FlashProjectSWDCommand"); | ||
|
||
public static readonly id = "flashProject"; | ||
|
||
constructor() { | ||
super(FlashProjectSWDCommand.id); | ||
} | ||
|
||
async execute(): Promise<boolean> { | ||
this._logger.info("Executing flash task..."); | ||
|
||
// Get the task with the specified name | ||
const task = (await tasks.fetchTasks()).find(task => task.name === "Flash"); | ||
|
||
if (task) { | ||
// Execute the task | ||
const emitter = new EventEmitter(); | ||
|
||
// add callbacks for task completion | ||
const end = tasks.onDidEndTaskProcess(e => { | ||
if (e.execution.task === task) { | ||
emitter.emit( | ||
"terminated", | ||
e.exitCode === undefined ? -1 : e.exitCode | ||
); | ||
} | ||
}); | ||
const end2 = tasks.onDidEndTask(e => { | ||
if (e.execution.task === task) { | ||
emitter.emit("terminated", -1); | ||
} | ||
}); | ||
|
||
const codePromise = new Promise<number>(resolve => { | ||
emitter.on("terminated", code => { | ||
if (typeof code === "number") { | ||
resolve(code); | ||
} else { | ||
resolve(-1); | ||
} | ||
}); | ||
}); | ||
|
||
let code = -1; | ||
try { | ||
await tasks.executeTask(task); | ||
|
||
code = await codePromise; | ||
} finally { | ||
// dispose of callbacks | ||
end.dispose(); | ||
end2.dispose(); | ||
} | ||
|
||
return code === 0; | ||
} else { | ||
// Task not found | ||
this._logger.error("Task 'Flash' not found."); | ||
void window.showErrorMessage("Task 'Flash' not found."); | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters