mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
feat(electron): more desktop app related shortcuts (#9724)
fix AF-2126, AF-2124 - Add CMD+M for minimize the app. - Enhance how CMD+W works. Close the following in order, stop if any one is closed: - peek view - split view - tab - otherwise, hide the app
This commit is contained in:
@@ -2,10 +2,10 @@ import { app, Menu } from 'electron';
|
||||
|
||||
import { isMacOS } from '../../shared/utils';
|
||||
import { logger, revealLogFile } from '../logger';
|
||||
import { uiSubjects } from '../ui/subject';
|
||||
import { checkForUpdates } from '../updater';
|
||||
import {
|
||||
addTab,
|
||||
closeTab,
|
||||
initAndShowMainWindow,
|
||||
reloadView,
|
||||
showDevTools,
|
||||
@@ -103,6 +103,9 @@ export function createApplicationMenu() {
|
||||
reloadView().catch(console.error);
|
||||
},
|
||||
},
|
||||
{
|
||||
role: 'windowMenu',
|
||||
},
|
||||
{
|
||||
label: 'Open devtools',
|
||||
accelerator: isMac ? 'Cmd+Option+I' : 'Ctrl+Shift+I',
|
||||
@@ -129,11 +132,12 @@ export function createApplicationMenu() {
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Close tab',
|
||||
label: 'Close view',
|
||||
accelerator: 'CommandOrControl+W',
|
||||
click() {
|
||||
logger.info('Close tab with shortcut');
|
||||
closeTab().catch(console.error);
|
||||
logger.info('Close view with shortcut');
|
||||
// tell the active workbench to close the current view
|
||||
uiSubjects.onCloseView$.next();
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -195,7 +199,7 @@ export function createApplicationMenu() {
|
||||
{
|
||||
label: 'Learn More',
|
||||
click: async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
// oxlint-disable-next-line
|
||||
const { shell } = require('electron');
|
||||
await shell.openExternal('https://affine.pro/');
|
||||
},
|
||||
@@ -216,7 +220,7 @@ export function createApplicationMenu() {
|
||||
{
|
||||
label: 'Documentation',
|
||||
click: async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
// oxlint-disable-next-line
|
||||
const { shell } = require('electron');
|
||||
await shell.openExternal(
|
||||
'https://docs.affine.pro/docs/hello-bonjour-aloha-你好'
|
||||
|
||||
@@ -42,4 +42,10 @@ export const uiEvents = {
|
||||
sub.unsubscribe();
|
||||
};
|
||||
},
|
||||
onCloseView: (fn: () => void) => {
|
||||
const sub = uiSubjects.onCloseView$.subscribe(fn);
|
||||
return () => {
|
||||
sub.unsubscribe();
|
||||
};
|
||||
},
|
||||
} satisfies Record<string, MainEventRegister>;
|
||||
|
||||
@@ -71,6 +71,10 @@ export const uiHandlers = {
|
||||
handleCloseApp: async () => {
|
||||
app.quit();
|
||||
},
|
||||
handleHideApp: async () => {
|
||||
const window = await getMainWindow();
|
||||
window?.hide();
|
||||
},
|
||||
handleNetworkChange: async (_, _isOnline: boolean) => {
|
||||
isOnline = _isOnline;
|
||||
},
|
||||
@@ -191,6 +195,7 @@ export const uiHandlers = {
|
||||
closeTab: async (_, ...args: Parameters<typeof closeTab>) => {
|
||||
await closeTab(...args);
|
||||
},
|
||||
|
||||
activateView: async (_, ...args: Parameters<typeof activateView>) => {
|
||||
await activateView(...args);
|
||||
},
|
||||
|
||||
@@ -7,4 +7,6 @@ export const uiSubjects = {
|
||||
onFullScreen$: new Subject<boolean>(),
|
||||
onToggleRightSidebar$: new Subject<string>(),
|
||||
authenticationRequest$: new Subject<AuthenticationRequest>(),
|
||||
// via menu -> close view (CMD+W)
|
||||
onCloseView$: new Subject<void>(),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user