mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-23 17:54:03 +03:00
fix(electron): window only ui (#2926)
This commit is contained in:
parent
8021efd81a
commit
8a7908c692
@ -7,6 +7,7 @@ import { contextBridge, ipcRenderer } from 'electron';
|
||||
contextBridge.exposeInMainWorld('appInfo', appInfo);
|
||||
contextBridge.exposeInMainWorld('apis', apis);
|
||||
contextBridge.exposeInMainWorld('events', events);
|
||||
contextBridge.exposeInMainWorld('platform', process.platform);
|
||||
|
||||
// Credit to microsoft/vscode
|
||||
const globals = {
|
||||
|
@ -140,3 +140,12 @@ test('affine onboarding button', async ({ page }) => {
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { migrateToSubdoc } from '@affine/env/blocksuite';
|
||||
import { setupGlobal } from '@affine/env/global';
|
||||
import { platformSchema, setupGlobal } from '@affine/env/global';
|
||||
import type {
|
||||
LocalIndexedDBDownloadProvider,
|
||||
WorkspaceAdapter,
|
||||
@ -39,6 +39,13 @@ if (!environment.isServer) {
|
||||
import('@affine/bookmark-block');
|
||||
}
|
||||
|
||||
// platform check
|
||||
{
|
||||
if (globalThis.platform) {
|
||||
platformSchema.parse(globalThis.platform);
|
||||
}
|
||||
}
|
||||
|
||||
if (!environment.isDesktop && !environment.isServer) {
|
||||
// Polyfill Electron
|
||||
const unimplemented = () => {
|
||||
|
@ -4,7 +4,7 @@ import {
|
||||
appSidebarOpenAtom,
|
||||
} from '@affine/component/app-sidebar';
|
||||
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 { CloseIcon, MinusIcon, RoundedRectangleIcon } from '@blocksuite/icons';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
@ -123,7 +123,10 @@ const HeaderRightItems: Record<HeaderRightItemName, HeaderItem> = {
|
||||
});
|
||||
}, []);
|
||||
return (
|
||||
<div className={styles.windowAppControlsWrapper}>
|
||||
<div
|
||||
data-platform-target="win32"
|
||||
className={styles.windowAppControlsWrapper}
|
||||
>
|
||||
<button
|
||||
data-type="minimize"
|
||||
className={styles.windowAppControl}
|
||||
@ -149,7 +152,7 @@ const HeaderRightItems: Record<HeaderRightItemName, HeaderItem> = {
|
||||
);
|
||||
},
|
||||
availableWhen: () => {
|
||||
return isDesktop && isBrowser;
|
||||
return isDesktop && globalThis.platform === 'win32';
|
||||
},
|
||||
},
|
||||
};
|
||||
|
18
packages/env/src/global.ts
vendored
18
packages/env/src/global.ts
vendored
@ -35,6 +35,8 @@ declare global {
|
||||
events: any;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-var
|
||||
var platform: Platform | undefined;
|
||||
// eslint-disable-next-line no-var
|
||||
var environment: Environment;
|
||||
// eslint-disable-next-line no-var
|
||||
@ -96,6 +98,22 @@ const { publicRuntimeConfig: config } = getConfig() as {
|
||||
|
||||
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 = {
|
||||
/**
|
||||
* @example https://app.affine.pro
|
||||
|
Loading…
Reference in New Issue
Block a user