mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
refactor: avoid runtime config object (#8202)
This commit is contained in:
@@ -46,7 +46,7 @@ export async function createFirstAppData(workspacesService: WorkspacesService) {
|
||||
return;
|
||||
}
|
||||
localStorage.setItem('is-first-open', 'false');
|
||||
if (runtimeConfig.enablePreloading) {
|
||||
if (BUILD_CONFIG.enablePreloading) {
|
||||
const { meta, defaultDocId } = await buildShowcaseWorkspace(
|
||||
workspacesService,
|
||||
WorkspaceFlavour.LOCAL,
|
||||
|
||||
@@ -23,7 +23,7 @@ export function registerAffineHelpCommands({
|
||||
label: t['com.affine.cmdk.affine.whats-new'](),
|
||||
run() {
|
||||
track.$.cmdk.help.openChangelog();
|
||||
popupWindow(runtimeConfig.changelogUrl);
|
||||
popupWindow(BUILD_CONFIG.changelogUrl);
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
@@ -50,7 +50,7 @@ function OAuthProvider({ provider }: { provider: OAuthProviderType }) {
|
||||
|
||||
const onClick = useCallback(() => {
|
||||
let oauthUrl =
|
||||
(environment.isElectron ? runtimeConfig.serverUrlPrefix : '') +
|
||||
(environment.isElectron ? BUILD_CONFIG.serverUrlPrefix : '') +
|
||||
`/oauth/login?provider=${provider}`;
|
||||
|
||||
if (environment.isElectron) {
|
||||
|
||||
@@ -48,7 +48,7 @@ interface NameWorkspaceContentProps extends ConfirmModalProps {
|
||||
) => void;
|
||||
}
|
||||
|
||||
const shouldEnableCloud = !runtimeConfig.allowLocalWorkspace;
|
||||
const shouldEnableCloud = !BUILD_CONFIG.allowLocalWorkspace;
|
||||
|
||||
const NameWorkspaceContent = ({
|
||||
loading,
|
||||
@@ -159,7 +159,7 @@ const NameWorkspaceContent = ({
|
||||
{shouldEnableCloud ? (
|
||||
<a
|
||||
className={styles.cloudTips}
|
||||
href={runtimeConfig.downloadUrl}
|
||||
href={BUILD_CONFIG.downloadUrl}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
@@ -229,7 +229,7 @@ export const CreateWorkspaceModal = ({
|
||||
|
||||
// this will be the last step for web for now
|
||||
// fix me later
|
||||
if (runtimeConfig.enablePreloading) {
|
||||
if (BUILD_CONFIG.enablePreloading) {
|
||||
const { meta, defaultDocId } = await buildShowcaseWorkspace(
|
||||
workspacesService,
|
||||
workspaceFlavour,
|
||||
|
||||
@@ -24,7 +24,7 @@ export const IssueFeedbackModal = () => {
|
||||
onOpenChange={setOpen}
|
||||
description={t['com.affine.issue-feedback.description']()}
|
||||
cancelText={t['com.affine.issue-feedback.cancel']()}
|
||||
to={`${runtimeConfig.githubUrl}/issues/new/choose`}
|
||||
to={`${BUILD_CONFIG.githubUrl}/issues/new/choose`}
|
||||
confirmText={t['com.affine.issue-feedback.confirm']()}
|
||||
confirmButtonOptions={{
|
||||
variant: 'primary',
|
||||
|
||||
@@ -21,7 +21,7 @@ export const AboutAffine = () => {
|
||||
const t = useI18n();
|
||||
const { appSettings, updateSettings } = useAppSettingHelper();
|
||||
const { toggleAutoCheck, toggleAutoDownload } = useAppUpdater();
|
||||
const channel = runtimeConfig.appBuildType;
|
||||
const channel = BUILD_CONFIG.appBuildType;
|
||||
const appIcon = appIconMap[channel];
|
||||
const appName = appNames[channel];
|
||||
|
||||
@@ -63,14 +63,14 @@ export const AboutAffine = () => {
|
||||
<SettingWrapper title={t['com.affine.aboutAFFiNE.version.title']()}>
|
||||
<SettingRow
|
||||
name={appName}
|
||||
desc={runtimeConfig.appVersion}
|
||||
desc={BUILD_CONFIG.appVersion}
|
||||
className={styles.appImageRow}
|
||||
>
|
||||
<img src={appIcon} alt={appName} width={56} height={56} />
|
||||
</SettingRow>
|
||||
<SettingRow
|
||||
name={t['com.affine.aboutAFFiNE.version.editor.title']()}
|
||||
desc={runtimeConfig.editorVersion}
|
||||
desc={BUILD_CONFIG.editorVersion}
|
||||
/>
|
||||
{environment.isElectron ? (
|
||||
<>
|
||||
@@ -100,7 +100,7 @@ export const AboutAffine = () => {
|
||||
desc={t['com.affine.aboutAFFiNE.changelog.description']()}
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => {
|
||||
popupWindow(runtimeConfig.changelogUrl);
|
||||
popupWindow(BUILD_CONFIG.changelogUrl);
|
||||
}}
|
||||
>
|
||||
<ArrowRightSmallIcon />
|
||||
|
||||
@@ -98,7 +98,7 @@ export const AppearanceSettings = () => {
|
||||
/>
|
||||
</SettingRow>
|
||||
) : null}
|
||||
{runtimeConfig.enableNewSettingUnstableApi && environment.isElectron ? (
|
||||
{BUILD_CONFIG.enableNewSettingUnstableApi && environment.isElectron ? (
|
||||
<SettingRow
|
||||
name={t['com.affine.appearanceSettings.windowFrame.title']()}
|
||||
desc={t['com.affine.appearanceSettings.windowFrame.description']()}
|
||||
@@ -118,11 +118,11 @@ export const AppearanceSettings = () => {
|
||||
/>
|
||||
</SettingRow>
|
||||
) : null}
|
||||
{runtimeConfig.enableThemeEditor ? <ThemeEditorSetting /> : null}
|
||||
{BUILD_CONFIG.enableThemeEditor ? <ThemeEditorSetting /> : null}
|
||||
</SettingWrapper>
|
||||
{/* // TODO(@JimmFly): remove Page component when stable release */}
|
||||
<Page />
|
||||
{runtimeConfig.enableNewSettingUnstableApi ? (
|
||||
{BUILD_CONFIG.enableNewSettingUnstableApi ? (
|
||||
<SettingWrapper title={t['com.affine.appearanceSettings.date.title']()}>
|
||||
<SettingRow
|
||||
name={t['com.affine.appearanceSettings.dateFormat.title']()}
|
||||
|
||||
@@ -107,7 +107,7 @@ export const useGeneralSettingList = (): GeneralSettingList => {
|
||||
}
|
||||
}
|
||||
|
||||
if (runtimeConfig.enableExperimentalFeature) {
|
||||
if (BUILD_CONFIG.enableExperimentalFeature) {
|
||||
settings.push({
|
||||
key: 'experimental-features',
|
||||
title: t['com.affine.settings.workspace.experimental-features'](),
|
||||
|
||||
@@ -24,7 +24,7 @@ export const StarAFFiNEModal = () => {
|
||||
onOpenChange={setOpen}
|
||||
description={t['com.affine.star-affine.description']()}
|
||||
cancelText={t['com.affine.star-affine.cancel']()}
|
||||
to={runtimeConfig.githubUrl}
|
||||
to={BUILD_CONFIG.githubUrl}
|
||||
confirmButtonOptions={{
|
||||
variant: 'primary',
|
||||
}}
|
||||
|
||||
@@ -89,22 +89,22 @@ const BlockSuiteEditorImpl = ({
|
||||
|
||||
// provide image proxy endpoint to blocksuite
|
||||
editor.host?.std.clipboard.use(
|
||||
customImageProxyMiddleware(runtimeConfig.imageProxyUrl)
|
||||
customImageProxyMiddleware(BUILD_CONFIG.imageProxyUrl)
|
||||
);
|
||||
ImageBlockService.setImageProxyURL(runtimeConfig.imageProxyUrl);
|
||||
ImageBlockService.setImageProxyURL(BUILD_CONFIG.imageProxyUrl);
|
||||
|
||||
// provide link preview endpoint to blocksuite
|
||||
BookmarkBlockService.setLinkPreviewEndpoint(
|
||||
runtimeConfig.linkPreviewUrl
|
||||
BUILD_CONFIG.linkPreviewUrl
|
||||
);
|
||||
EmbedGithubBlockService.setLinkPreviewEndpoint(
|
||||
runtimeConfig.linkPreviewUrl
|
||||
BUILD_CONFIG.linkPreviewUrl
|
||||
);
|
||||
EmbedYoutubeBlockService.setLinkPreviewEndpoint(
|
||||
runtimeConfig.linkPreviewUrl
|
||||
BUILD_CONFIG.linkPreviewUrl
|
||||
);
|
||||
EmbedLoomBlockService.setLinkPreviewEndpoint(
|
||||
runtimeConfig.linkPreviewUrl
|
||||
BUILD_CONFIG.linkPreviewUrl
|
||||
);
|
||||
|
||||
return editor.host?.updateComplete;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { AffineCanvasTextFonts, FontConfigExtension } from '@blocksuite/blocks';
|
||||
|
||||
export function getFontConfigExtension() {
|
||||
return FontConfigExtension(
|
||||
runtimeConfig.isSelfHosted
|
||||
BUILD_CONFIG.isSelfHosted
|
||||
? AffineCanvasTextFonts.map(font => ({
|
||||
...font,
|
||||
// self-hosted fonts are served from /assets
|
||||
|
||||
@@ -304,16 +304,13 @@ export const PageHeaderMenuButton = ({
|
||||
)}
|
||||
|
||||
<MenuSeparator />
|
||||
|
||||
{runtimeConfig.enableInfoModal && (
|
||||
<MenuItem
|
||||
prefixIcon={<InformationIcon />}
|
||||
data-testid="editor-option-menu-info"
|
||||
onSelect={openInfoModal}
|
||||
>
|
||||
{t['com.affine.page-properties.page-info.view']()}
|
||||
</MenuItem>
|
||||
)}
|
||||
<MenuItem
|
||||
prefixIcon={<InformationIcon />}
|
||||
data-testid="editor-option-menu-info"
|
||||
onSelect={openInfoModal}
|
||||
>
|
||||
{t['com.affine.page-properties.page-info.view']()}
|
||||
</MenuItem>
|
||||
{currentMode === 'page' ? (
|
||||
<MenuItem
|
||||
prefixIcon={<TocIcon />}
|
||||
|
||||
@@ -173,11 +173,9 @@ export const PageOperationCell = ({
|
||||
? t['com.affine.favoritePageOperation.remove']()
|
||||
: t['com.affine.favoritePageOperation.add']()}
|
||||
</MenuItem>
|
||||
{runtimeConfig.enableInfoModal ? (
|
||||
<MenuItem onClick={onOpenInfoModal} prefixIcon={<InformationIcon />}>
|
||||
{t['com.affine.page-properties.page-info.view']()}
|
||||
</MenuItem>
|
||||
) : null}
|
||||
<MenuItem onClick={onOpenInfoModal} prefixIcon={<InformationIcon />}>
|
||||
{t['com.affine.page-properties.page-info.view']()}
|
||||
</MenuItem>
|
||||
|
||||
<MenuItem onClick={onOpenInNewTab} prefixIcon={<OpenInNewIcon />}>
|
||||
{t['com.affine.workbench.tab.page-menu-open']()}
|
||||
|
||||
@@ -77,7 +77,7 @@ export const HelpIsland = () => {
|
||||
<StyledIconWrapper
|
||||
data-testid="right-bottom-change-log-icon"
|
||||
onClick={() => {
|
||||
popupWindow(runtimeConfig.changelogUrl);
|
||||
popupWindow(BUILD_CONFIG.changelogUrl);
|
||||
}}
|
||||
>
|
||||
<NewIcon />
|
||||
|
||||
@@ -176,7 +176,7 @@ export const RootAppSidebar = (): ReactElement => {
|
||||
</SidebarContainer>
|
||||
<SidebarScrollableContainer>
|
||||
<ExplorerFavorites />
|
||||
{runtimeConfig.enableOrganize && <ExplorerOrganize />}
|
||||
<ExplorerOrganize />
|
||||
<ExplorerMigrationFavorites />
|
||||
<ExplorerCollections />
|
||||
<ExplorerTags />
|
||||
|
||||
@@ -36,7 +36,7 @@ export const AddWorkspace = ({
|
||||
className={styles.ItemContainer}
|
||||
>
|
||||
<div className={styles.ItemText}>
|
||||
{runtimeConfig.allowLocalWorkspace
|
||||
{BUILD_CONFIG.allowLocalWorkspace
|
||||
? t['com.affine.workspaceList.addWorkspace.create']()
|
||||
: t['com.affine.workspaceList.addWorkspace.create-cloud']()}
|
||||
</div>
|
||||
|
||||
@@ -88,7 +88,7 @@ const UserWithWorkspaceListInner = ({
|
||||
}, [setOpenSignIn]);
|
||||
|
||||
const onNewWorkspace = useCallback(() => {
|
||||
if (!isAuthenticated && !runtimeConfig.allowLocalWorkspace) {
|
||||
if (!isAuthenticated && !BUILD_CONFIG.allowLocalWorkspace) {
|
||||
return openSignInModal();
|
||||
}
|
||||
track.$.navigationPanel.workspaceList.createWorkspace();
|
||||
|
||||
@@ -95,9 +95,7 @@ export function useRegisterBlocksuiteEditorCommands(editor: Editor) {
|
||||
registerAffineCommand({
|
||||
id: `editor:${mode}-view-info`,
|
||||
preconditionStrategy: () =>
|
||||
PreconditionStrategy.InPaperOrEdgeless &&
|
||||
!trash &&
|
||||
runtimeConfig.enableInfoModal,
|
||||
PreconditionStrategy.InPaperOrEdgeless && !trash,
|
||||
category: `editor:${mode}`,
|
||||
icon: mode === 'page' ? <PageIcon /> : <EdgelessIcon />,
|
||||
label: t['com.affine.page-properties.page-info.view'](),
|
||||
|
||||
@@ -177,7 +177,7 @@ export const useAppUpdater = () => {
|
||||
|
||||
const openChangelog = useAsyncCallback(async () => {
|
||||
track.$.navigationPanel.bottomButtons.openChangelog();
|
||||
popupWindow(runtimeConfig.changelogUrl);
|
||||
popupWindow(BUILD_CONFIG.changelogUrl);
|
||||
await setChangelogUnread(true);
|
||||
}, [setChangelogUnread]);
|
||||
|
||||
|
||||
@@ -32,10 +32,10 @@ function createMixpanel() {
|
||||
const wrapped = {
|
||||
init() {
|
||||
mixpanel.register({
|
||||
appVersion: runtimeConfig.appVersion,
|
||||
environment: runtimeConfig.appBuildType,
|
||||
editorVersion: runtimeConfig.editorVersion,
|
||||
isSelfHosted: Boolean(runtimeConfig.isSelfHosted),
|
||||
appVersion: BUILD_CONFIG.appVersion,
|
||||
environment: BUILD_CONFIG.appBuildType,
|
||||
editorVersion: BUILD_CONFIG.editorVersion,
|
||||
isSelfHosted: Boolean(BUILD_CONFIG.isSelfHosted),
|
||||
isDesktop: environment.isElectron,
|
||||
});
|
||||
},
|
||||
|
||||
@@ -6,7 +6,7 @@ import { BackendError, NetworkError } from '../error';
|
||||
|
||||
export function getAffineCloudBaseUrl(): string {
|
||||
if (environment.isElectron) {
|
||||
return runtimeConfig.serverUrlPrefix;
|
||||
return BUILD_CONFIG.serverUrlPrefix;
|
||||
}
|
||||
const { protocol, hostname, port } = window.location;
|
||||
return `${protocol}//${hostname}${port ? `:${port}` : ''}`;
|
||||
|
||||
@@ -35,7 +35,7 @@ interface NameWorkspaceContentProps extends ConfirmModalProps {
|
||||
) => void;
|
||||
}
|
||||
|
||||
const shouldEnableCloud = !runtimeConfig.allowLocalWorkspace;
|
||||
const shouldEnableCloud = !BUILD_CONFIG.allowLocalWorkspace;
|
||||
|
||||
const NameWorkspaceContent = ({
|
||||
loading,
|
||||
@@ -146,7 +146,7 @@ const NameWorkspaceContent = ({
|
||||
{shouldEnableCloud ? (
|
||||
<a
|
||||
className={styles.cloudTips}
|
||||
href={runtimeConfig.downloadUrl}
|
||||
href={BUILD_CONFIG.downloadUrl}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
@@ -213,7 +213,7 @@ const CreateWorkspaceDialog = () => {
|
||||
|
||||
// this will be the last step for web for now
|
||||
// fix me later
|
||||
if (runtimeConfig.enablePreloading) {
|
||||
if (BUILD_CONFIG.enablePreloading) {
|
||||
const { meta, defaultDocId } = await buildShowcaseWorkspace(
|
||||
workspacesService,
|
||||
workspaceFlavour,
|
||||
|
||||
@@ -154,21 +154,17 @@ export const useExplorerDocNodeOperations = (
|
||||
/>
|
||||
),
|
||||
},
|
||||
...(runtimeConfig.enableInfoModal
|
||||
? [
|
||||
{
|
||||
index: 50,
|
||||
view: (
|
||||
<MenuItem
|
||||
prefixIcon={<InformationIcon />}
|
||||
onClick={handleOpenInfoModal}
|
||||
>
|
||||
{t['com.affine.page-properties.page-info.view']()}
|
||||
</MenuItem>
|
||||
),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
index: 50,
|
||||
view: (
|
||||
<MenuItem
|
||||
prefixIcon={<InformationIcon />}
|
||||
onClick={handleOpenInfoModal}
|
||||
>
|
||||
{t['com.affine.page-properties.page-info.view']()}
|
||||
</MenuItem>
|
||||
),
|
||||
},
|
||||
{
|
||||
index: 99,
|
||||
view: (
|
||||
|
||||
@@ -11,7 +11,7 @@ export const useCustomTheme = (target: HTMLElement) => {
|
||||
const { resolvedTheme } = useTheme();
|
||||
|
||||
useEffect(() => {
|
||||
if (!runtimeConfig.enableThemeEditor) return;
|
||||
if (!BUILD_CONFIG.enableThemeEditor) return;
|
||||
if (_provided) return;
|
||||
|
||||
_provided = true;
|
||||
|
||||
@@ -36,7 +36,7 @@ export class UserDBDocServer implements DocServer {
|
||||
await this.socket.emitWithAck('space:join', {
|
||||
spaceType: 'userspace',
|
||||
spaceId: this.userId,
|
||||
clientVersion: runtimeConfig.appVersion,
|
||||
clientVersion: BUILD_CONFIG.appVersion,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -166,7 +166,7 @@ export class CloudAwarenessConnection implements AwarenessConnection {
|
||||
spaceType: 'workspace',
|
||||
spaceId: this.workspaceId,
|
||||
docId: this.workspaceId,
|
||||
clientVersion: runtimeConfig.appVersion,
|
||||
clientVersion: BUILD_CONFIG.appVersion,
|
||||
},
|
||||
(res: any) => {
|
||||
logger.debug('awareness handshake finished', res);
|
||||
|
||||
@@ -37,7 +37,7 @@ export class CloudDocEngineServer implements DocServer {
|
||||
await this.socket.emitWithAck('space:join', {
|
||||
spaceType: 'workspace',
|
||||
spaceId: this.workspaceId,
|
||||
clientVersion: runtimeConfig.appVersion,
|
||||
clientVersion: BUILD_CONFIG.appVersion,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ export function NormalPageHeader({ page, workspace }: PageHeaderProps) {
|
||||
{hideCollect ? null : (
|
||||
<>
|
||||
<FavoriteButton pageId={page?.id} />
|
||||
{runtimeConfig.enableInfoModal ? <InfoButton /> : null}
|
||||
<InfoButton />
|
||||
</>
|
||||
)}
|
||||
<PageHeaderMenuButton
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
export function popupWindow(target: string) {
|
||||
const url = new URL(runtimeConfig.serverUrlPrefix + '/redirect-proxy');
|
||||
const url = new URL(BUILD_CONFIG.serverUrlPrefix + '/redirect-proxy');
|
||||
target = /^https?:\/\//.test(target)
|
||||
? target
|
||||
: runtimeConfig.serverUrlPrefix + target;
|
||||
: BUILD_CONFIG.serverUrlPrefix + target;
|
||||
url.searchParams.set('redirect_uri', target);
|
||||
return window.open(url, '_blank', `noreferrer noopener`);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ interface AppUrlOptions {
|
||||
|
||||
export function buildAppUrl(path: string, opts: AppUrlOptions = {}) {
|
||||
// TODO(@EYHN): should use server base url
|
||||
const webBase = runtimeConfig.serverUrlPrefix;
|
||||
const webBase = BUILD_CONFIG.serverUrlPrefix;
|
||||
// TODO(@pengx17): how could we know the corresponding app schema in web environment
|
||||
if (opts.desktop && appInfo?.schema) {
|
||||
const urlCtor = new URL(path, webBase);
|
||||
|
||||
Reference in New Issue
Block a user