mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-08 14:35:03 +00:00
fix(snapshot): normalize renderer:get-last-opened-workspaces output to avoid reactivating a deleted workspace (#8033)
* fix: normalize workspace paths during workspace switch to prevent stale state * chore: test text * tests(snapshot): more workspace coverage
This commit is contained in:
@@ -808,6 +808,7 @@ export const workspaceOpenedEvent = (workspacePath, workspaceUid, workspaceConfi
|
||||
try {
|
||||
const snapshot = await ipcRenderer.invoke('renderer:snapshot:get');
|
||||
const activeWorkspacePath = snapshot?.activeWorkspacePath;
|
||||
const normalizedWorkspacePath = normalizePath(workspacePath || '');
|
||||
|
||||
const currentState = getState();
|
||||
if (!currentState.app.snapshotReady && snapshot?.extras?.devTools) {
|
||||
@@ -822,7 +823,23 @@ export const workspaceOpenedEvent = (workspacePath, workspaceUid, workspaceConfi
|
||||
}
|
||||
|
||||
if (activeWorkspacePath) {
|
||||
shouldSwitch = workspacePath === activeWorkspacePath;
|
||||
const normalizedActiveWorkspacePath = normalizePath(activeWorkspacePath);
|
||||
shouldSwitch = normalizedWorkspacePath === normalizedActiveWorkspacePath;
|
||||
|
||||
// If the snapshot points to a workspace that no longer exists on disk,
|
||||
// fall back to the default workspace instead of leaving stale active state.
|
||||
if (!shouldSwitch && workspaceConfig.type === 'default') {
|
||||
const lastOpenedWorkspacePaths = await ipcRenderer.invoke('renderer:get-last-opened-workspaces').catch(() => []);
|
||||
const normalizedLastOpenedWorkspacePaths = new Set(
|
||||
(Array.isArray(lastOpenedWorkspacePaths) ? lastOpenedWorkspacePaths : [])
|
||||
.map((pathname) => normalizePath(pathname))
|
||||
);
|
||||
const hasActiveWorkspacePath = normalizedLastOpenedWorkspacePaths.has(normalizedActiveWorkspacePath);
|
||||
|
||||
if (!hasActiveWorkspacePath) {
|
||||
shouldSwitch = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
shouldSwitch = !activeWorkspaceUid || workspaceConfig.type === 'default';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user