mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 01:09:54 +08:00
feat: open about page in setting modal when click about menu (#6245)
Co-authored-by: EYHN <cneyhn@gmail.com>
This commit is contained in:
@@ -1,9 +1,16 @@
|
|||||||
|
import { events } from '@affine/electron-api';
|
||||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||||
import { WorkspaceManager } from '@toeverything/infra';
|
import { WorkspaceManager } from '@toeverything/infra';
|
||||||
import { useService } from '@toeverything/infra/di';
|
import { useService } from '@toeverything/infra/di';
|
||||||
import { useLiveData } from '@toeverything/infra/livedata';
|
import { useLiveData } from '@toeverything/infra/livedata';
|
||||||
import { useAtom } from 'jotai';
|
import { useAtom } from 'jotai';
|
||||||
import { lazy, type ReactElement, Suspense, useCallback } from 'react';
|
import {
|
||||||
|
lazy,
|
||||||
|
type ReactElement,
|
||||||
|
Suspense,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
} from 'react';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
authAtom,
|
authAtom,
|
||||||
@@ -116,6 +123,18 @@ export const Setting = () => {
|
|||||||
[setOpenSettingModalAtom]
|
[setOpenSettingModalAtom]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (environment.isDesktop) {
|
||||||
|
return events?.applicationMenu.openAboutPageInSettingModal(() =>
|
||||||
|
setOpenSettingModalAtom({
|
||||||
|
activeTab: 'about',
|
||||||
|
open: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}, [setOpenSettingModalAtom]);
|
||||||
|
|
||||||
if (!open) {
|
if (!open) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { app, Menu } from 'electron';
|
|||||||
|
|
||||||
import { isMacOS } from '../../shared/utils';
|
import { isMacOS } from '../../shared/utils';
|
||||||
import { revealLogFile } from '../logger';
|
import { revealLogFile } from '../logger';
|
||||||
import { initAndShowMainWindow } from '../main-window';
|
import { initAndShowMainWindow, showMainWindow } from '../main-window';
|
||||||
import { checkForUpdates } from '../updater';
|
import { checkForUpdates } from '../updater';
|
||||||
import { applicationMenuSubjects } from './subject';
|
import { applicationMenuSubjects } from './subject';
|
||||||
|
|
||||||
@@ -22,7 +22,13 @@ export function createApplicationMenu() {
|
|||||||
{
|
{
|
||||||
label: app.name,
|
label: app.name,
|
||||||
submenu: [
|
submenu: [
|
||||||
{ role: 'about' },
|
{
|
||||||
|
label: `About ${app.getName()}`,
|
||||||
|
click: async () => {
|
||||||
|
await showMainWindow();
|
||||||
|
applicationMenuSubjects.openAboutPageInSettingModal.next();
|
||||||
|
},
|
||||||
|
},
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{ role: 'services' },
|
{ role: 'services' },
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
|
|||||||
@@ -17,4 +17,11 @@ export const applicationMenuEvents = {
|
|||||||
sub.unsubscribe();
|
sub.unsubscribe();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
openAboutPageInSettingModal: (fn: () => void) => {
|
||||||
|
const sub =
|
||||||
|
applicationMenuSubjects.openAboutPageInSettingModal.subscribe(fn);
|
||||||
|
return () => {
|
||||||
|
sub.unsubscribe();
|
||||||
|
};
|
||||||
|
},
|
||||||
} satisfies Record<string, MainEventRegister>;
|
} satisfies Record<string, MainEventRegister>;
|
||||||
|
|||||||
@@ -2,4 +2,5 @@ import { Subject } from 'rxjs';
|
|||||||
|
|
||||||
export const applicationMenuSubjects = {
|
export const applicationMenuSubjects = {
|
||||||
newPageAction: new Subject<void>(),
|
newPageAction: new Subject<void>(),
|
||||||
|
openAboutPageInSettingModal: new Subject<void>(),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -215,6 +215,15 @@ export async function getMainWindow() {
|
|||||||
return window;
|
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) {
|
export async function handleOpenUrlInHiddenWindow(url: string) {
|
||||||
const win = new BrowserWindow({
|
const win = new BrowserWindow({
|
||||||
width: 1200,
|
width: 1200,
|
||||||
|
|||||||
Reference in New Issue
Block a user