From db374f7feb735d5022e3d77586e2fc6850596010 Mon Sep 17 00:00:00 2001 From: EYHN Date: Mon, 21 Oct 2024 05:39:04 +0000 Subject: [PATCH] feat(core): build config for ios android (#8555) --- packages/common/env/src/global.ts | 4 +++- packages/frontend/component/src/ui/safe-area/index.tsx | 6 +++++- .../frontend/core/src/components/affine/auth/oauth.tsx | 5 +++-- packages/frontend/core/src/modules/cloud/services/fetch.ts | 2 +- packages/frontend/core/src/utils/popup.ts | 7 ++++--- packages/frontend/graphql/src/index.ts | 2 +- tools/cli/src/config/index.ts | 2 +- tools/cli/src/webpack/config.ts | 4 +++- tools/cli/src/webpack/runtime-config.ts | 2 ++ tools/cli/src/webpack/webpack.config.ts | 7 ++++++- 10 files changed, 29 insertions(+), 12 deletions(-) diff --git a/packages/common/env/src/global.ts b/packages/common/env/src/global.ts index 6e5774222d..1f7d149793 100644 --- a/packages/common/env/src/global.ts +++ b/packages/common/env/src/global.ts @@ -2,7 +2,7 @@ import { UaHelper } from './ua-helper.js'; export type BUILD_CONFIG_TYPE = { debug: boolean; - distribution: 'web' | 'desktop' | 'admin' | 'mobile'; + distribution: 'web' | 'desktop' | 'admin' | 'mobile' | 'ios' | 'android'; /** * 'web' | 'desktop' | 'admin' */ @@ -15,6 +15,8 @@ export type BUILD_CONFIG_TYPE = { isElectron: boolean; isWeb: boolean; isMobileWeb: boolean; + isIOS: boolean; + isAndroid: boolean; // this is for the electron app /** diff --git a/packages/frontend/component/src/ui/safe-area/index.tsx b/packages/frontend/component/src/ui/safe-area/index.tsx index 54f480a303..1d0a8904ae 100644 --- a/packages/frontend/component/src/ui/safe-area/index.tsx +++ b/packages/frontend/component/src/ui/safe-area/index.tsx @@ -30,7 +30,11 @@ export const SafeArea = forwardRef(
{ let oauthUrl = - (BUILD_CONFIG.isElectron ? BUILD_CONFIG.serverUrlPrefix : '') + - `/oauth/login?provider=${provider}`; + (BUILD_CONFIG.isElectron || BUILD_CONFIG.isIOS || BUILD_CONFIG.isAndroid + ? BUILD_CONFIG.serverUrlPrefix + : '') + `/oauth/login?provider=${provider}`; if (BUILD_CONFIG.isElectron) { oauthUrl += `&client=${appInfo?.schema}`; diff --git a/packages/frontend/core/src/modules/cloud/services/fetch.ts b/packages/frontend/core/src/modules/cloud/services/fetch.ts index c37334ecb3..c164b051d7 100644 --- a/packages/frontend/core/src/modules/cloud/services/fetch.ts +++ b/packages/frontend/core/src/modules/cloud/services/fetch.ts @@ -5,7 +5,7 @@ import { fromPromise, Service } from '@toeverything/infra'; import { BackendError, NetworkError } from '../error'; export function getAffineCloudBaseUrl(): string { - if (BUILD_CONFIG.isElectron) { + if (BUILD_CONFIG.isElectron || BUILD_CONFIG.isIOS || BUILD_CONFIG.isAndroid) { return BUILD_CONFIG.serverUrlPrefix; } const { protocol, hostname, port } = window.location; diff --git a/packages/frontend/core/src/utils/popup.ts b/packages/frontend/core/src/utils/popup.ts index 3aafc087a3..04e6088fd2 100644 --- a/packages/frontend/core/src/utils/popup.ts +++ b/packages/frontend/core/src/utils/popup.ts @@ -3,9 +3,10 @@ import { apis } from '@affine/electron-api'; const logger = new DebugLogger('popup'); -const origin = BUILD_CONFIG.isElectron - ? BUILD_CONFIG.serverUrlPrefix - : location.origin; +const origin = + BUILD_CONFIG.isElectron || BUILD_CONFIG.isIOS || BUILD_CONFIG.isAndroid + ? BUILD_CONFIG.serverUrlPrefix + : location.origin; /** * @deprecated need to be refactored as [UrlService] dependencies on [ServerConfigService] diff --git a/packages/frontend/graphql/src/index.ts b/packages/frontend/graphql/src/index.ts index 8e6b547371..7ad9c47580 100644 --- a/packages/frontend/graphql/src/index.ts +++ b/packages/frontend/graphql/src/index.ts @@ -10,7 +10,7 @@ import { gqlFetcherFactory } from './fetcher'; setupGlobal(); export function getBaseUrl(): string { - if (BUILD_CONFIG.isElectron) { + if (BUILD_CONFIG.isElectron || BUILD_CONFIG.isIOS || BUILD_CONFIG.isAndroid) { return BUILD_CONFIG.serverUrlPrefix; } if (typeof window === 'undefined') { diff --git a/tools/cli/src/config/index.ts b/tools/cli/src/config/index.ts index 161ea2f2f7..f4452c5da0 100644 --- a/tools/cli/src/config/index.ts +++ b/tools/cli/src/config/index.ts @@ -1,5 +1,5 @@ export type BuildFlags = { - distribution: 'web' | 'desktop' | 'admin' | 'mobile'; + distribution: 'web' | 'desktop' | 'admin' | 'mobile' | 'ios' | 'android'; mode: 'development' | 'production'; channel: 'stable' | 'beta' | 'canary' | 'internal'; static: boolean; diff --git a/tools/cli/src/webpack/config.ts b/tools/cli/src/webpack/config.ts index a4a63c05d2..6b5b001fb3 100644 --- a/tools/cli/src/webpack/config.ts +++ b/tools/cli/src/webpack/config.ts @@ -69,7 +69,9 @@ export const getPublicPath = (buildFlags: BuildFlags) => { if ( buildFlags.mode === 'development' || process.env.COVERAGE || - buildFlags.distribution === 'desktop' + buildFlags.distribution === 'desktop' || + buildFlags.distribution === 'ios' || + buildFlags.distribution === 'android' ) { return '/'; } diff --git a/tools/cli/src/webpack/runtime-config.ts b/tools/cli/src/webpack/runtime-config.ts index 380581ea1d..88ee8399a4 100644 --- a/tools/cli/src/webpack/runtime-config.ts +++ b/tools/cli/src/webpack/runtime-config.ts @@ -18,6 +18,8 @@ export function getBuildConfig(buildFlags: BuildFlags): BUILD_CONFIG_TYPE { isElectron: buildFlags.distribution === 'desktop', isWeb: buildFlags.distribution === 'web', isMobileWeb: buildFlags.distribution === 'mobile', + isIOS: buildFlags.distribution === 'ios', + isAndroid: buildFlags.distribution === 'android', isSelfHosted: process.env.SELF_HOSTED === 'true', appBuildType: 'stable' as const, diff --git a/tools/cli/src/webpack/webpack.config.ts b/tools/cli/src/webpack/webpack.config.ts index 9fda8dd2d0..dbeb696fb4 100644 --- a/tools/cli/src/webpack/webpack.config.ts +++ b/tools/cli/src/webpack/webpack.config.ts @@ -58,7 +58,12 @@ export function createWebpackConfig(cwd: string, flags: BuildFlags) { PRECONNECT: cdnOrigin ? `` : '', - VIEWPORT_FIT: flags.distribution === 'mobile' ? 'cover' : 'auto', + VIEWPORT_FIT: + flags.distribution === 'mobile' || + flags.distribution === 'ios' || + flags.distribution === 'android' + ? 'cover' + : 'auto', }; const createHTMLPlugins = (entryName: string) => {