Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: open about page in setting modal when click about menu #6245

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/frontend/core/src/components/root-app-sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AnimatedDeleteIcon } from '@affine/component';
import { openSettingModalAtom } from '@affine/core/atoms';
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
import { CollectionService } from '@affine/core/modules/collection';
import { apis, events } from '@affine/electron-api';
Expand All @@ -7,7 +8,7 @@ import { FolderIcon, SettingsIcon } from '@blocksuite/icons';
import { type Doc } from '@blocksuite/store';
import { useDroppable } from '@dnd-kit/core';
import { useLiveData, useService, type Workspace } from '@toeverything/infra';
import { useAtomValue } from 'jotai';
import { useAtomValue, useSetAtom } from 'jotai';
import { nanoid } from 'nanoid';
import type { HTMLAttributes, ReactElement } from 'react';
import { forwardRef, useCallback, useEffect } from 'react';
Expand Down Expand Up @@ -100,6 +101,7 @@ export const RootAppSidebar = ({
const docCollection = currentWorkspace.docCollection;
const t = useAFFiNEI18N();
const currentPath = useLiveData(useService(Workbench).location).pathname;
const setOpenSettingModalAtom = useSetAtom(openSettingModalAtom);

const onClickNewPage = useAsyncCallback(async () => {
const page = createPage();
Expand Down Expand Up @@ -130,6 +132,18 @@ export const RootAppSidebar = ({
return;
}, [onClickNewPage]);

useEffect(() => {
pengx17 marked this conversation as resolved.
Show resolved Hide resolved
if (environment.isDesktop) {
return events?.applicationMenu.openAboutPageInSettingModal(() =>
setOpenSettingModalAtom({
activeTab: 'about',
open: true,
})
);
}
return;
}, [setOpenSettingModalAtom]);

const sidebarOpen = useAtomValue(appSidebarOpenAtom);
useEffect(() => {
if (environment.isDesktop) {
Expand Down
10 changes: 8 additions & 2 deletions packages/frontend/electron/src/main/application-menu/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { app, Menu } from 'electron';

import { isMacOS } from '../../shared/utils';
import { revealLogFile } from '../logger';
import { initAndShowMainWindow } from '../main-window';
import { initAndShowMainWindow, showMainWindow } from '../main-window';
import { checkForUpdates } from '../updater';
import { applicationMenuSubjects } from './subject';

Expand All @@ -22,7 +22,13 @@ export function createApplicationMenu() {
{
label: app.name,
submenu: [
{ role: 'about' },
{
label: `About ${app.getName()}`,
click: async () => {
await showMainWindow();
applicationMenuSubjects.openAboutPageInSettingModal.next();
},
},
{ type: 'separator' },
{ role: 'services' },
{ type: 'separator' },
Expand Down
7 changes: 7 additions & 0 deletions packages/frontend/electron/src/main/application-menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ export const applicationMenuEvents = {
sub.unsubscribe();
};
},
openAboutPageInSettingModal: (fn: () => void) => {
const sub =
applicationMenuSubjects.openAboutPageInSettingModal.subscribe(fn);
return () => {
sub.unsubscribe();
};
},
} satisfies Record<string, MainEventRegister>;
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import { Subject } from 'rxjs';

export const applicationMenuSubjects = {
newPageAction: new Subject<void>(),
openAboutPageInSettingModal: new Subject<void>(),
};
9 changes: 9 additions & 0 deletions packages/frontend/electron/src/main/main-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ export async function getMainWindow() {
return window;
}

export async function showMainWindow() {
const window = await getMainWindow();
if (!window) return;
if (window.isMinimized()) {
window.restore();
}
window.focus();
}

export async function handleOpenUrlInHiddenWindow(url: string) {
const win = new BrowserWindow({
width: 1200,
Expand Down
Loading