@@ -15,17 +15,96 @@ let panel: vscode.WebviewPanel;
1515
1616const channel : vscode . OutputChannel = vscode . window . createOutputChannel ( 'CRC Logs' ) ;
1717
18+ /*
19+ interface ViewEvent {
20+ action: string;
21+ }
22+
23+
24+ interface OpenPageEvent extends ViewEvent {
25+ params: {
26+ url: string;
27+ }
28+ }
29+
30+ interface CrcStartEvent extends ViewEvent {
31+ data: string;
32+ pullSecret: string;
33+ crcLoc: string;
34+ cpuSize: number;
35+ memory: number;
36+ isSetting: boolean;
37+ }
38+ */
1839async function clusterEditorMessageListener ( event : any ) : Promise < any > {
19- if ( [ 'openLaunchSandboxPage' , 'openCreateClusterPage' , 'openCrcAddClusterPage' ] . includes ( event . action ) ) {
20- await vscode . commands . executeCommand ( `openshift.explorer.addCluster.${ event . action } ` , event . params ?. url ) ;
40+ switch ( event . action ) {
41+ case 'openLaunchSandboxPage' :
42+ case 'openCreateClusterPage' :
43+ case 'openCrcAddClusterPage' :
44+ case 'crcSetup' :
45+ case 'crcStart' :
46+ case 'crcStop' :
47+ await vscode . commands . executeCommand ( `openshift.explorer.addCluster.${ event . action } ` , event ) ;
48+ break ;
49+
50+ case 'crcSaveSettings' :
51+ ClusterViewLoader . crcSaveSettings ( event ) ;
52+ break ;
53+
54+ case 'checksetting' :
55+ const binaryFromSetting :string = vscode . workspace . getConfiguration ( 'openshiftConnector' ) . get ( 'crcBinaryLocation' ) ;
56+ if ( binaryFromSetting ) {
57+ panel . webview . postMessage ( { action : 'crcsetting' } ) ;
58+ ClusterViewLoader . checkCrcStatus ( binaryFromSetting , 'crcstatus' , panel ) ;
59+ }
60+ break ;
61+
62+ case 'checkcrcstatus' :
63+ ClusterViewLoader . checkCrcStatus ( event . data , 'crcstatus' , panel ) ;
64+ break
65+
66+ case 'crcLogin' :
67+ vscode . commands . executeCommand (
68+ 'openshift.explorer.login.credentialsLogin' ,
69+ true ,
70+ event . url ,
71+ event . data . username ,
72+ event . data . password
73+ ) ;
74+ break ;
75+ }
76+ }
77+
78+ export default class ClusterViewLoader {
79+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
80+ static get extensionPath ( ) {
81+ return vscode . extensions . getExtension ( ExtenisonID ) . extensionPath
2182 }
2283
23- if ( event . action === 'run' ) {
84+ @vsCommand ( 'openshift.explorer.addCluster.openLaunchSandboxPage' )
85+ static async openLaunchSandboxPage ( url : string ) {
86+ await vscode . commands . executeCommand ( 'vscode.open' , vscode . Uri . parse ( url ) ) ;
87+ }
88+
89+ @vsCommand ( 'openshift.explorer.addCluster.openCreateClusterPage' )
90+ static async openCreateClusterPage ( url : string ) {
91+ await vscode . commands . executeCommand ( 'vscode.open' , vscode . Uri . parse ( url ) ) ;
92+ }
93+
94+ @vsCommand ( 'openshift.explorer.addCluster.openCrcAddClusterPage' )
95+ static async openCrcAddClusterPage ( ) {
96+ // fake command to report crc selection through telemetry
97+ }
98+
99+ @vsCommand ( 'openshift.explorer.addCluster.crcSetup' )
100+ static async crcSetup ( event : any ) {
24101 const terminal : vscode . Terminal = WindowUtil . createTerminal ( 'OpenShift: CRC Setup' , undefined ) ;
25102 terminal . sendText ( `${ event . data } setup` ) ;
26103 terminal . show ( ) ;
27104 }
28- if ( event . action === 'start' ) {
105+
106+ @vsCommand ( 'openshift.explorer.addCluster.crcStart' )
107+ static async crcStart ( event : any ) {
29108 let startProcess : ChildProcess ;
30109 channel . show ( ) ;
31110 if ( event . isSetting ) {
@@ -37,11 +116,6 @@ async function clusterEditorMessageListener (event: any ): Promise<any> {
37116 startProcess = spawn ( `${ binaryFromSetting } ` , crcOptions ) ;
38117 channel . append ( `\n\n${ binaryFromSetting } ${ crcOptions . join ( ' ' ) } \n` ) ;
39118 } else {
40- const configuration = vscode . workspace . getConfiguration ( 'openshiftConnector' ) ;
41- configuration . update ( 'crcBinaryLocation' , event . crcLoc , vscode . ConfigurationTarget . Global ) ;
42- configuration . update ( 'crcPullSecretPath' , event . pullSecret , vscode . ConfigurationTarget . Global ) ;
43- configuration . update ( 'crcCpuCores' , event . cpuSize , vscode . ConfigurationTarget . Global ) ;
44- configuration . update ( 'crcMemoryAllocated' , Number . parseInt ( event . memory , 10 ) , vscode . ConfigurationTarget . Global ) ;
45119 const [ tool , ...params ] = event . data . split ( ' ' ) ;
46120 startProcess = spawn ( tool , params ) ;
47121 channel . append ( `\n\n${ tool } ${ params . join ( ' ' ) } \n` ) ;
@@ -64,7 +138,9 @@ async function clusterEditorMessageListener (event: any ): Promise<any> {
64138 ClusterViewLoader . checkCrcStatus ( binaryLoc , 'crcstartstatus' , panel ) ;
65139 } ) ;
66140 }
67- if ( event . action === 'stop' ) {
141+
142+ @vsCommand ( 'openshift.explorer.addCluster.crcStop' )
143+ static async crcStop ( event ) {
68144 let filePath : string ;
69145 channel . show ( ) ;
70146 if ( event . data === '' ) {
@@ -88,47 +164,14 @@ async function clusterEditorMessageListener (event: any ): Promise<any> {
88164 ClusterViewLoader . checkCrcStatus ( filePath , 'crcstopstatus' , panel ) ;
89165 } ) ;
90166 }
91- if ( event . action === 'checksetting' ) {
92- const binaryFromSetting :string = vscode . workspace . getConfiguration ( 'openshiftConnector' ) . get ( 'crcBinaryLocation' ) ;
93- if ( binaryFromSetting ) {
94- panel . webview . postMessage ( { action : 'crcsetting' } ) ;
95- ClusterViewLoader . checkCrcStatus ( binaryFromSetting , 'crcstatus' , panel ) ;
96- }
97- }
98- if ( event . action === 'checkcrcstatus' ) {
99- ClusterViewLoader . checkCrcStatus ( event . data , 'crcstatus' , panel ) ;
100- }
101167
102- if ( event . action === 'crclogin' ) {
103- vscode . commands . executeCommand (
104- 'openshift.explorer.login.credentialsLogin' ,
105- true ,
106- event . url ,
107- event . data . username ,
108- event . data . password
109- ) ;
110- }
111- }
112-
113- export default class ClusterViewLoader {
114- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
115- static get extensionPath ( ) {
116- return vscode . extensions . getExtension ( ExtenisonID ) . extensionPath
117- }
118-
119- @vsCommand ( 'openshift.explorer.addCluster.openLaunchSandboxPage' )
120- static async openLaunchSandboxPage ( url : string ) {
121- await vscode . commands . executeCommand ( 'vscode.open' , vscode . Uri . parse ( url ) ) ;
122- }
123-
124- @vsCommand ( 'openshift.explorer.addCluster.openCreateClusterPage' )
125- static async openCreateClusterPage ( url : string ) {
126- await vscode . commands . executeCommand ( 'vscode.open' , vscode . Uri . parse ( url ) ) ;
127- }
128-
129- @vsCommand ( 'openshift.explorer.addCluster.openCrcAddClusterPage' )
130- static async openCrcAddClusterPage ( url : string ) {
131- // fake command to report crc selection through telemetry
168+ static async crcSaveSettings ( event ) {
169+ const cfg = vscode . workspace . getConfiguration ( 'openshiftConnector' ) ;
170+ await cfg . update ( 'crcBinaryLocation' , event . crcLoc , vscode . ConfigurationTarget . Global ) ;
171+ await cfg . update ( 'crcPullSecretPath' , event . pullSecret , vscode . ConfigurationTarget . Global ) ;
172+ await cfg . update ( 'crcCpuCores' , event . cpuSize , vscode . ConfigurationTarget . Global ) ;
173+ await cfg . update ( 'crcMemoryAllocated' , Number . parseInt ( event . memory , 10 ) , vscode . ConfigurationTarget . Global ) ;
174+ await cfg . update ( 'crcNameserver' , event . nameserver ) ;
132175 }
133176
134177 // eslint-disable-next-line @typescript-eslint/require-await
@@ -192,7 +235,7 @@ export default class ClusterViewLoader {
192235 const reactAppUri = p . webview . asWebviewUri ( reactAppPathOnDisk ) ;
193236 const htmlString :Buffer = fs . readFileSync ( path . join ( reactAppRootOnDisk , 'index.html' ) ) ;
194237 const meta = `<meta http-equiv="Content-Security-Policy"
195- content="connect-src *;
238+ content="connect-src *;
196239 default-src 'none';
197240 img-src ${ p . webview . cspSource } https: 'self' data:;
198241 script-src 'unsafe-eval' 'unsafe-inline' vscode-resource:;
0 commit comments