Skip to content

Commit

Permalink
feat: Monitor for disconnect
Browse files Browse the repository at this point in the history
fix #47
  • Loading branch information
PeterStaev committed Jan 27, 2024
1 parent 1b51536 commit d591cab
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## 1.7.1 - 2024-01-27
* Disconnect monitoring (#47)

## 1.7.0 - 2022-04-10
* Multifile support (#58)
* Updated SerialPort dependencies
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "LEGO SPIKE Prime / MINDSTORMS Robot Inventor Extension",
"description": "Helps you connect Lego's SPIKE Prime/MINDSTORMS Robot Inventor",
"publisher": "PeterStaev",
"version": "1.7.0",
"version": "1.7.1",
"engines": {
"vscode": "^1.66.0"
},
Expand Down
13 changes: 6 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function activate(context: vscode.ExtensionContext) {
},
() => rpc.open(),
);
rpc.onClosed.event(() => void updateHubStatusBarItem());

await updateHubStatusBarItem();
showTerminal();
Expand All @@ -91,8 +92,6 @@ export function activate(context: vscode.ExtensionContext) {
},
() => rpc.close(),
);

await updateHubStatusBarItem();
});

const uploadProgramCommand = vscode.commands.registerCommand("lego-spikeprime-mindstorms-vscode.uploadProgram", async () => {
Expand Down Expand Up @@ -332,11 +331,11 @@ async function performUploadProgram(slotId: number, type: "python" | "scratch",
const assembledFile = assembleFile(currentlyOpenTabFileUri.fsPath);

let assembledFilePath;
if (config.get("legoSpikePrimeMindstorms.saveFileToUpload")){
if (config.get("legoSpikePrimeMindstorms.saveFileToUpload")) {
assembledFilePath = path.join(path.dirname(currentlyOpenTabFilePath), currentlyOpenTabFileName + ".assembled.py");
}
else{
assembledFilePath =path.join(os.tmpdir(), currentlyOpenTabFileName + ".assembled.py");
else {
assembledFilePath = path.join(os.tmpdir(), currentlyOpenTabFileName + ".assembled.py");
}

fs.writeFileSync(assembledFilePath, assembledFile, "utf8");
Expand Down Expand Up @@ -535,12 +534,12 @@ function assembleFile(filePath: string): Uint8Array | undefined {

let includePath = match[1] + ".py";
includePath = path.resolve(path.dirname(filePath), includePath);
if(!fs.existsSync(includePath)){
if (!fs.existsSync(includePath)) {
vscode.window.showWarningMessage("File: " + includePath + " not found");
continue;
}
assembledLines.splice(index, 1);
if((includedFiles.some(includedFile => includedFile === includePath)))
if ((includedFiles.some(includedFile => includedFile === includePath)))
continue;
try {
startLine = index;
Expand Down
4 changes: 4 additions & 0 deletions src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Logger } from "./logger";
import { getRandomString } from "./utils";

export class Rpc {
public onClosed: vscode.EventEmitter<void> = new vscode.EventEmitter<void>();
public get isOpenIn(): boolean {
return this._serialPort?.isOpen;
}
Expand Down Expand Up @@ -86,6 +87,9 @@ export class Rpc {
console.error(e);
}
});
this._serialPort.on("close", () => {
this.onClosed.fire();
});
}

public open(): Promise<void> {
Expand Down

0 comments on commit d591cab

Please sign in to comment.