Skip to content

Commit 72b9a61

Browse files
committed
Add support for upgrade via package manager. Closes #262
Closes #262
1 parent 1c8ee8f commit 72b9a61

File tree

4 files changed

+92
-4
lines changed

4 files changed

+92
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
> **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.
99
10-
## [0.25.0] - Unreleased
10+
## [0.25.1] - Unreleased
1111

1212
### Added:
1313

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

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

2122
## [0.24.0] - 2025-06-04
2223

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Shown when the active document is a Dev Proxy configuration file
6464

6565
- Not installed
6666
- New version detection
67+
- Upgrade Dev Proxy
6768

6869
### Settings
6970

@@ -173,3 +174,4 @@ Shown when the active document is a Dev Proxy configuration file
173174
- Display tick if Dev Proxy is latest version (check based on `newVersionNotification` config setting in Dev Proxy configuration file)
174175
- Display radio tower when Dev Proxy is running
175176
- Display error is Dev Proxy is not installed
177+
- Upgrade Dev Proxy progress

src/commands.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from 'vscode';
22
import { pluginDocs } from './constants';
33
import { VersionPreference } from './enums';
4-
import { executeCommand, isConfigFile } from './helpers';
4+
import { executeCommand, isConfigFile, openUpgradeDocumentation, upgradeDevProxyWithPackageManager } from './helpers';
55
import { isDevProxyRunning, getDevProxyExe } from './detect';
66

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

8181
context.subscriptions.push(
8282
vscode.commands.registerCommand('dev-proxy-toolkit.upgrade', async () => {
83-
const url = 'https://aka.ms/devproxy/upgrade';
84-
vscode.env.openExternal(vscode.Uri.parse(url));
83+
const platform = process.platform;
84+
const versionPreference = configuration.get('version') as VersionPreference;
85+
86+
// Handle Linux early - always redirect to documentation
87+
if (platform === 'linux') {
88+
openUpgradeDocumentation();
89+
return;
90+
}
91+
92+
// Handle Windows
93+
if (platform === 'win32') {
94+
const packageId = versionPreference === VersionPreference.Stable ? 'Microsoft.DevProxy' : 'Microsoft.DevProxy.Beta';
95+
const upgradeCommand = `winget upgrade ${packageId} --silent`;
96+
97+
const upgraded = await upgradeDevProxyWithPackageManager('winget', packageId, upgradeCommand);
98+
if (!upgraded) {
99+
openUpgradeDocumentation();
100+
}
101+
return;
102+
}
103+
104+
// Handle macOS
105+
if (platform === 'darwin') {
106+
const packageId = versionPreference === VersionPreference.Stable ? 'dev-proxy' : 'dev-proxy-beta';
107+
const upgradeCommand = `brew upgrade ${packageId}`;
108+
109+
const upgraded = await upgradeDevProxyWithPackageManager('brew', packageId, upgradeCommand);
110+
if (!upgraded) {
111+
openUpgradeDocumentation();
112+
}
113+
return;
114+
}
115+
116+
// Unknown platform - redirect to documentation
117+
openUpgradeDocumentation();
85118
}));
86119

87120
context.subscriptions.push(

src/helpers.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,55 @@ export const executeCommand = async (cmd: string, options: ExecOptions = {}): Pr
116116
});
117117
});
118118
};
119+
120+
export const upgradeDevProxyWithPackageManager = async (
121+
packageManager: string,
122+
packageId: string,
123+
upgradeCommand: string,
124+
): Promise<boolean> => {
125+
try {
126+
// Check if package manager is available
127+
await executeCommand(`${packageManager} --version`);
128+
129+
// Check if Dev Proxy is installed via package manager
130+
const listCommand =
131+
packageManager === 'winget'
132+
? `winget list ${packageId}`
133+
: 'brew list --formula';
134+
const listOutput = await executeCommand(listCommand);
135+
136+
if (!listOutput.includes(packageId)) {
137+
return false;
138+
}
139+
140+
// Proceed with upgrade
141+
const statusMessage = vscode.window.setStatusBarMessage(
142+
'Upgrading Dev Proxy...',
143+
);
144+
145+
try {
146+
await executeCommand(upgradeCommand);
147+
statusMessage.dispose();
148+
149+
const result = await vscode.window.showInformationMessage(
150+
'Dev Proxy has been successfully upgraded!',
151+
'Reload Window',
152+
);
153+
if (result === 'Reload Window') {
154+
await vscode.commands.executeCommand('workbench.action.reloadWindow');
155+
}
156+
return true;
157+
} catch (error) {
158+
statusMessage.dispose();
159+
vscode.window.showErrorMessage(`Failed to upgrade Dev Proxy: ${error}`);
160+
return false;
161+
}
162+
} catch (error) {
163+
return false;
164+
}
165+
};
166+
167+
export const openUpgradeDocumentation = () => {
168+
const url = 'https://aka.ms/devproxy/upgrade';
169+
vscode.env.openExternal(vscode.Uri.parse(url));
170+
};

0 commit comments

Comments
 (0)