Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

> **Note**: odd version numbers, for example, `0.13.0`, are not included in this changelog. They are used to test the new features and fixes before the final release.

## [0.25.0] - Unreleased
## [0.25.1] - Unreleased

### Added:

Expand All @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Snippets: Updated all snippets to use `v0.29.0` schema
- Snippets: Updated all snuppers to use new DLL name, `DevProxy.Plugins.dll`
- Notification: Upgrade notification invokes package manager to upgrade Dev Proxy

## [0.24.0] - 2025-06-04

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Shown when the active document is a Dev Proxy configuration file

- Not installed
- New version detection
- Upgrade Dev Proxy

### Settings

Expand Down Expand Up @@ -173,3 +174,4 @@ Shown when the active document is a Dev Proxy configuration file
- Display tick if Dev Proxy is latest version (check based on `newVersionNotification` config setting in Dev Proxy configuration file)
- Display radio tower when Dev Proxy is running
- Display error is Dev Proxy is not installed
- Upgrade Dev Proxy progress
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dev-proxy-toolkit",
"displayName": "Dev Proxy Toolkit",
"description": "Makes it easy to create and update Dev Proxy configuration files.",
"version": "0.25.0",
"version": "0.25.1",
"publisher": "garrytrinder",
"engines": {
"vscode": "^1.101.0"
Expand Down
39 changes: 36 additions & 3 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import { pluginDocs } from './constants';
import { VersionPreference } from './enums';
import { executeCommand, isConfigFile } from './helpers';
import { executeCommand, isConfigFile, openUpgradeDocumentation, upgradeDevProxyWithPackageManager } from './helpers';
import { isDevProxyRunning, getDevProxyExe } from './detect';

export const registerCommands = (context: vscode.ExtensionContext, configuration: vscode.WorkspaceConfiguration) => {
Expand Down Expand Up @@ -80,8 +80,41 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration

context.subscriptions.push(
vscode.commands.registerCommand('dev-proxy-toolkit.upgrade', async () => {
const url = 'https://aka.ms/devproxy/upgrade';
vscode.env.openExternal(vscode.Uri.parse(url));
const platform = process.platform;
const versionPreference = configuration.get('version') as VersionPreference;

// Handle Linux early - always redirect to documentation
if (platform === 'linux') {
openUpgradeDocumentation();
return;
}

// Handle Windows
if (platform === 'win32') {
const packageId = versionPreference === VersionPreference.Stable ? 'Microsoft.DevProxy' : 'Microsoft.DevProxy.Beta';
const upgradeCommand = `winget upgrade ${packageId} --silent`;

const upgraded = await upgradeDevProxyWithPackageManager('winget', packageId, upgradeCommand);
if (!upgraded) {
openUpgradeDocumentation();
}
return;
}

// Handle macOS
if (platform === 'darwin') {
const packageId = versionPreference === VersionPreference.Stable ? 'dev-proxy' : 'dev-proxy-beta';
const upgradeCommand = `brew upgrade ${packageId}`;

const upgraded = await upgradeDevProxyWithPackageManager('brew', packageId, upgradeCommand);
if (!upgraded) {
openUpgradeDocumentation();
}
return;
}

// Unknown platform - redirect to documentation
openUpgradeDocumentation();
}));

context.subscriptions.push(
Expand Down
52 changes: 52 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,55 @@ export const executeCommand = async (cmd: string, options: ExecOptions = {}): Pr
});
});
};

export const upgradeDevProxyWithPackageManager = async (
packageManager: string,
packageId: string,
upgradeCommand: string,
): Promise<boolean> => {
try {
// Check if package manager is available
await executeCommand(`${packageManager} --version`);

// Check if Dev Proxy is installed via package manager
const listCommand =
packageManager === 'winget'
? `winget list ${packageId}`
: 'brew list --formula';
const listOutput = await executeCommand(listCommand);

if (!listOutput.includes(packageId)) {
return false;
}

// Proceed with upgrade
const statusMessage = vscode.window.setStatusBarMessage(
'Upgrading Dev Proxy...',
);

try {
await executeCommand(upgradeCommand);
statusMessage.dispose();

const result = await vscode.window.showInformationMessage(
'Dev Proxy has been successfully upgraded!',
'Reload Window',
);
if (result === 'Reload Window') {
await vscode.commands.executeCommand('workbench.action.reloadWindow');
}
return true;
} catch (error) {
statusMessage.dispose();
vscode.window.showErrorMessage(`Failed to upgrade Dev Proxy: ${error}`);
return false;
}
} catch (error) {
return false;
}
};

export const openUpgradeDocumentation = () => {
const url = 'https://aka.ms/devproxy/upgrade';
vscode.env.openExternal(vscode.Uri.parse(url));
};