From 6a02d0bc96c8af902425d9a7a480311d0870bd0a Mon Sep 17 00:00:00 2001 From: BABA <38986298+BABA983@users.noreply.github.com> Date: Sat, 23 Mar 2024 21:27:05 +0800 Subject: [PATCH] feat: open about page in setting modal when click about menu (#6245) Co-authored-by: EYHN --- .../core/src/providers/modal-provider.tsx | 21 ++++++++++++++++++- .../src/main/application-menu/create.ts | 10 +++++++-- .../src/main/application-menu/index.ts | 7 +++++++ .../src/main/application-menu/subject.ts | 1 + .../frontend/electron/src/main/main-window.ts | 9 ++++++++ 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/packages/frontend/core/src/providers/modal-provider.tsx b/packages/frontend/core/src/providers/modal-provider.tsx index 7671d065a89c8..27efcd3466e8b 100644 --- a/packages/frontend/core/src/providers/modal-provider.tsx +++ b/packages/frontend/core/src/providers/modal-provider.tsx @@ -1,9 +1,16 @@ +import { events } from '@affine/electron-api'; import { WorkspaceFlavour } from '@affine/env/workspace'; import { WorkspaceManager } from '@toeverything/infra'; import { useService } from '@toeverything/infra/di'; import { useLiveData } from '@toeverything/infra/livedata'; import { useAtom } from 'jotai'; -import { lazy, type ReactElement, Suspense, useCallback } from 'react'; +import { + lazy, + type ReactElement, + Suspense, + useCallback, + useEffect, +} from 'react'; import { authAtom, @@ -116,6 +123,18 @@ export const Setting = () => { [setOpenSettingModalAtom] ); + useEffect(() => { + if (environment.isDesktop) { + return events?.applicationMenu.openAboutPageInSettingModal(() => + setOpenSettingModalAtom({ + activeTab: 'about', + open: true, + }) + ); + } + return; + }, [setOpenSettingModalAtom]); + if (!open) { return null; } diff --git a/packages/frontend/electron/src/main/application-menu/create.ts b/packages/frontend/electron/src/main/application-menu/create.ts index c34816ded4b7c..b7fd6faa438c9 100644 --- a/packages/frontend/electron/src/main/application-menu/create.ts +++ b/packages/frontend/electron/src/main/application-menu/create.ts @@ -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'; @@ -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' }, diff --git a/packages/frontend/electron/src/main/application-menu/index.ts b/packages/frontend/electron/src/main/application-menu/index.ts index 6c739346d360d..618875f2ae3b3 100644 --- a/packages/frontend/electron/src/main/application-menu/index.ts +++ b/packages/frontend/electron/src/main/application-menu/index.ts @@ -17,4 +17,11 @@ export const applicationMenuEvents = { sub.unsubscribe(); }; }, + openAboutPageInSettingModal: (fn: () => void) => { + const sub = + applicationMenuSubjects.openAboutPageInSettingModal.subscribe(fn); + return () => { + sub.unsubscribe(); + }; + }, } satisfies Record; diff --git a/packages/frontend/electron/src/main/application-menu/subject.ts b/packages/frontend/electron/src/main/application-menu/subject.ts index 01840868025fd..7d7ae54fffd87 100644 --- a/packages/frontend/electron/src/main/application-menu/subject.ts +++ b/packages/frontend/electron/src/main/application-menu/subject.ts @@ -2,4 +2,5 @@ import { Subject } from 'rxjs'; export const applicationMenuSubjects = { newPageAction: new Subject(), + openAboutPageInSettingModal: new Subject(), }; diff --git a/packages/frontend/electron/src/main/main-window.ts b/packages/frontend/electron/src/main/main-window.ts index a71e082ce16df..a00b1dd7a0839 100644 --- a/packages/frontend/electron/src/main/main-window.ts +++ b/packages/frontend/electron/src/main/main-window.ts @@ -215,6 +215,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,