diff --git a/CHANGELOG.md b/CHANGELOG.md index 02bf2a7..fc1ec4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: @@ -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 diff --git a/README.md b/README.md index ceeea6e..7a78185 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ Shown when the active document is a Dev Proxy configuration file - Not installed - New version detection +- Upgrade Dev Proxy ### Settings @@ -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 diff --git a/package-lock.json b/package-lock.json index 4a6b9c4..2188e43 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "dev-proxy-toolkit", - "version": "0.25.0", + "version": "0.25.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "dev-proxy-toolkit", - "version": "0.25.0", + "version": "0.25.1", "dependencies": { "json-to-ast": "^2.1.0" }, diff --git a/package.json b/package.json index 886d926..eaa60ef 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/commands.ts b/src/commands.ts index 9b2e6ac..288f752 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -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) => { @@ -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( diff --git a/src/helpers.ts b/src/helpers.ts index 59fd632..eaf8325 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -116,3 +116,55 @@ export const executeCommand = async (cmd: string, options: ExecOptions = {}): Pr }); }); }; + +export const upgradeDevProxyWithPackageManager = async ( + packageManager: string, + packageId: string, + upgradeCommand: string, +): Promise => { + 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)); +};