mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-20 03:26:47 +08:00
refactor: migrate environment to BUILD_CONFIG (#8206)
This commit is contained in:
@@ -303,7 +303,8 @@ export const AppTabsHeader = ({
|
||||
const sidebarWidth = useAtomValue(appSidebarWidthAtom);
|
||||
const sidebarOpen = useAtomValue(appSidebarOpenAtom);
|
||||
const sidebarResizing = useAtomValue(appSidebarResizingAtom);
|
||||
const isMacosDesktop = environment.isElectron && environment.isMacOs;
|
||||
const isMacosDesktop = BUILD_CONFIG.isElectron && environment.isMacOs;
|
||||
const isWindowsDesktop = BUILD_CONFIG.isElectron && environment.isWindows;
|
||||
const fullScreen = useIsFullScreen();
|
||||
|
||||
const tabsHeaderService = useService(AppTabsHeaderService);
|
||||
@@ -412,7 +413,7 @@ export const AppTabsHeader = ({
|
||||
className={clsx(styles.root, className)}
|
||||
style={style}
|
||||
data-mode={mode}
|
||||
data-is-windows={environment.isElectron && environment.isWindows}
|
||||
data-is-windows={isWindowsDesktop}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
@@ -473,9 +474,9 @@ export const AppTabsHeader = ({
|
||||
<IconButton size="24" onClick={onToggleRightSidebar}>
|
||||
<RightSidebarIcon />
|
||||
</IconButton>
|
||||
{environment.isElectron && environment.isWindows ? (
|
||||
{isWindowsDesktop && (
|
||||
<div className={styles.windowsAppControlsPlaceholder} />
|
||||
) : null}
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -91,7 +91,7 @@ export class AuthService extends Service {
|
||||
email,
|
||||
// we call it [callbackUrl] instead of [redirect_uri]
|
||||
// to make it clear the url is used to finish the sign-in process instead of redirect after signed-in
|
||||
callbackUrl: `/magic-link?client=${environment.isElectron ? appInfo?.schema : 'web'}`,
|
||||
callbackUrl: `/magic-link?client=${BUILD_CONFIG.isElectron ? appInfo?.schema : 'web'}`,
|
||||
}),
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
|
||||
@@ -5,7 +5,7 @@ import { fromPromise, Service } from '@toeverything/infra';
|
||||
import { BackendError, NetworkError } from '../error';
|
||||
|
||||
export function getAffineCloudBaseUrl(): string {
|
||||
if (environment.isElectron) {
|
||||
if (BUILD_CONFIG.isElectron) {
|
||||
return BUILD_CONFIG.serverUrlPrefix;
|
||||
}
|
||||
const { protocol, hostname, port } = window.location;
|
||||
|
||||
@@ -28,7 +28,7 @@ const getDefaultSubscriptionSuccessCallbackLink = (
|
||||
plan === SubscriptionPlan.AI ? '/ai-upgrade-success' : '/upgrade-success';
|
||||
const urlString = getAffineCloudBaseUrl() + path;
|
||||
const url = new URL(urlString);
|
||||
if (environment.isElectron && appInfo) {
|
||||
if (BUILD_CONFIG.isElectron && appInfo) {
|
||||
url.searchParams.set('schema', appInfo.schema);
|
||||
}
|
||||
return url.toString();
|
||||
|
||||
@@ -183,7 +183,7 @@ export const useExplorerCollectionNodeOperations = (
|
||||
</MenuItem>
|
||||
),
|
||||
},
|
||||
...(environment.isElectron && enableMultiView
|
||||
...(BUILD_CONFIG.isElectron && enableMultiView
|
||||
? [
|
||||
{
|
||||
index: 99,
|
||||
|
||||
@@ -192,7 +192,7 @@ export const useExplorerDocNodeOperations = (
|
||||
</MenuItem>
|
||||
),
|
||||
},
|
||||
...(enableMultiView && environment.isElectron
|
||||
...(BUILD_CONFIG.isElectron && enableMultiView
|
||||
? [
|
||||
{
|
||||
index: 100,
|
||||
|
||||
@@ -119,7 +119,7 @@ export const useExplorerTagNodeOperations = (
|
||||
</MenuItem>
|
||||
),
|
||||
},
|
||||
...(enableMultiView && environment.isElectron
|
||||
...(BUILD_CONFIG.isElectron && enableMultiView
|
||||
? [
|
||||
{
|
||||
index: 100,
|
||||
|
||||
@@ -40,7 +40,7 @@ export class Navigator extends Entity {
|
||||
);
|
||||
|
||||
back() {
|
||||
if (!environment.isElectron) {
|
||||
if (!BUILD_CONFIG.isElectron) {
|
||||
window.history.back();
|
||||
} else {
|
||||
this.history$.value.back();
|
||||
@@ -48,7 +48,7 @@ export class Navigator extends Entity {
|
||||
}
|
||||
|
||||
forward() {
|
||||
if (!environment.isElectron) {
|
||||
if (!BUILD_CONFIG.isElectron) {
|
||||
window.history.forward();
|
||||
} else {
|
||||
this.history$.value.forward();
|
||||
|
||||
@@ -10,6 +10,14 @@ import * as styles from './navigation-buttons.css';
|
||||
const tooltipSideBottom = { side: 'bottom' as const };
|
||||
|
||||
export const NavigationButtons = () => {
|
||||
if (!BUILD_CONFIG.isElectron) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <ElectronNavigationButtons />;
|
||||
};
|
||||
|
||||
const ElectronNavigationButtons = () => {
|
||||
const t = useI18n();
|
||||
|
||||
const navigator = useService(NavigatorService).navigator;
|
||||
@@ -44,10 +52,6 @@ export const NavigationButtons = () => {
|
||||
};
|
||||
}, [navigator]);
|
||||
|
||||
if (!environment.isElectron) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<IconButton
|
||||
|
||||
@@ -129,7 +129,7 @@ export const DocPeekViewControls = ({
|
||||
peekView.close('none');
|
||||
},
|
||||
},
|
||||
environment.isElectron && {
|
||||
BUILD_CONFIG.isElectron && {
|
||||
icon: <SplitViewIcon />,
|
||||
nameKey: 'split-view',
|
||||
name: t['com.affine.peek-view-controls.open-doc-in-split-view'](),
|
||||
|
||||
@@ -13,7 +13,7 @@ export class DesktopStateSynchronizer extends Service {
|
||||
}
|
||||
|
||||
startSync = () => {
|
||||
if (!environment.isElectron) {
|
||||
if (!BUILD_CONFIG.isElectron) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ export const RouteContainer = () => {
|
||||
return (
|
||||
<div className={styles.root}>
|
||||
<div className={styles.header}>
|
||||
{viewPosition.isFirst && !environment.isElectron && (
|
||||
{!BUILD_CONFIG.isElectron && viewPosition.isFirst && (
|
||||
<SidebarSwitch
|
||||
show={!leftSidebarOpen}
|
||||
className={styles.leftSidebarButton}
|
||||
@@ -64,7 +64,7 @@ export const RouteContainer = () => {
|
||||
viewId={view.id}
|
||||
className={styles.viewHeaderContainer}
|
||||
/>
|
||||
{viewPosition.isLast && !environment.isElectron && (
|
||||
{!BUILD_CONFIG.isElectron && viewPosition.isLast && (
|
||||
<ToggleButton
|
||||
show={!sidebarOpen}
|
||||
className={styles.rightSidebarButton}
|
||||
|
||||
@@ -38,7 +38,7 @@ export const SidebarContainer = ({
|
||||
viewId={view.id}
|
||||
className={clsx(
|
||||
styles.sidebarBodyTarget,
|
||||
!environment.isElectron && styles.borderTop
|
||||
!BUILD_CONFIG.isElectron && styles.borderTop
|
||||
)}
|
||||
/>
|
||||
))
|
||||
|
||||
@@ -44,7 +44,7 @@ export const Header = ({ floating, children, onToggle }: HeaderProps) => {
|
||||
return (
|
||||
<Container className={styles.header} floating={floating}>
|
||||
{children}
|
||||
{!environment.isElectron && (
|
||||
{!BUILD_CONFIG.isElectron && (
|
||||
<>
|
||||
<div className={styles.spacer} />
|
||||
<ToggleButton onToggle={onToggle} />
|
||||
|
||||
@@ -40,7 +40,7 @@ export const WorkbenchLink = forwardRef<HTMLAnchorElement, WorkbenchLinkProps>(
|
||||
}
|
||||
const at = (() => {
|
||||
if (isNewTabTrigger(event)) {
|
||||
return event.altKey && enableMultiView && environment.isElectron
|
||||
return BUILD_CONFIG.isElectron && event.altKey && enableMultiView
|
||||
? 'tail'
|
||||
: 'new-tab';
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import { ViewIslandRegistryProvider } from './view-islands';
|
||||
import { ViewRoot } from './view-root';
|
||||
import * as styles from './workbench-root.css';
|
||||
|
||||
const useAdapter = environment.isElectron
|
||||
const useAdapter = BUILD_CONFIG.isElectron
|
||||
? useBindWorkbenchToDesktopRouter
|
||||
: useBindWorkbenchToBrowserRouter;
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ export class LocalWorkspaceFlavourProvider
|
||||
JSON.stringify(allWorkspaceIDs.filter(x => x !== id))
|
||||
);
|
||||
|
||||
if (apis && environment.isElectron) {
|
||||
if (BUILD_CONFIG.isElectron && apis) {
|
||||
await apis.workspace.delete(id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user