@@ -36,6 +36,30 @@ class WebPanel {
3636 return WebPanel . currentPanel ;
3737 }
3838
39+ public static updateTitle ( extensionPath : string ) {
40+ const column = vscode . window . activeTextEditor
41+ ? vscode . window . activeTextEditor . viewColumn
42+ : undefined ;
43+
44+ // If we already have a panel, show it.
45+ // Otherwise, create angular panel.
46+ if ( WebPanel . currentPanel ) {
47+ WebPanel . currentPanel . panel . reveal ( column ) ;
48+ } else {
49+ WebPanel . currentPanel = new WebPanel (
50+ extensionPath ,
51+ column || vscode . ViewColumn . One ,
52+ ) ;
53+ }
54+
55+ WebPanel . currentPanel . panel . webview . postMessage ( {
56+ command : 'update-title' ,
57+ payload : {
58+ title : `Hello from ${ extensionPath } - ${ Date ( ) . toString ( ) } ` ,
59+ } ,
60+ } ) ;
61+ }
62+
3963 private constructor ( extensionPath : string , column : vscode . ViewColumn ) {
4064 this . extensionPath = extensionPath ;
4165 this . builtAppFolder = 'dist' ;
@@ -65,9 +89,10 @@ class WebPanel {
6589
6690 // Handle messages from the webview
6791 this . panel . webview . onDidReceiveMessage (
68- ( message : any ) => {
92+ ( message ) => {
6993 switch ( message . command ) {
70- case 'alert' :
94+ case 'notification' :
95+ vscode . window . showInformationMessage ( message . data . text ) ;
7196 vscode . window . showErrorMessage ( message . text ) ;
7297 return ;
7398 }
@@ -128,4 +153,10 @@ export function activate(context: vscode.ExtensionContext) {
128153 WebPanel . createOrShow ( context . extensionPath ) ;
129154 } ) ,
130155 ) ;
156+
157+ context . subscriptions . push (
158+ vscode . commands . registerCommand ( 'angular-webview.update-title' , ( ) => {
159+ WebPanel . updateTitle ( context . extensionPath ) ;
160+ } ) ,
161+ ) ;
131162}
0 commit comments