Skip to content

Commit

Permalink
Added importOnConnect setting
Browse files Browse the repository at this point in the history
Signed-off-by: paulober <[email protected]>
  • Loading branch information
paulober committed Dec 27, 2023
1 parent 93cf5d0 commit c12df52
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ This extension contributes the following settings:
* `micropico.gcBeforeUpload`: Run garbage collection before uploading files to the board. This will free up some memory usefull when uploading large files but adds about a second or two to the upload process.
* `micropico.softResetAfterUpload`: Soft-resets your board after any upload action. Usefull if you are developing with `main.py` or `boot.py`.
* `micropico.executeOnConnect`: Path to a MicroPython script on the Pico to execute on connect. Leave empty to disable. (must be relative to the root of the Pico's filesystem; doesn't need to begin with a slash; overrides `micropico.openOnStart` setting)
* `micropico.importOnConnect`: A MicroPython module to import in vREPL on connect. Leave empty to disable.

## Extension Context Keys

Expand Down
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,14 @@
"title": "Script to execute on connect",
"description": "Path to a MicroPython script on the Pico to execute on connect. Leave empty to disable.",
"order": 13
},
"micropico.importOnConnect": {
"type": "string",
"default": "",
"scope": "resource",
"title": "MicroPython module to import on connect",
"description": "A MicroPython module to import in vREPL on connect. Leave empty to disable.",
"order": 14
}
}
},
Expand Down
10 changes: 10 additions & 0 deletions src/activator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,16 @@ export default class Activator {
scriptToExecute
);
}

const moduleToImport = settings.getString(
SettingsKey.importOnConnect
);
if (
moduleToImport !== undefined &&
moduleToImport.trim() !== ""
) {
await this.pyb?.executeCommand(`import ${moduleToImport}`);
}
}
this.ui?.refreshState(true);

Expand Down
1 change: 1 addition & 0 deletions src/settings.mts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum SettingsKey {
gcBeforeUpload = "gcBeforeUpload",
softResetAfterUpload = "softResetAfterUpload",
executeOnConnect = "executeOnConnect",
importOnConnect = "importOnConnect",
}

export type Setting = string | boolean | string[] | null | undefined;
Expand Down

0 comments on commit c12df52

Please sign in to comment.