Skip to content

Commit 4712a1e

Browse files
committed
Refactor command registration to optimize version preference retrieval
1 parent a873216 commit 4712a1e

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/commands.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import { executeCommand, isConfigFile } from './helpers';
55
import { isDevProxyRunning, getDevProxyExe } from './detect';
66

77
export 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
@@ -86,7 +88,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
8688
vscode.commands.registerCommand('dev-proxy-toolkit.start', async () => {
8789
const showTerminal = configuration.get('showTerminal') as boolean;
8890
const newTerminal = configuration.get('newTerminal') as boolean;
89-
const devProxyExe = getDevProxyExe(configuration.get('version') as VersionPreference);
91+
9092

9193
let terminal: vscode.Terminal;
9294

@@ -106,7 +108,6 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
106108
context.subscriptions.push(
107109
vscode.commands.registerCommand('dev-proxy-toolkit.stop', async () => {
108110
const apiPort = configuration.get('apiPort') as number;
109-
const devProxyExe = getDevProxyExe(configuration.get('version') as VersionPreference);
110111

111112
await fetch(`http://localhost:${apiPort}/proxy/stopproxy`, {
112113
method: 'POST',
@@ -148,7 +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 devProxyExe = getDevProxyExe(configuration.get('version') as VersionPreference);
152152

153153
try {
154154
await fetch(`http://localhost:${apiPort}/proxy/stopproxy`, {
@@ -246,17 +246,15 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
246246

247247
context.subscriptions.push(
248248
vscode.commands.registerCommand('dev-proxy-toolkit.config-open', async () => {
249-
const devProxyExe = getDevProxyExe(configuration.get('version') as VersionPreference);
250249
await executeCommand(`${devProxyExe} config open`);
251250
}));
252251

253252
context.subscriptions.push(
254253
vscode.commands.registerCommand('dev-proxy-toolkit.config-new', async () => {
255-
const devProxyExe = getDevProxyExe(configuration.get('version') as VersionPreference);
256-
257254
// ask the user for the filename that they want to use
258255
const fileName = await vscode.window.showInputBox({
259256
prompt: 'Enter the name of the new config file',
257+
placeHolder: 'devproxyrc.json',
260258
value: 'devproxyrc.json',
261259
validateInput: (value: string) => {
262260
console.log(value);

0 commit comments

Comments
 (0)