From 071fbe769f1b7d05450673e0314938d413847d65 Mon Sep 17 00:00:00 2001 From: Simon Zhu Date: Thu, 4 Dec 2025 16:30:49 -0500 Subject: [PATCH 1/2] add saved workspaces callback --- packages/compass-web/src/entrypoint.tsx | 4 +++ packages/compass-workspaces/src/index.ts | 27 ++++++++++++------- .../src/stores/workspaces-middleware.ts | 8 ++++-- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/packages/compass-web/src/entrypoint.tsx b/packages/compass-web/src/entrypoint.tsx index 599319b205c..160431cf43f 100644 --- a/packages/compass-web/src/entrypoint.tsx +++ b/packages/compass-web/src/entrypoint.tsx @@ -306,6 +306,8 @@ export type CompassWebProps = { * safely closed without losing any important unsaved changes */ onBeforeUnloadCallbackRequest?: (canCloseCallback: () => boolean) => void; + + shouldSaveWorkspaces?: () => boolean; }; function CompassWorkspace({ @@ -495,6 +497,7 @@ const CompassWeb = ({ onOpenConnectViaModal, onFailToLoadConnections, onBeforeUnloadCallbackRequest, + shouldSaveWorkspaces, }: CompassWebProps) => { const appRegistry = useInitialValue(new AppRegistry()); const logger = useCompassWebLogger({ @@ -585,6 +588,7 @@ const CompassWeb = ({ boolean ) { const initialTabs = initialWorkspaceTabs && initialWorkspaceTabs.length > 0 @@ -73,7 +74,7 @@ export function configureStore( }, applyMiddleware( thunk.withExtraArgument(services), - workspacesStateChangeMiddleware(services) + workspacesStateChangeMiddleware(services, shouldSaveWorkspaces) ) ); @@ -84,9 +85,11 @@ export function activateWorkspacePlugin( { initialWorkspaceTabs, onBeforeUnloadCallbackRequest, + shouldSaveWorkspaces, }: { initialWorkspaceTabs?: OpenWorkspaceOptions[] | null; onBeforeUnloadCallbackRequest?: (canCloseCallback: () => boolean) => void; + shouldSaveWorkspaces?: () => boolean; }, { globalAppRegistry, @@ -98,14 +101,18 @@ export function activateWorkspacePlugin( }: WorkspacesServices, { on, cleanup, addCleanup }: ActivateHelpers ) { - const store = configureStore(initialWorkspaceTabs, { - globalAppRegistry, - instancesManager, - connections, - logger, - preferences, - userData, - }); + const store = configureStore( + initialWorkspaceTabs, + { + globalAppRegistry, + instancesManager, + connections, + logger, + preferences, + userData, + }, + shouldSaveWorkspaces + ); void store.dispatch(loadSavedWorkspaces()); diff --git a/packages/compass-workspaces/src/stores/workspaces-middleware.ts b/packages/compass-workspaces/src/stores/workspaces-middleware.ts index 2c335156c8c..9cdef92d6c5 100644 --- a/packages/compass-workspaces/src/stores/workspaces-middleware.ts +++ b/packages/compass-workspaces/src/stores/workspaces-middleware.ts @@ -23,7 +23,8 @@ const handleWorkspacesStateChange = (() => { * This allows you to perform side effects when the state is updated. */ export function workspacesStateChangeMiddleware( - services: WorkspacesServices + services: WorkspacesServices, + shouldSaveWorkspaces?: () => boolean ): Middleware, WorkspacesState> { return (store) => (next) => (action: AnyAction) => { const prevState = store.getState(); @@ -32,7 +33,10 @@ export function workspacesStateChangeMiddleware( // Only call the callback if the workspaces state actually changed if (prevState !== nextState) { - if (services.preferences.getPreferences().enableRestoreWorkspaces) { + if ( + services.preferences.getPreferences().enableRestoreWorkspaces && + shouldSaveWorkspaces?.() + ) { handleWorkspacesStateChange(nextState, services); } } From 84b55c377f3edb6f1e03dc498ef4b127fd4accc9 Mon Sep 17 00:00:00 2001 From: Simon Zhu Date: Thu, 4 Dec 2025 17:41:25 -0500 Subject: [PATCH 2/2] add saved workspaces callback --- packages/compass-workspaces/src/components/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/compass-workspaces/src/components/index.tsx b/packages/compass-workspaces/src/components/index.tsx index 97214082351..d1f56a6245c 100644 --- a/packages/compass-workspaces/src/components/index.tsx +++ b/packages/compass-workspaces/src/components/index.tsx @@ -66,6 +66,8 @@ type WorkspacesWithSidebarProps = { * safely closed without losing any important unsaved changes */ onBeforeUnloadCallbackRequest?: (canCloseCallback: () => boolean) => void; + + shouldSaveWorkspaces?: () => boolean; }; const containerLightThemeStyles = css({