Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(electron): add isMaximized flag to html #6199

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/frontend/core/src/bootstrap/setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './register-blocksuite-components';
import './edgeless-template';

import { apis, events } from '@affine/electron-api';
import { setupGlobal } from '@affine/env/global';
import * as Sentry from '@sentry/react';
import { useEffect } from 'react';
Expand Down Expand Up @@ -51,10 +52,16 @@ export function setup() {

// load persistent config for electron
// TODO: should be sync, but it's not necessary for now
environment.isDesktop &&
if (environment.isDesktop) {
appConfigProxy
.getSync()
.catch(() => console.error('failed to load app config'));
const handleMaximized = (maximized: boolean | undefined) => {
document.documentElement.dataset.maximized = String(maximized);
};
apis?.ui.isMaximized().then(handleMaximized).catch(console.error);
events?.ui.onMaximized(handleMaximized);
}

performanceSetupLogger.info('done');
}
6 changes: 5 additions & 1 deletion packages/frontend/electron-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ type ClientHandler = {
arg0: any,
...rest: infer A
) => any
? (...args: A) => Promise<ReturnType<MainHandlers[namespace][method]>>
? (
...args: A
) => ReturnType<MainHandlers[namespace][method]> extends Promise<any>
? ReturnType<MainHandlers[namespace][method]>
: Promise<ReturnType<MainHandlers[namespace][method]>>
: never;
};
} & HelperHandlers;
Expand Down
4 changes: 4 additions & 0 deletions packages/frontend/electron/src/main/main-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ async function createWindow(additionalArguments: string[]) {
);

logger.info('main window is ready to show');

if (browserWindow.isMaximized() || browserWindow.isFullScreen()) {
uiSubjects.onMaximized.next(true);
}
});

browserWindow.on('close', e => {
Expand Down
4 changes: 4 additions & 0 deletions packages/frontend/electron/src/main/ui/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import { getChallengeResponse } from './challenge';
import { getGoogleOauthCode } from './google-auth';

export const uiHandlers = {
isMaximized: async () => {
const window = await getMainWindow();
return window?.isMaximized();
},
handleThemeChange: async (_, theme: (typeof nativeTheme)['themeSource']) => {
nativeTheme.themeSource = theme;
},
Expand Down
Loading