fix(electron): window only ui (#2926)

This commit is contained in:
Alex Yang 2023-06-30 00:15:44 +08:00 committed by GitHub
parent 8021efd81a
commit 8a7908c692
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import { contextBridge, ipcRenderer } from 'electron';
contextBridge.exposeInMainWorld('appInfo', appInfo); contextBridge.exposeInMainWorld('appInfo', appInfo);
contextBridge.exposeInMainWorld('apis', apis); contextBridge.exposeInMainWorld('apis', apis);
contextBridge.exposeInMainWorld('events', events); contextBridge.exposeInMainWorld('events', events);
contextBridge.exposeInMainWorld('platform', process.platform);
// Credit to microsoft/vscode // Credit to microsoft/vscode
const globals = { const globals = {

View File

@ -140,3 +140,12 @@ test('affine onboarding button', async ({ page }) => {
expect(await onboardingModal.isVisible()).toEqual(false); expect(await onboardingModal.isVisible()).toEqual(false);
}); });
test('windows only check', async ({ page }) => {
const windowOnlyUI = page.locator('[data-platform-target=win32]');
if (process.platform === 'win32') {
await expect(windowOnlyUI).toBeVisible();
} else {
await expect(windowOnlyUI).not.toBeVisible();
}
});

View File

@ -1,5 +1,5 @@
import { migrateToSubdoc } from '@affine/env/blocksuite'; import { migrateToSubdoc } from '@affine/env/blocksuite';
import { setupGlobal } from '@affine/env/global'; import { platformSchema, setupGlobal } from '@affine/env/global';
import type { import type {
LocalIndexedDBDownloadProvider, LocalIndexedDBDownloadProvider,
WorkspaceAdapter, WorkspaceAdapter,
@ -39,6 +39,13 @@ if (!environment.isServer) {
import('@affine/bookmark-block'); import('@affine/bookmark-block');
} }
// platform check
{
if (globalThis.platform) {
platformSchema.parse(globalThis.platform);
}
}
if (!environment.isDesktop && !environment.isServer) { if (!environment.isDesktop && !environment.isServer) {
// Polyfill Electron // Polyfill Electron
const unimplemented = () => { const unimplemented = () => {

View File

@ -4,7 +4,7 @@ import {
appSidebarOpenAtom, appSidebarOpenAtom,
} from '@affine/component/app-sidebar'; } from '@affine/component/app-sidebar';
import { SidebarSwitch } from '@affine/component/app-sidebar/sidebar-header'; import { SidebarSwitch } from '@affine/component/app-sidebar/sidebar-header';
import { isBrowser, isDesktop } from '@affine/env/constant'; import { isDesktop } from '@affine/env/constant';
import { WorkspaceFlavour } from '@affine/env/workspace'; import { WorkspaceFlavour } from '@affine/env/workspace';
import { CloseIcon, MinusIcon, RoundedRectangleIcon } from '@blocksuite/icons'; import { CloseIcon, MinusIcon, RoundedRectangleIcon } from '@blocksuite/icons';
import type { Page } from '@blocksuite/store'; import type { Page } from '@blocksuite/store';
@ -123,7 +123,10 @@ const HeaderRightItems: Record<HeaderRightItemName, HeaderItem> = {
}); });
}, []); }, []);
return ( return (
<div className={styles.windowAppControlsWrapper}> <div
data-platform-target="win32"
className={styles.windowAppControlsWrapper}
>
<button <button
data-type="minimize" data-type="minimize"
className={styles.windowAppControl} className={styles.windowAppControl}
@ -149,7 +152,7 @@ const HeaderRightItems: Record<HeaderRightItemName, HeaderItem> = {
); );
}, },
availableWhen: () => { availableWhen: () => {
return isDesktop && isBrowser; return isDesktop && globalThis.platform === 'win32';
}, },
}, },
}; };

View File

@ -35,6 +35,8 @@ declare global {
events: any; events: any;
} }
// eslint-disable-next-line no-var
var platform: Platform | undefined;
// eslint-disable-next-line no-var // eslint-disable-next-line no-var
var environment: Environment; var environment: Environment;
// eslint-disable-next-line no-var // eslint-disable-next-line no-var
@ -96,6 +98,22 @@ const { publicRuntimeConfig: config } = getConfig() as {
publicRuntimeConfigSchema.parse(config); publicRuntimeConfigSchema.parse(config);
export const platformSchema = z.enum([
'aix',
'android',
'darwin',
'freebsd',
'haiku',
'linux',
'openbsd',
'sunos',
'win32',
'cygwin',
'netbsd',
]);
export type Platform = z.infer<typeof platformSchema>;
type BrowserBase = { type BrowserBase = {
/** /**
* @example https://app.affine.pro * @example https://app.affine.pro