fix: wait for sidebar before other commands
This commit is contained in:
parent
86b40c7d14
commit
1566adcaeb
1 changed files with 28 additions and 1 deletions
|
|
@ -284,6 +284,28 @@ async function processDiff(
|
|||
}
|
||||
}
|
||||
|
||||
function waitForSidebarReady(
|
||||
sidebar: ContinueGUIWebviewViewProvider,
|
||||
timeout: number,
|
||||
interval: number,
|
||||
): Promise<boolean> {
|
||||
return new Promise((resolve) => {
|
||||
const startTime = Date.now();
|
||||
|
||||
const checkReadyState = () => {
|
||||
if (sidebar.isReady) {
|
||||
resolve(true);
|
||||
} else if (Date.now() - startTime >= timeout) {
|
||||
resolve(false); // Timed out
|
||||
} else {
|
||||
setTimeout(checkReadyState, interval);
|
||||
}
|
||||
};
|
||||
|
||||
checkReadyState();
|
||||
});
|
||||
}
|
||||
|
||||
// Copy everything over from extension.ts
|
||||
const getCommandsMap: (
|
||||
ide: VsCodeIde,
|
||||
|
|
@ -437,9 +459,14 @@ const getCommandsMap: (
|
|||
// This is a temporary fix—sidebar.webviewProtocol.request is blocking
|
||||
// when the GUI hasn't yet been setup and we should instead be
|
||||
// immediately throwing an error, or returning a Result object
|
||||
|
||||
if (!sidebar.isReady) {
|
||||
focusGUI();
|
||||
return;
|
||||
|
||||
const isReady = await waitForSidebarReady(sidebar, 5000, 100);
|
||||
if (!isReady) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const historyLength = await sidebar.webviewProtocol.request(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue