fix(core): right sidebar switching not work after switching workspace (#13179)

Due to missing the correct unsubscription, switching workspaces triggers
multiple events. As a result, the sidebar cannot be closed on every
second trigger.
This commit is contained in:
Cats Juice
2025-07-11 23:15:16 +08:00
committed by GitHub
parent 41f338bce0
commit 0d414d914a

View File

@@ -25,6 +25,7 @@ export class DesktopStateSynchronizer extends Service {
const workbench = this.workbenchService.workbench; const workbench = this.workbenchService.workbench;
const appInfo = this.electronApi.appInfo; const appInfo = this.electronApi.appInfo;
this.disposables.push(
this.electronApi.events.ui.onTabAction(event => { this.electronApi.events.ui.onTabAction(event => {
if ( if (
event.type === 'open-in-split-view' && event.type === 'open-in-split-view' &&
@@ -52,8 +53,10 @@ export class DesktopStateSynchronizer extends Service {
) { ) {
workbench.active(event.payload.viewIndex); workbench.active(event.payload.viewIndex);
} }
}); })
);
this.disposables.push(
this.electronApi.events.ui.onCloseView(() => { this.electronApi.events.ui.onCloseView(() => {
(async () => { (async () => {
if (await this.electronApi.handler.ui.isActiveTab()) { if (await this.electronApi.handler.ui.isActiveTab()) {
@@ -76,23 +79,28 @@ export class DesktopStateSynchronizer extends Service {
} }
} }
})().catch(console.error); })().catch(console.error);
}); })
);
this.disposables.push(
this.electronApi.events.ui.onToggleRightSidebar(tabId => { this.electronApi.events.ui.onToggleRightSidebar(tabId => {
if (tabId === appInfo?.viewId) { if (tabId === appInfo?.viewId) {
workbench.setSidebarOpen(!workbench.sidebarOpen$.value); workbench.setSidebarOpen(!workbench.sidebarOpen$.value);
} }
}); })
);
this.disposables.push(
this.electronApi.events.ui.onTabGoToRequest(opts => { this.electronApi.events.ui.onTabGoToRequest(opts => {
if (opts.tabId === appInfo?.viewId) { if (opts.tabId === appInfo?.viewId) {
this.workbenchService.workbench.open(opts.to); this.workbenchService.workbench.open(opts.to);
} }
}); })
);
// sync workbench state with main process // sync workbench state with main process
// also fill tab view meta with title & moduleName // also fill tab view meta with title & moduleName
LiveData.computed(get => { const viewsSub = LiveData.computed(get => {
return get(workbench.views$).map(view => { return get(workbench.views$).map(view => {
const location = get(view.location$); const location = get(view.location$);
return { return {
@@ -118,7 +126,8 @@ export class DesktopStateSynchronizer extends Service {
.catch(console.error); .catch(console.error);
}); });
workbench.activeViewIndex$.subscribe(activeViewIndex => { const activeViewIndexSub = workbench.activeViewIndex$.subscribe(
activeViewIndex => {
if (!appInfo?.viewId) { if (!appInfo?.viewId) {
return; return;
} }
@@ -128,9 +137,10 @@ export class DesktopStateSynchronizer extends Service {
activeViewIndex: activeViewIndex, activeViewIndex: activeViewIndex,
}) })
.catch(console.error); .catch(console.error);
}); }
);
workbench.basename$.subscribe(basename => { const basenameSub = workbench.basename$.subscribe(basename => {
if (!appInfo?.viewId) { if (!appInfo?.viewId) {
return; return;
} }
@@ -141,5 +151,11 @@ export class DesktopStateSynchronizer extends Service {
}) })
.catch(console.error); .catch(console.error);
}); });
this.disposables.push(
() => viewsSub.unsubscribe(),
() => activeViewIndexSub.unsubscribe(),
() => basenameSub.unsubscribe()
);
}; };
} }