mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-05-19 07:59:39 +00:00
fix: implement protocol URL queue to handle requests before window ready
This commit is contained in:
parent
79e32cb8c4
commit
ac540b09be
2 changed files with 43 additions and 1 deletions
|
|
@ -40,6 +40,10 @@ let python_process: ChildProcessWithoutNullStreams | null = null;
|
|||
let backendPort: number = 5001;
|
||||
let browser_port = 9222;
|
||||
|
||||
// Protocol URL queue for handling URLs before window is ready
|
||||
let protocolUrlQueue: string[] = [];
|
||||
let isWindowReady = false;
|
||||
|
||||
// ==================== path config ====================
|
||||
const preload = path.join(__dirname, '../preload/index.mjs');
|
||||
const indexHtml = path.join(RENDERER_DIST, 'index.html');
|
||||
|
|
@ -97,6 +101,19 @@ const setupProtocolHandlers = () => {
|
|||
// ==================== protocol url handle ====================
|
||||
function handleProtocolUrl(url: string) {
|
||||
log.info('enter handleProtocolUrl', url);
|
||||
|
||||
// If window is not ready, queue the URL
|
||||
if (!isWindowReady || !win || win.isDestroyed()) {
|
||||
log.info('Window not ready, queuing protocol URL:', url);
|
||||
protocolUrlQueue.push(url);
|
||||
return;
|
||||
}
|
||||
|
||||
processProtocolUrl(url);
|
||||
}
|
||||
|
||||
// Process a single protocol URL
|
||||
function processProtocolUrl(url: string) {
|
||||
const urlObj = new URL(url);
|
||||
const code = urlObj.searchParams.get('code');
|
||||
const share_token = urlObj.searchParams.get('share_token');
|
||||
|
|
@ -130,6 +147,19 @@ function handleProtocolUrl(url: string) {
|
|||
}
|
||||
}
|
||||
|
||||
// Process all queued protocol URLs
|
||||
function processQueuedProtocolUrls() {
|
||||
if (protocolUrlQueue.length > 0) {
|
||||
log.info('Processing queued protocol URLs:', protocolUrlQueue.length);
|
||||
const urls = [...protocolUrlQueue];
|
||||
protocolUrlQueue = [];
|
||||
|
||||
urls.forEach(url => {
|
||||
processProtocolUrl(url);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== single instance lock ====================
|
||||
const setupSingleInstanceLock = () => {
|
||||
const gotLock = app.requestSingleInstanceLock();
|
||||
|
|
@ -1114,6 +1144,11 @@ async function createWindow() {
|
|||
});
|
||||
});
|
||||
|
||||
// Mark window as ready and process any queued protocol URLs
|
||||
isWindowReady = true;
|
||||
log.info('Window is ready, processing queued protocol URLs...');
|
||||
processQueuedProtocolUrls();
|
||||
|
||||
// Now check and install dependencies
|
||||
let res:PromiseReturnType = await checkAndInstallDepsOnUpdate({ win });
|
||||
if (!res.success) {
|
||||
|
|
@ -1346,7 +1381,10 @@ app.on('window-all-closed', () => {
|
|||
webViewManager = null;
|
||||
}
|
||||
|
||||
// Reset window state
|
||||
win = null;
|
||||
isWindowReady = false;
|
||||
protocolUrlQueue = [];
|
||||
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
|
|
@ -1399,6 +1437,10 @@ app.on('before-quit', async (event) => {
|
|||
global.gc();
|
||||
}
|
||||
|
||||
// Reset protocol handling state
|
||||
isWindowReady = false;
|
||||
protocolUrlQueue = [];
|
||||
|
||||
log.info('All cleanup completed, exiting...');
|
||||
} catch (error) {
|
||||
log.error('Error during cleanup:', error);
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ async function proxyFetchRequest(
|
|||
...customHeaders,
|
||||
}
|
||||
|
||||
console.debug('url', url, token)
|
||||
// console.debug('url', url, token)
|
||||
if (!url.includes('http://') && !url.includes('https://') && token) {
|
||||
headers['Authorization'] = `Bearer ${token}`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue