diff --git a/CHANGELOG.md b/CHANGELOG.md index 1da38f1..ee54b88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Snippets: Updated all snippets to use new DLL name, `DevProxy.Plugins.dll` - Notification: Upgrade notification invokes package manager to upgrade Dev Proxy - Improved diagnostics range detection to ensure that they only appear againt the relevant code and don't overlap with ending quotes and commas +- Detection: Changed isDevProxyRunning check to use Dev Proxy API instead of process detection ## [0.24.0] - 2025-06-04 diff --git a/src/detect.ts b/src/detect.ts index 019bde5..e9bddbe 100644 --- a/src/detect.ts +++ b/src/detect.ts @@ -47,25 +47,27 @@ export const getOutdatedVersion = async (devProxyExe: string): Promise = }; export const isDevProxyRunning = async (devProxyExe: string): Promise => { - const platform = os.platform(); - - if (platform === 'win32') { - const processId = await executeCommand(`pwsh.exe -c "(Get-Process ${devProxyExe} -ErrorAction SilentlyContinue).Id"`); - return processId.trim() !== ''; - }; - if (platform === 'darwin') { - const processId = await executeCommand(`$SHELL -c "ps -e -o pid=,comm= | awk \'\\$2==\"${devProxyExe}\" {print \\$1}\'"`); - return processId.trim() !== ''; - }; - if (platform === 'linux') { - const processId = await executeCommand(`/bin/bash -c "ps -e -o pid=,comm= | awk \'\\$2==\"${devProxyExe}\" {print \\$1}\'"`); - return processId.trim() !== ''; + try { + // Get the API port from configuration + const configuration = vscode.workspace.getConfiguration('dev-proxy-toolkit'); + const apiPort = configuration.get('apiPort') as number; + + // Try to connect to the Dev Proxy API on the configured port + const response = await fetch(`http://127.0.0.1:${apiPort}/proxy`, { + method: 'GET', + signal: AbortSignal.timeout(2000), // 2 second timeout + }); + + // If we get any response (even an error), Dev Proxy is running + return response.status >= 200 && response.status < 500; + } catch (error) { + // If the request fails (connection refused, timeout, etc.), Dev Proxy is not running + return false; } - return false; }; export const getDevProxyExe = (versionPreference: VersionPreference) => { return versionPreference === VersionPreference.Stable ? VersionExeName.Stable : VersionExeName.Beta; -}; \ No newline at end of file +}; diff --git a/src/test/examples/devproxyrc.json b/src/test/examples/devproxyrc.json index d7ec73e..12c712e 100644 --- a/src/test/examples/devproxyrc.json +++ b/src/test/examples/devproxyrc.json @@ -1,4 +1,14 @@ { - "$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.24.0/rc.schema.json", - "plugins": [] -} \ No newline at end of file + "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/rc.schema.json", + "plugins": [ + { + "name": "LatencyPlugin", + "enabled": true, + "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll" + } + ], + "urlsToWatch": ["https://jsonplaceholder.typicode.com/*"], + "logLevel": "information", + "newVersionNotification": "stable", + "showSkipMessages": true +}