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 ) => {
88 context . subscriptions . push (
@@ -86,6 +86,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
8686 vscode . commands . registerCommand ( 'dev-proxy-toolkit.start' , async ( ) => {
8787 const showTerminal = configuration . get ( 'showTerminal' ) as boolean ;
8888 const newTerminal = configuration . get ( 'newTerminal' ) as boolean ;
89+ const devProxyExe = getDevProxyExe ( configuration . get ( 'version' ) as VersionPreference ) ;
8990
9091 let terminal : vscode . Terminal ;
9192
@@ -98,15 +99,14 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
9899 }
99100
100101 vscode . window . activeTextEditor && isConfigFile ( vscode . window . activeTextEditor . document )
101- ? terminal . sendText ( `devproxy --config-file "${ vscode . window . activeTextEditor . document . uri . fsPath } "` )
102- : terminal . sendText ( 'devproxy' ) ;
102+ ? terminal . sendText ( `${ devProxyExe } --config-file "${ vscode . window . activeTextEditor . document . uri . fsPath } "` )
103+ : terminal . sendText ( devProxyExe ) ;
103104 } ) ) ;
104105
105106 context . subscriptions . push (
106107 vscode . commands . registerCommand ( 'dev-proxy-toolkit.stop' , async ( ) => {
107108 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 ;
109+ const devProxyExe = getDevProxyExe ( configuration . get ( 'version' ) as VersionPreference ) ;
110110
111111 await fetch ( `http://localhost:${ apiPort } /proxy/stopproxy` , {
112112 method : 'POST' ,
@@ -119,7 +119,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
119119 if ( closeTerminal ) {
120120 const checkProxyStatus = async ( ) => {
121121 try {
122- return await isDevProxyRunning ( exeName ) ;
122+ return await isDevProxyRunning ( devProxyExe ) ;
123123 } catch {
124124 return false ;
125125 }
@@ -148,8 +148,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
148148 context . subscriptions . push (
149149 vscode . commands . registerCommand ( 'dev-proxy-toolkit.restart' , async ( ) => {
150150 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 ;
151+ const devProxyExe = getDevProxyExe ( configuration . get ( 'version' ) as VersionPreference ) ;
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,16 +246,13 @@ 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+ const devProxyExe = getDevProxyExe ( configuration . get ( 'version' ) as VersionPreference ) ;
250+ await executeCommand ( `${ devProxyExe } config open` ) ;
254251 } ) ) ;
255252
256253 context . subscriptions . push (
257254 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 ;
255+ const devProxyExe = getDevProxyExe ( configuration . get ( 'version' ) as VersionPreference ) ;
260256
261257 // ask the user for the filename that they want to use
262258 const fileName = await vscode . window . showInputBox ( {
@@ -300,7 +296,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
300296 location : vscode . ProgressLocation . Notification ,
301297 title : 'Creating new config file...'
302298 } , async ( ) => {
303- await executeCommand ( `${ exeName } config new ${ fileName } ` , { cwd : vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath } ) ;
299+ await executeCommand ( `${ devProxyExe } config new ${ fileName } ` , { cwd : vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath } ) ;
304300 } ) ;
305301
306302 const configUri = vscode . Uri . file ( `${ vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath } /${ fileName } ` ) ;
0 commit comments