|
1 | 1 | import * as vscode from 'vscode'; |
2 | | -import { Commands, Urls } from '../constants'; |
| 2 | +import { Commands } from '../constants'; |
3 | 3 | import { |
4 | 4 | executeCommand, |
5 | 5 | getPackageIdentifier, |
| 6 | + getInstallScriptUrl, |
6 | 7 | upgradeDevProxyWithPackageManager, |
7 | 8 | openUpgradeDocumentation, |
8 | 9 | } from '../utils/shell'; |
@@ -40,8 +41,7 @@ async function installDevProxy( |
40 | 41 | } else if (platform === 'darwin') { |
41 | 42 | await installOnMac(versionPreference); |
42 | 43 | } else if (platform === 'linux') { |
43 | | - // Linux requires manual installation |
44 | | - vscode.env.openExternal(vscode.Uri.parse(Urls.linuxInstall)); |
| 44 | + await installOnLinux(versionPreference); |
45 | 45 | } |
46 | 46 | } finally { |
47 | 47 | message.dispose(); |
@@ -93,14 +93,77 @@ async function installOnMac(versionPreference: VersionPreference): Promise<void> |
93 | 93 | } |
94 | 94 | } |
95 | 95 |
|
| 96 | +async function checkLinuxPrerequisites(): Promise<boolean> { |
| 97 | + try { |
| 98 | + await executeCommand('bash --version'); |
| 99 | + } catch { |
| 100 | + vscode.window.showErrorMessage('Bash is not available. Please install Bash and try again.'); |
| 101 | + return false; |
| 102 | + } |
| 103 | + |
| 104 | + try { |
| 105 | + await executeCommand('curl --version'); |
| 106 | + } catch { |
| 107 | + vscode.window.showErrorMessage('curl is not installed. Please install curl and try again.'); |
| 108 | + return false; |
| 109 | + } |
| 110 | + |
| 111 | + return true; |
| 112 | +} |
| 113 | + |
| 114 | +function buildLinuxInstallCommand(scriptUrl: string): string { |
| 115 | + return `bash -c "$(curl -sL ${scriptUrl})"`; |
| 116 | +} |
| 117 | + |
| 118 | +async function installOnLinux(versionPreference: VersionPreference): Promise<void> { |
| 119 | + if (!(await checkLinuxPrerequisites())) { |
| 120 | + return; |
| 121 | + } |
| 122 | + |
| 123 | + const scriptUrl = getInstallScriptUrl(versionPreference); |
| 124 | + |
| 125 | + try { |
| 126 | + await executeCommand(buildLinuxInstallCommand(scriptUrl)); |
| 127 | + const result = await vscode.window.showInformationMessage('Dev Proxy installed.', 'Reload'); |
| 128 | + if (result === 'Reload') { |
| 129 | + await vscode.commands.executeCommand('workbench.action.reloadWindow'); |
| 130 | + } |
| 131 | + } catch (error) { |
| 132 | + vscode.window.showErrorMessage(`Failed to install Dev Proxy.\n${error}`); |
| 133 | + } |
| 134 | +} |
| 135 | + |
96 | 136 | async function upgradeDevProxy(configuration: vscode.WorkspaceConfiguration): Promise<void> { |
97 | 137 | const platform = process.platform; |
98 | 138 | const versionPreference = configuration.get('version') as VersionPreference; |
99 | 139 | const isBeta = versionPreference === VersionPreference.Beta; |
100 | 140 |
|
101 | | - // Linux always redirects to documentation |
| 141 | + // Linux uses install script to upgrade |
102 | 142 | if (platform === 'linux') { |
103 | | - openUpgradeDocumentation(); |
| 143 | + if (!(await checkLinuxPrerequisites())) { |
| 144 | + openUpgradeDocumentation(); |
| 145 | + return; |
| 146 | + } |
| 147 | + |
| 148 | + const scriptUrl = getInstallScriptUrl(versionPreference); |
| 149 | + const versionText = isBeta ? 'Dev Proxy Beta' : 'Dev Proxy'; |
| 150 | + const statusMessage = vscode.window.setStatusBarMessage(`Upgrading ${versionText}...`); |
| 151 | + |
| 152 | + try { |
| 153 | + await executeCommand(buildLinuxInstallCommand(scriptUrl)); |
| 154 | + statusMessage.dispose(); |
| 155 | + |
| 156 | + const result = await vscode.window.showInformationMessage( |
| 157 | + `${versionText} has been successfully upgraded!`, |
| 158 | + 'Reload Window' |
| 159 | + ); |
| 160 | + if (result === 'Reload Window') { |
| 161 | + await vscode.commands.executeCommand('workbench.action.reloadWindow'); |
| 162 | + } |
| 163 | + } catch { |
| 164 | + statusMessage.dispose(); |
| 165 | + openUpgradeDocumentation(); |
| 166 | + } |
104 | 167 | return; |
105 | 168 | } |
106 | 169 |
|
|
0 commit comments