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