mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08:00
fix: should use fullscreen to control where to place macos window controls (#6351)
This commit is contained in:
@@ -60,8 +60,13 @@ export function setup() {
|
|||||||
const handleMaximized = (maximized: boolean | undefined) => {
|
const handleMaximized = (maximized: boolean | undefined) => {
|
||||||
document.documentElement.dataset.maximized = String(maximized);
|
document.documentElement.dataset.maximized = String(maximized);
|
||||||
};
|
};
|
||||||
|
const handleFullscreen = (fullscreen: boolean | undefined) => {
|
||||||
|
document.documentElement.dataset.fullscreen = String(fullscreen);
|
||||||
|
};
|
||||||
apis?.ui.isMaximized().then(handleMaximized).catch(console.error);
|
apis?.ui.isMaximized().then(handleMaximized).catch(console.error);
|
||||||
|
apis?.ui.isFullScreen().then(handleFullscreen).catch(console.error);
|
||||||
events?.ui.onMaximized(handleMaximized);
|
events?.ui.onMaximized(handleMaximized);
|
||||||
|
events?.ui.onFullScreen(handleFullscreen);
|
||||||
|
|
||||||
const handleResize = debounce(() => {
|
const handleResize = debounce(() => {
|
||||||
apis?.ui.handleWindowResize().catch(console.error);
|
apis?.ui.handleWindowResize().catch(console.error);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export const navHeaderStyle = style({
|
|||||||
});
|
});
|
||||||
|
|
||||||
globalStyle(
|
globalStyle(
|
||||||
`html[data-maximized="false"]
|
`html[data-fullscreen="false"]
|
||||||
${navHeaderStyle}[data-is-macos-electron="true"]`,
|
${navHeaderStyle}[data-is-macos-electron="true"]`,
|
||||||
{
|
{
|
||||||
paddingLeft: '90px',
|
paddingLeft: '90px',
|
||||||
|
|||||||
@@ -2,17 +2,34 @@ import { apis, events } from '@affine/electron-api';
|
|||||||
import { useAtomValue } from 'jotai';
|
import { useAtomValue } from 'jotai';
|
||||||
import { atomWithObservable } from 'jotai/utils';
|
import { atomWithObservable } from 'jotai/utils';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { Observable } from 'rxjs';
|
import { combineLatest, map, Observable } from 'rxjs';
|
||||||
|
|
||||||
import * as style from './style.css';
|
import * as style from './style.css';
|
||||||
|
|
||||||
const maximizedAtom = atomWithObservable(() => {
|
const maximized$ = new Observable<boolean>(subscriber => {
|
||||||
return new Observable<boolean>(subscriber => {
|
subscriber.next(false);
|
||||||
subscriber.next(false);
|
if (events) {
|
||||||
return events?.ui.onMaximized(maximized => {
|
return events.ui.onMaximized(res => {
|
||||||
return subscriber.next(maximized);
|
subscriber.next(res);
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
return () => {};
|
||||||
|
});
|
||||||
|
|
||||||
|
const fullscreen$ = new Observable<boolean>(subscriber => {
|
||||||
|
subscriber.next(false);
|
||||||
|
if (events) {
|
||||||
|
return events.ui.onFullScreen(res => {
|
||||||
|
subscriber.next(res);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return () => {};
|
||||||
|
});
|
||||||
|
|
||||||
|
const maximizedAtom = atomWithObservable(() => {
|
||||||
|
return combineLatest([maximized$, fullscreen$]).pipe(
|
||||||
|
map(([maximized, fullscreen]) => maximized || fullscreen)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const minimizeSVG = (
|
const minimizeSVG = (
|
||||||
|
|||||||
@@ -104,9 +104,8 @@ async function createWindow(additionalArguments: string[]) {
|
|||||||
|
|
||||||
logger.info('main window is ready to show');
|
logger.info('main window is ready to show');
|
||||||
|
|
||||||
if (browserWindow.isMaximized() || browserWindow.isFullScreen()) {
|
uiSubjects.onMaximized$.next(browserWindow.isMaximized());
|
||||||
uiSubjects.onMaximized$.next(true);
|
uiSubjects.onFullScreen$.next(browserWindow.isFullScreen());
|
||||||
}
|
|
||||||
|
|
||||||
handleWebContentsResize().catch(logger.error);
|
handleWebContentsResize().catch(logger.error);
|
||||||
});
|
});
|
||||||
@@ -143,21 +142,26 @@ async function createWindow(additionalArguments: string[]) {
|
|||||||
browserWindow.setSize(size[0], size[1]);
|
browserWindow.setSize(size[0], size[1]);
|
||||||
});
|
});
|
||||||
uiSubjects.onMaximized$.next(false);
|
uiSubjects.onMaximized$.next(false);
|
||||||
|
uiSubjects.onFullScreen$.next(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
browserWindow.on('maximize', () => {
|
browserWindow.on('maximize', () => {
|
||||||
uiSubjects.onMaximized$.next(true);
|
uiSubjects.onMaximized$.next(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
// full-screen == maximized in UI on windows
|
|
||||||
browserWindow.on('enter-full-screen', () => {
|
|
||||||
uiSubjects.onMaximized$.next(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
browserWindow.on('unmaximize', () => {
|
browserWindow.on('unmaximize', () => {
|
||||||
uiSubjects.onMaximized$.next(false);
|
uiSubjects.onMaximized$.next(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// full-screen == maximized in UI on windows
|
||||||
|
browserWindow.on('enter-full-screen', () => {
|
||||||
|
uiSubjects.onFullScreen$.next(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
browserWindow.on('leave-full-screen', () => {
|
||||||
|
uiSubjects.onFullScreen$.next(false);
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL for main window.
|
* URL for main window.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -11,4 +11,10 @@ export const uiEvents = {
|
|||||||
sub.unsubscribe();
|
sub.unsubscribe();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
onFullScreen: (fn: (fullScreen: boolean) => void) => {
|
||||||
|
const sub = uiSubjects.onFullScreen$.subscribe(fn);
|
||||||
|
return () => {
|
||||||
|
sub.unsubscribe();
|
||||||
|
};
|
||||||
|
},
|
||||||
} satisfies Record<string, MainEventRegister>;
|
} satisfies Record<string, MainEventRegister>;
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ export const uiHandlers = {
|
|||||||
const window = await getMainWindow();
|
const window = await getMainWindow();
|
||||||
return window?.isMaximized();
|
return window?.isMaximized();
|
||||||
},
|
},
|
||||||
|
isFullScreen: async () => {
|
||||||
|
const window = await getMainWindow();
|
||||||
|
return window?.isFullScreen();
|
||||||
|
},
|
||||||
handleThemeChange: async (_, theme: (typeof nativeTheme)['themeSource']) => {
|
handleThemeChange: async (_, theme: (typeof nativeTheme)['themeSource']) => {
|
||||||
nativeTheme.themeSource = theme;
|
nativeTheme.themeSource = theme;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,4 +2,5 @@ import { Subject } from 'rxjs';
|
|||||||
|
|
||||||
export const uiSubjects = {
|
export const uiSubjects = {
|
||||||
onMaximized$: new Subject<boolean>(),
|
onMaximized$: new Subject<boolean>(),
|
||||||
|
onFullScreen$: new Subject<boolean>(),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user