mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-01 15:22:08 +00:00
Changed the VSCode detection to a test url that will not open if successful
This commit is contained in:
@@ -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: {
|
||||||
|
|||||||
Reference in New Issue
Block a user