Skip to content

Commit

Permalink
feat(core): build config for ios android (toeverything#8555)
Browse files Browse the repository at this point in the history
  • Loading branch information
EYHN committed Oct 21, 2024
1 parent d1783b6 commit db374f7
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 12 deletions.
4 changes: 3 additions & 1 deletion packages/common/env/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
*/
Expand All @@ -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
/**
Expand Down
6 changes: 5 additions & 1 deletion packages/frontend/component/src/ui/safe-area/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export const SafeArea = forwardRef<HTMLDivElement, SafeAreaProps>(
<div
ref={ref}
className={clsx(safeArea, className)}
data-standalone={environment.isPwa ? '' : undefined}
data-standalone={
environment.isPwa || BUILD_CONFIG.isAndroid || BUILD_CONFIG.isIOS
? ''
: undefined
}
data-bottom={bottom ? '' : undefined}
data-top={top ? '' : undefined}
style={{
Expand Down
5 changes: 3 additions & 2 deletions packages/frontend/core/src/components/affine/auth/oauth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ function OAuthProvider({ provider }: { provider: OAuthProviderType }) {

const onClick = useCallback(() => {
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}`;
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/core/src/modules/cloud/services/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions packages/frontend/core/src/utils/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion tools/cli/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 3 additions & 1 deletion tools/cli/src/webpack/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '/';
}
Expand Down
2 changes: 2 additions & 0 deletions tools/cli/src/webpack/runtime-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion tools/cli/src/webpack/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ export function createWebpackConfig(cwd: string, flags: BuildFlags) {
PRECONNECT: cdnOrigin
? `<link rel="preconnect" href="${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) => {
Expand Down

0 comments on commit db374f7

Please sign in to comment.