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