Changed the VSCode detection to a test url that will not open if successful

This commit is contained in:
Justin Kolasa (from Dev Box)
2025-05-20 08:02:13 -04:00
parent ec195c466a
commit 2db9978d72

View File

@@ -300,17 +300,13 @@ export default class Explorer {
iframe.style.display = "none"; iframe.style.display = "none";
document.body.appendChild(iframe); document.body.appendChild(iframe);
// Set timeout to handle case where protocol isn't supported
const timeoutId = setTimeout(() => { const timeoutId = setTimeout(() => {
// Clean up iframe
if (document.body.contains(iframe)) { if (document.body.contains(iframe)) {
document.body.removeChild(iframe); document.body.removeChild(iframe);
} }
// Could not open VS Code within timeout period
resolve(false); resolve(false);
}, 1000); }, 1000);
// Try to navigate to VS Code protocol
try { try {
// Listen for blur event which might indicate app was launched // Listen for blur event which might indicate app was launched
const onBlur = () => { const onBlur = () => {
@@ -323,9 +319,8 @@ export default class Explorer {
resolve(true); resolve(true);
}; };
window.addEventListener("blur", onBlur, { once: true }); window.addEventListener("blur", onBlur, { once: true });
// Use a test URL that won't open a specific resource but will check if the extension is installed
// Navigate iframe to the VSCode URL iframe.src = "vscode://ms-azuretools.vscode-cosmosdb?test=1";
iframe.src = vscodeUrl;
} catch (error) { } catch (error) {
clearTimeout(timeoutId); clearTimeout(timeoutId);
if (document.body.contains(iframe)) { if (document.body.contains(iframe)) {
@@ -336,25 +331,20 @@ export default class Explorer {
}); });
}; };
// Try to open VS Code directly first
detectVSCode().then((isVSCodeInstalled) => { detectVSCode().then((isVSCodeInstalled) => {
if (isVSCodeInstalled) { if (isVSCodeInstalled) {
try { try {
// VS Code is likely installed, open URL directly
window.location.href = vscodeUrl; window.location.href = vscodeUrl;
TelemetryProcessor.traceStart(Action.OpenVSCode); TelemetryProcessor.traceStart(Action.OpenVSCode);
} catch (error) { } catch (error) {
logConsoleError(`Failed to open VS Code: ${getErrorMessage(error)}`); logConsoleError(`Failed to open VS Code: ${getErrorMessage(error)}`);
// If opening fails, show the dialog as fallback
showVSCodeDialog(); showVSCodeDialog();
} }
} else { } else {
// VS Code not detected, show installation dialog
showVSCodeDialog(); showVSCodeDialog();
} }
}); });
// Helper function to show the VS Code dialog
const showVSCodeDialog = () => { const showVSCodeDialog = () => {
const openVSCodeDialogProps: DialogProps = { const openVSCodeDialogProps: DialogProps = {
linkProps: { linkProps: {