fix(electron): only the active view should respond to CMD+N (#8068)

This commit is contained in:
pengx17 2024-09-03 11:48:06 +00:00
parent aad442e73d
commit ae3b13bfb4
No known key found for this signature in database
GPG Key ID: 23F23D9E8B3971ED

View File

@ -11,7 +11,7 @@ import {
import { ExplorerTags } from '@affine/core/modules/explorer/views/sections/tags';
import { CMDKQuickSearchService } from '@affine/core/modules/quicksearch/services/cmdk';
import { isNewTabTrigger } from '@affine/core/utils';
import { events } from '@affine/electron-api';
import { apis, events } from '@affine/electron-api';
import { useI18n } from '@affine/i18n';
import type { DocMode } from '@blocksuite/blocks';
import {
@ -122,7 +122,19 @@ export const RootAppSidebar = (): ReactElement => {
useEffect(() => {
if (environment.isDesktop) {
return events?.applicationMenu.onNewPageAction(() => onClickNewPage());
return events?.applicationMenu.onNewPageAction(() => {
apis?.ui
.isActiveTab()
.then(isActive => {
if (!isActive) {
return;
}
onClickNewPage();
})
.catch(err => {
console.error(err);
});
});
}
return;
}, [onClickNewPage]);