From ea4755005dbc0ffe107b346a553f7adb5df9d1aa Mon Sep 17 00:00:00 2001 From: sw3205933776 <3205933776@qq.com> Date: Tue, 9 Sep 2025 18:25:26 +0800 Subject: [PATCH 1/6] ix: resolve issue where tasks from previous account kept running after switching accounts --- electron/main/index.ts | 7 +++++++ src/pages/Setting/Models.tsx | 3 --- src/store/chatStore.ts | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/electron/main/index.ts b/electron/main/index.ts index af7152835..e39e1e5e4 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -312,6 +312,13 @@ function registerIpcHandlers() { }); ipcMain.handle('get-app-version', () => app.getVersion()); ipcMain.handle('get-backend-port', () => backendPort); + ipcMain.handle('restart-backend', () => { + if (backendPort) { + cleanupPythonProcess(); + checkAndStartBackend(); + } + return { success: true }; + }); ipcMain.handle('get-system-language', getSystemLanguage); ipcMain.handle('is-fullscreen', () => win?.isFullScreen() || false); ipcMain.handle('get-home-dir', () => { diff --git a/src/pages/Setting/Models.tsx b/src/pages/Setting/Models.tsx index 5bb082586..577119b80 100644 --- a/src/pages/Setting/Models.tsx +++ b/src/pages/Setting/Models.tsx @@ -682,9 +682,6 @@ export default function SettingModels() { GPT-5 GPT-5 mini GPT-5 nano - - Claude Opus 4.1 - Claude Sonnet 4 diff --git a/src/store/chatStore.ts b/src/store/chatStore.ts index 7069fa406..ef7268ecc 100644 --- a/src/store/chatStore.ts +++ b/src/store/chatStore.ts @@ -1639,6 +1639,7 @@ const chatStore = create()( const { create } = get() console.log('clearTasks') fetchDelete('/task/stop-all') + window.ipcRenderer.invoke('restart-backend') const newTaskId = create() set((state) => ({ ...state, From bf42d595cd6eb02426aa65ac6ea175e745345fb9 Mon Sep 17 00:00:00 2001 From: sw3205933776 <3205933776@qq.com> Date: Thu, 11 Sep 2025 18:19:57 +0800 Subject: [PATCH 2/6] update --- electron/main/index.ts | 6 +++--- src/store/chatStore.ts | 27 +++++++++++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/electron/main/index.ts b/electron/main/index.ts index e39e1e5e4..f3022c8ff 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -312,10 +312,10 @@ function registerIpcHandlers() { }); ipcMain.handle('get-app-version', () => app.getVersion()); ipcMain.handle('get-backend-port', () => backendPort); - ipcMain.handle('restart-backend', () => { + ipcMain.handle('restart-backend', async () => { if (backendPort) { - cleanupPythonProcess(); - checkAndStartBackend(); + await cleanupPythonProcess(); + await checkAndStartBackend(); } return { success: true }; }); diff --git a/src/store/chatStore.ts b/src/store/chatStore.ts index ef7268ecc..198322048 100644 --- a/src/store/chatStore.ts +++ b/src/store/chatStore.ts @@ -497,7 +497,7 @@ const chatStore = create()( setTaskAssigning(taskId, taskAssigning) return; } - + // Activate agent if (agentMessages.step === "activate_agent" || agentMessages.step === "deactivate_agent") { let taskAssigning = [...tasks[taskId].taskAssigning] @@ -607,7 +607,7 @@ const chatStore = create()( if (taskAssigning && taskAssigning[assigneeAgentIndex]) { // Check if task already exists in the agent's task list const existingTaskIndex = taskAssigning[assigneeAgentIndex].tasks.findIndex(item => item.id === task_id); - + if (existingTaskIndex !== -1) { // Task already exists, update its status taskAssigning[assigneeAgentIndex].tasks[existingTaskIndex].status = "running"; @@ -624,7 +624,7 @@ const chatStore = create()( taskAssigning[assigneeAgentIndex].tasks.push(taskTemp ?? { id: task_id, content, status: "running", }); } } - + // Only update or add to taskRunning, never duplicate if (taskRunningIndex === -1) { // Task not in taskRunning, add it @@ -1639,16 +1639,19 @@ const chatStore = create()( const { create } = get() console.log('clearTasks') fetchDelete('/task/stop-all') - window.ipcRenderer.invoke('restart-backend') - const newTaskId = create() - set((state) => ({ - ...state, - tasks: { - [newTaskId]: { - ...state.tasks[newTaskId], + window.ipcRenderer.invoke('restart-backend').then((res) => { + console.log('restart-backend', res) + const newTaskId = create() + set((state) => ({ + ...state, + tasks: { + [newTaskId]: { + ...state.tasks[newTaskId], + }, }, - }, - })) + })) + }) + }, }) ); From 1788465fe11afad5b61cb9b07763d56e35561376 Mon Sep 17 00:00:00 2001 From: sw3205933776 <3205933776@qq.com> Date: Thu, 11 Sep 2025 18:37:55 +0800 Subject: [PATCH 3/6] fix: browser not working due to no active page available (#328) --- electron/main/webview.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/electron/main/webview.ts b/electron/main/webview.ts index 20816fd1b..4ac0a7738 100644 --- a/electron/main/webview.ts +++ b/electron/main/webview.ts @@ -120,10 +120,12 @@ export class WebViewManager { const activeSize = this.getActiveWebview().length const allSize = Array.from(this.webViews.values()).length if (allSize - activeSize <= 3) { - const newId = Array.from(this.webViews.keys()).length + 2 + const newId = (Math.max(0, ...Array.from(this.webViews.keys()).map(Number)) || 0) + 2 this.createWebview(newId.toString(), 'about:blank?use=0') this.createWebview((newId + 1).toString(), 'about:blank?use=0') this.createWebview((newId + 2).toString(), 'about:blank?use=0') + this.createWebview((newId + 3).toString(), 'about:blank?use=0') + this.createWebview((newId + 4).toString(), 'about:blank?use=0') } // setTimeout(() => { From 7afdd5d99c683923e58e476f607238bc428d77f4 Mon Sep 17 00:00:00 2001 From: Wendong-Fan Date: Mon, 15 Sep 2025 16:19:13 +0800 Subject: [PATCH 4/6] enhance: resolve issue where tasks from previous account kept running PR 332 --- electron/main/index.ts | 19 +++++++++++++++---- src/store/chatStore.ts | 36 +++++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/electron/main/index.ts b/electron/main/index.ts index f3022c8ff..dd0394ed0 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -313,11 +313,22 @@ function registerIpcHandlers() { ipcMain.handle('get-app-version', () => app.getVersion()); ipcMain.handle('get-backend-port', () => backendPort); ipcMain.handle('restart-backend', async () => { - if (backendPort) { - await cleanupPythonProcess(); - await checkAndStartBackend(); + try { + if (backendPort) { + log.info('Restarting backend service...'); + await cleanupPythonProcess(); + await checkAndStartBackend(); + log.info('Backend restart completed successfully'); + return { success: true }; + } else { + log.warn('No backend port found, starting fresh backend'); + await checkAndStartBackend(); + return { success: true }; + } + } catch (error) { + log.error('Failed to restart backend:', error); + return { success: false, error: String(error) }; } - return { success: true }; }); ipcMain.handle('get-system-language', getSystemLanguage); ipcMain.handle('is-fullscreen', () => win?.isFullScreen() || false); diff --git a/src/store/chatStore.ts b/src/store/chatStore.ts index 198322048..7ab3e6670 100644 --- a/src/store/chatStore.ts +++ b/src/store/chatStore.ts @@ -1638,20 +1638,30 @@ const chatStore = create()( clearTasks: () => { const { create } = get() console.log('clearTasks') - fetchDelete('/task/stop-all') - window.ipcRenderer.invoke('restart-backend').then((res) => { - console.log('restart-backend', res) - const newTaskId = create() - set((state) => ({ - ...state, - tasks: { - [newTaskId]: { - ...state.tasks[newTaskId], - }, - }, - })) - }) + // Fire and forget task stop, but ensure restart happens after it + fetchDelete('/task/stop-all') + .then(() => { + console.log('All tasks stopped successfully') + return window.ipcRenderer.invoke('restart-backend') + }) + .then((res) => { + console.log('restart-backend', res) + }) + .catch((error) => { + console.error('Error in clearTasks cleanup:', error) + }) + + // Immediately create new task to maintain UI responsiveness + const newTaskId = create() + set((state) => ({ + ...state, + tasks: { + [newTaskId]: { + ...state.tasks[newTaskId], + }, + }, + })) }, }) ); From f4a90e8c69934103c016d554a5d094170d694f08 Mon Sep 17 00:00:00 2001 From: Wendong-Fan Date: Mon, 15 Sep 2025 16:51:50 +0800 Subject: [PATCH 5/6] enhance: PR 335 browser not working due to no active page available --- electron/main/webview.ts | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/electron/main/webview.ts b/electron/main/webview.ts index 4ac0a7738..123d464d2 100644 --- a/electron/main/webview.ts +++ b/electron/main/webview.ts @@ -112,20 +112,23 @@ export class WebViewManager { } console.log(`Webview ${id} navigated to: ${navigationUrl}`) if (webViewInfo.isActive && webViewInfo.isShow && navigationUrl !== 'about:blank?use=0' && navigationUrl !== 'about:blank') { - console.log("did-navigate", id, url) - this.win?.webContents.send("url-updated", url); + console.log("did-navigate", id, navigationUrl) + this.win?.webContents.send("url-updated", navigationUrl); return } webViewInfo.view.setBounds({ x: -1919, y: -1079, width: 1920, height: 1080 }) const activeSize = this.getActiveWebview().length const allSize = Array.from(this.webViews.values()).length if (allSize - activeSize <= 3) { - const newId = (Math.max(0, ...Array.from(this.webViews.keys()).map(Number)) || 0) + 2 - this.createWebview(newId.toString(), 'about:blank?use=0') - this.createWebview((newId + 1).toString(), 'about:blank?use=0') - this.createWebview((newId + 2).toString(), 'about:blank?use=0') - this.createWebview((newId + 3).toString(), 'about:blank?use=0') - this.createWebview((newId + 4).toString(), 'about:blank?use=0') + const existingKeys = Array.from(this.webViews.keys()).map(Number).filter(n => !isNaN(n)) + const maxId = existingKeys.length > 0 ? Math.max(...existingKeys) : 0 + const startId = maxId + 1 + + // Create webviews sequentially to avoid race conditions + for (let i = 0; i < 3; i++) { + const nextId = (startId + i).toString() + this.createWebview(nextId, 'about:blank?use=0') + } } // setTimeout(() => { @@ -244,8 +247,12 @@ export class WebViewManager { } } - public distroy() { - // TODO: Destroy all webviews + public destroy() { + // Destroy all webviews + Array.from(this.webViews.keys()).forEach(id => { + this.destroyWebview(id) + }) + this.webViews.clear() } } From c2b9b16018a00290b18c6660682f2b7a8c14680d Mon Sep 17 00:00:00 2001 From: sw3205933776 <3205933776@qq.com> Date: Mon, 15 Sep 2025 17:59:55 +0800 Subject: [PATCH 6/6] refactor: remove /task/stop-all API request --- src/store/chatStore.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/store/chatStore.ts b/src/store/chatStore.ts index 7ab3e6670..64649dabe 100644 --- a/src/store/chatStore.ts +++ b/src/store/chatStore.ts @@ -1639,12 +1639,7 @@ const chatStore = create()( const { create } = get() console.log('clearTasks') - // Fire and forget task stop, but ensure restart happens after it - fetchDelete('/task/stop-all') - .then(() => { - console.log('All tasks stopped successfully') - return window.ipcRenderer.invoke('restart-backend') - }) + window.ipcRenderer.invoke('restart-backend') .then((res) => { console.log('restart-backend', res) }) @@ -1652,6 +1647,7 @@ const chatStore = create()( console.error('Error in clearTasks cleanup:', error) }) + // Immediately create new task to maintain UI responsiveness const newTaskId = create() set((state) => ({