11import * as vscode from 'vscode' ;
22import { pluginDocs } from './constants' ;
3- import { VersionExeName , VersionPreference } from './enums' ;
3+ import { VersionPreference } from './enums' ;
44import { executeCommand , isConfigFile } from './helpers' ;
5- import { isDevProxyRunning } from './detect' ;
5+ import { isDevProxyRunning , getDevProxyExe } from './detect' ;
66
77export const registerCommands = ( context : vscode . ExtensionContext , configuration : vscode . WorkspaceConfiguration ) => {
8+ const versionPreference = configuration . get ( 'version' ) as VersionPreference ;
9+ const devProxyExe = getDevProxyExe ( configuration . get ( 'version' ) as VersionPreference ) ;
10+
811 context . subscriptions . push (
912 vscode . commands . registerCommand ( 'dev-proxy-toolkit.install' , async ( platform : NodeJS . Platform ) => {
10- const versionPreference = configuration . get ( 'version' ) as VersionPreference ;
1113 const message = vscode . window . setStatusBarMessage ( 'Installing Dev Proxy...' ) ;
1214
1315 // we are on windows so we can use winget
@@ -87,6 +89,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
8789 const showTerminal = configuration . get ( 'showTerminal' ) as boolean ;
8890 const newTerminal = configuration . get ( 'newTerminal' ) as boolean ;
8991
92+
9093 let terminal : vscode . Terminal ;
9194
9295 if ( ! newTerminal && vscode . window . activeTerminal ) {
@@ -98,15 +101,13 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
98101 }
99102
100103 vscode . window . activeTextEditor && isConfigFile ( vscode . window . activeTextEditor . document )
101- ? terminal . sendText ( `devproxy --config-file "${ vscode . window . activeTextEditor . document . uri . fsPath } "` )
102- : terminal . sendText ( 'devproxy' ) ;
104+ ? terminal . sendText ( `${ devProxyExe } --config-file "${ vscode . window . activeTextEditor . document . uri . fsPath } "` )
105+ : terminal . sendText ( devProxyExe ) ;
103106 } ) ) ;
104107
105108 context . subscriptions . push (
106109 vscode . commands . registerCommand ( 'dev-proxy-toolkit.stop' , async ( ) => {
107110 const apiPort = configuration . get ( 'apiPort' ) as number ;
108- const versionPreference = configuration . get ( 'version' ) as VersionPreference ;
109- const exeName = versionPreference === VersionPreference . Stable ? VersionExeName . Stable : VersionExeName . Beta ;
110111
111112 await fetch ( `http://localhost:${ apiPort } /proxy/stopproxy` , {
112113 method : 'POST' ,
@@ -119,7 +120,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
119120 if ( closeTerminal ) {
120121 const checkProxyStatus = async ( ) => {
121122 try {
122- return await isDevProxyRunning ( exeName ) ;
123+ return await isDevProxyRunning ( devProxyExe ) ;
123124 } catch {
124125 return false ;
125126 }
@@ -148,8 +149,6 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
148149 context . subscriptions . push (
149150 vscode . commands . registerCommand ( 'dev-proxy-toolkit.restart' , async ( ) => {
150151 const apiPort = configuration . get ( 'apiPort' ) as number ;
151- const versionPreference = configuration . get ( 'version' ) as VersionPreference ;
152- const exeName = versionPreference === VersionPreference . Stable ? VersionExeName . Stable : VersionExeName . Beta ;
153152
154153 try {
155154 await fetch ( `http://localhost:${ apiPort } /proxy/stopproxy` , {
@@ -161,7 +160,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
161160
162161 const checkProxyStatus = async ( ) => {
163162 try {
164- return await isDevProxyRunning ( exeName ) ;
163+ return await isDevProxyRunning ( devProxyExe ) ;
165164 } catch {
166165 return false ;
167166 }
@@ -192,8 +191,8 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
192191 }
193192
194193 vscode . window . activeTextEditor && isConfigFile ( vscode . window . activeTextEditor . document )
195- ? terminal . sendText ( `devproxy --config-file "${ vscode . window . activeTextEditor . document . uri . fsPath } "` )
196- : terminal . sendText ( 'devproxy' ) ;
194+ ? terminal . sendText ( `${ devProxyExe } --config-file "${ vscode . window . activeTextEditor . document . uri . fsPath } "` )
195+ : terminal . sendText ( devProxyExe ) ;
197196 } catch {
198197 vscode . window . showErrorMessage ( 'Failed to restart Dev Proxy' ) ;
199198 }
@@ -247,23 +246,17 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
247246
248247 context . subscriptions . push (
249248 vscode . commands . registerCommand ( 'dev-proxy-toolkit.config-open' , async ( ) => {
250- const versionPreference = configuration . get ( 'version' ) as VersionPreference ;
251- versionPreference === VersionPreference . Stable
252- ? await executeCommand ( `${ VersionExeName . Stable } config open` )
253- : await executeCommand ( `${ VersionExeName . Beta } config open` ) ;
249+ await executeCommand ( `${ devProxyExe } config open` ) ;
254250 } ) ) ;
255251
256252 context . subscriptions . push (
257253 vscode . commands . registerCommand ( 'dev-proxy-toolkit.config-new' , async ( ) => {
258- const versionPreference = configuration . get ( 'version' ) as VersionPreference ;
259- const exeName = versionPreference === VersionPreference . Stable ? VersionExeName . Stable : VersionExeName . Beta ;
260-
261254 // ask the user for the filename that they want to use
262255 const fileName = await vscode . window . showInputBox ( {
263256 prompt : 'Enter the name of the new config file' ,
257+ placeHolder : 'devproxyrc.json' ,
264258 value : 'devproxyrc.json' ,
265259 validateInput : ( value : string ) => {
266- console . log ( value ) ;
267260 const errors : string [ ] = [ ] ;
268261
269262 if ( ! value ) {
@@ -286,7 +279,6 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
286279 // we do this after the user has entered the filename
287280 try {
288281 const workspaceFolder = vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath ;
289- console . log ( workspaceFolder ) ;
290282 const { type } = await vscode . workspace . fs . stat ( vscode . Uri . file ( `${ workspaceFolder } /${ fileName } ` ) ) ;
291283 if ( type === vscode . FileType . File ) {
292284 vscode . window . showErrorMessage ( 'A file with that name already exists' ) ;
@@ -300,7 +292,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
300292 location : vscode . ProgressLocation . Notification ,
301293 title : 'Creating new config file...'
302294 } , async ( ) => {
303- await executeCommand ( `${ exeName } config new ${ fileName } ` , { cwd : vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath } ) ;
295+ await executeCommand ( `${ devProxyExe } config new ${ fileName } ` , { cwd : vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath } ) ;
304296 } ) ;
305297
306298 const configUri = vscode . Uri . file ( `${ vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath } /${ fileName } ` ) ;
0 commit comments