@@ -23,6 +23,7 @@ import which from "which";
2323import { existsSync } from "fs" ;
2424import { join } from "path" ;
2525import { PythonExtension } from "@vscode/python-extension" ;
26+ import { unknownErrorToString } from "../utils/errorHelper.mjs" ;
2627
2728interface SubmitMessageValue {
2829 projectName : string ;
@@ -77,10 +78,16 @@ export class NewMicroPythonProjectPanel {
7778 if ( ! settings ) {
7879 panel . dispose ( ) ;
7980
80- // TODO: maybe add restart button
81- void window . showErrorMessage (
82- "Failed to load settings. Please restart VSCode."
83- ) ;
81+ void window
82+ . showErrorMessage (
83+ "Failed to load settings. Please restart VS Code or reload the window." ,
84+ "Reload Window"
85+ )
86+ . then ( selected => {
87+ if ( selected === "Reload Window" ) {
88+ commands . executeCommand ( "workbench.action.reloadWindow" ) ;
89+ }
90+ } ) ;
8491
8592 return ;
8693 }
@@ -354,11 +361,9 @@ print("Finished.")\r\n`;
354361 await new Promise ( resolve => setTimeout ( resolve , 2000 ) ) ;
355362
356363 // open and call initialise
357- void commands . executeCommand (
358- "vscode.openFolder" ,
359- Uri . file ( projectFolder ) ,
360- ( workspace . workspaceFolders ?. length ?? 0 ) > 0
361- ) ;
364+ void commands . executeCommand ( "vscode.openFolder" , Uri . file ( projectFolder ) , {
365+ forceNewWindow : ( workspace . workspaceFolders ?. length ?? 0 ) > 0 ,
366+ } ) ;
362367 }
363368
364369 private async _update ( ) : Promise < void > {
@@ -375,7 +380,18 @@ print("Finished.")\r\n`;
375380 const html = await this . _getHtmlForWebview ( this . _panel . webview ) ;
376381
377382 if ( html !== "" ) {
378- this . _panel . webview . html = html ;
383+ try {
384+ this . _panel . webview . html = html ;
385+ } catch ( error ) {
386+ this . _logger . error (
387+ "Failed to set webview html. Webview might have been disposed. Error: " ,
388+ unknownErrorToString ( error )
389+ ) ;
390+ // properly dispose panel
391+ this . dispose ( ) ;
392+
393+ return ;
394+ }
379395 await this . _updateTheme ( ) ;
380396 } else {
381397 void window . showErrorMessage (
@@ -386,14 +402,23 @@ print("Finished.")\r\n`;
386402 }
387403
388404 private async _updateTheme ( ) : Promise < void > {
389- await this . _panel . webview . postMessage ( {
390- command : "setTheme" ,
391- theme :
392- window . activeColorTheme . kind === ColorThemeKind . Dark ||
393- window . activeColorTheme . kind === ColorThemeKind . HighContrast
394- ? "dark"
395- : "light" ,
396- } ) ;
405+ try {
406+ await this . _panel . webview . postMessage ( {
407+ command : "setTheme" ,
408+ theme :
409+ window . activeColorTheme . kind === ColorThemeKind . Dark ||
410+ window . activeColorTheme . kind === ColorThemeKind . HighContrast
411+ ? "dark"
412+ : "light" ,
413+ } ) ;
414+ } catch ( error ) {
415+ this . _logger . error (
416+ "Failed to update theme in webview. Webview might have been disposed. Error:" ,
417+ unknownErrorToString ( error )
418+ ) ;
419+ // properly dispose panel
420+ this . dispose ( ) ;
421+ }
397422 }
398423
399424 public dispose ( ) : void {
0 commit comments