Skip to content

Commit

Permalink
update @ProtonMail web clients
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimiry committed Jul 28, 2022
1 parent c18e291 commit 69b6f63
Show file tree
Hide file tree
Showing 17 changed files with 448 additions and 237 deletions.
37 changes: 2 additions & 35 deletions patches/protonmail/common.patch
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,6 @@ index 55715b89d..c87879ad4 100755
stdio: 'inherit',
}

diff --git a/packages/pack/webpack/plugins.js b/packages/pack/webpack/plugins.js
index ec0febbc7..28181dc72 100644
--- a/packages/pack/webpack/plugins.js
+++ b/packages/pack/webpack/plugins.js
@@ -139,7 +139,7 @@ module.exports = ({ isProduction, publicPath, appMode, buildData, featureFlags,
},
}),

- ...(writeSRI
+ ...(false
? [
new SubresourceIntegrityPlugin(),
new SriStripPlugin({

diff --git a/packages/pack/webpack/css.loader.js b/packages/pack/webpack/css.loader.js
index c50ab972c..a505eb314 100644
--- a/packages/pack/webpack/css.loader.js
Expand Down Expand Up @@ -148,13 +134,13 @@ index 6edb249f3..738c4da33 100644
});
};

+/* electron-mail mark */
+/* <electron-mail-mark> */
export const createUrl = (urlString: string, params: { [key: string]: any } = {}) => {
const url = new URL(urlString, window.location.origin);
appendQueryParams(url, params);
return url;
};
+/* electron-mail mark */
+/* </electron-mail-mark> */

export const checkStatus = (response: Response, config: any) => {
const { status } = response;
Expand All @@ -171,22 +157,3 @@ index 36bd0c712..c2fb3681c 100644
if (doesNotSupportEarlyAccessVersion()) {
return;
}

diff --git a/packages/shared/lib/helpers/url.ts b/packages/shared/lib/helpers/url.ts
index d01e07cc6..74af6c896 100644
--- a/packages/shared/lib/helpers/url.ts
+++ b/packages/shared/lib/helpers/url.ts
@@ -183,12 +183,7 @@ export const getRelativeApiHostname = (hostname: string) => {
};

export const getApiSubdomainUrl = (pathname: string) => {
- const url = new URL('/', window.location.origin);
- if (url.hostname === 'localhost') {
- url.pathname = `/api${pathname}`;
- return url;
- }
- url.hostname = getRelativeApiHostname(url.hostname);
+ const url = new URL('/', '___ELECTRON_MAIL_PROTON_API_ENTRY_URL_PLACEHOLDER___');
url.pathname = pathname;
return url;
};
61 changes: 0 additions & 61 deletions patches/protonmail/constants-3.patch

This file was deleted.

24 changes: 24 additions & 0 deletions patches/protonmail/constants-4.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git a/packages/shared/lib/constants.ts b/packages/shared/lib/constants.ts
index 63e73d801..0f88b15d8 100644
--- a/packages/shared/lib/constants.ts
+++ b/packages/shared/lib/constants.ts
@@ -49,7 +49,7 @@ export const APPS = {
} as const;
export const APPS_CONFIGURATION = {
[APPS.PROTONACCOUNT]: {
- publicPath: '',
+ publicPath: '/account',
subdomain: 'account',
name: ACCOUNT_APP_NAME,
bareName: 'Account',
@@ -103,8 +103,8 @@ export const APPS_CONFIGURATION = {
settingsSlug: 'calendar',
},
[APPS.PROTONVPN_SETTINGS]: {
- publicPath: '',
- subdomain: '',
+ publicPath: 'account/vpn',
+ subdomain: 'account',
name: VPN_APP_NAME,
bareName: 'VPN',
clientID: 'web-vpn-settings',
128 changes: 128 additions & 0 deletions patches/protonmail/embedded-verification-1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
diff --git a/packages/components/containers/index.ts b/packages/components/containers/index.ts
index fd20d8e62..7c3e55c87 100644
--- a/packages/components/containers/index.ts
+++ b/packages/components/containers/index.ts
@@ -56,6 +56,5 @@ export * from './sessions';
export * from './support';
export * from './themes';
export * from './topBanners';
-export * from './verification';
export * from './v5WelcomeModal';
export * from './vpn';

diff --git a/packages/components/containers/verification/EmbeddedVerification.tsx b/packages/components/containers/verification/EmbeddedVerification.tsx
deleted file mode 100644
index 242be9084..000000000
--- a/packages/components/containers/verification/EmbeddedVerification.tsx
+++ /dev/null
@@ -1,102 +0,0 @@
-import { useEffect, useMemo, useRef, useState } from 'react';
-import { localeCode } from '@proton/shared/lib/i18n';
-import { APPS } from '@proton/shared/lib/constants';
-import { HumanVerificationMethodType } from '@proton/shared/lib/interfaces';
-import { getAppUrlFromApiUrl, getAppUrlRelativeToOrigin, stringifySearchParams } from '@proton/shared/lib/helpers/url';
-
-import { useConfig, useNotifications } from '../../hooks';
-
-interface EmbeddedVerificationProps {
- token: string;
- methods: HumanVerificationMethodType[];
- defaultCountry?: string;
- defaultEmail?: string;
- defaultPhone?: string;
- onSuccess: (token: string, tokenType: HumanVerificationMethodType) => void;
-}
-
-const EmbeddedVerification = ({
- token,
- methods,
- onSuccess,
- defaultCountry,
- defaultEmail,
- defaultPhone,
-}: EmbeddedVerificationProps) => {
- const iframeRef = useRef<HTMLIFrameElement>(null);
- const [iframeHeight, setIframeHeight] = useState<number | undefined>();
- const { API_URL } = useConfig();
- const { createNotification } = useNotifications();
-
- const embedUrl = useMemo(() => {
- if (window.location.origin.includes('localhost')) {
- return getAppUrlFromApiUrl(API_URL, APPS.PROTONVERIFICATION);
- }
-
- return getAppUrlRelativeToOrigin(window.location.origin, APPS.PROTONVERIFICATION);
- }, []);
-
- useEffect(() => {
- const handleMessage = (e: MessageEvent) => {
- const { origin, data, source } = e;
-
- const contentWindow = iframeRef.current?.contentWindow;
-
- if (!contentWindow || origin !== embedUrl.origin || !data || source !== contentWindow) {
- return;
- }
-
- const { type, payload } = JSON.parse(e.data);
-
- switch (type) {
- case 'RESIZE': {
- const { height } = payload;
- setIframeHeight(height);
- break;
- }
-
- case 'NOTIFICATION': {
- createNotification(payload);
- break;
- }
-
- case 'HUMAN_VERIFICATION_SUCCESS': {
- const { token, type } = payload;
- onSuccess(token, type);
- break;
- }
-
- default:
- }
- };
-
- window.addEventListener('message', handleMessage);
-
- return () => {
- window.removeEventListener('message', handleMessage);
- };
- }, [onSuccess]);
-
- const params = {
- methods,
- token,
- defaultCountry: defaultCountry || undefined,
- defaultEmail: defaultEmail || undefined,
- defaultPhone: defaultPhone || undefined,
- locale: localeCode,
- };
-
- const src = `${embedUrl.toString()}?${stringifySearchParams(params)}`;
-
- return (
- <iframe
- style={{ height: `${iframeHeight}px`, width: '100%' }}
- src={src}
- ref={iframeRef}
- title="verification-iframe"
- sandbox="allow-scripts allow-same-origin allow-popups"
- />
- );
-};
-
-export default EmbeddedVerification;

diff --git a/packages/components/containers/verification/index.ts b/packages/components/containers/verification/index.ts
deleted file mode 100644
index 8da2cc627..000000000
--- a/packages/components/containers/verification/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as EmbeddedVerification } from './EmbeddedVerification'
44 changes: 27 additions & 17 deletions patches/protonmail/meta.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,60 @@
{
"proton-mail": [
"common.patch",
"constants-3.patch",
"sentry-6.patch",
"url-2.patch",
"constants-4.patch",
"sentry-8.patch",
"pack-api-arg-3.patch",
"pack-webpack-config-3.patch",
"pack-webpack-4.patch",
"session-storage-3.patch",
"link-handler-5.patch",
"embedded-verification-1.patch",
"proton-mail.patch"
],
"proton-account": [
"common.patch",
"constants-3.patch",
"sentry-6.patch",
"url-2.patch",
"constants-4.patch",
"sentry-8.patch",
"pack-api-arg-3.patch",
"pack-webpack-config-3.patch",
"pack-webpack-4.patch",
"session-storage-3.patch",
"link-handler-5.patch",
"embedded-verification-1.patch",
"proton-account.patch"
],
"proton-calendar": [
"common.patch",
"constants-3.patch",
"sentry-6.patch",
"url-2.patch",
"constants-4.patch",
"sentry-7.patch",
"pack-api-arg-3.patch",
"pack-webpack-config-3.patch",
"pack-webpack-4.patch",
"session-storage-3.patch",
"link-handler-5.patch",
"session-storage-3.patch"
"embedded-verification-1.patch"
],
"proton-drive": [
"common.patch",
"constants-3.patch",
"sentry-6.patch",
"url-2.patch",
"constants-4.patch",
"sentry-8.patch",
"pack-api-arg-3.patch",
"pack-webpack-config-3.patch",
"pack-webpack-4.patch",
"session-storage-3.patch",
"link-handler-5.patch",
"embedded-verification-1.patch",
"proton-drive.patch"
],
"proton-vpn-settings": [
"common.patch",
"constants-3.patch",
"sentry-6.patch",
"url-2.patch",
"constants-4.patch",
"sentry-8.patch",
"pack-api-arg-3.patch",
"pack-webpack-config-3.patch",
"pack-webpack-4.patch",
"session-storage-3.patch",
"link-handler-5.patch"
"link-handler-5.patch",
"embedded-verification-1.patch"
]
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
diff --git a/packages/pack/webpack/plugins.js b/packages/pack/webpack/plugins.js
index 213ede7de..f8e72d6b5 100644
--- a/packages/pack/webpack/plugins.js
+++ b/packages/pack/webpack/plugins.js
@@ -124,7 +124,7 @@ module.exports = ({ isProduction, publicPath, appMode, buildData, featureFlags,
},
}),

- ...(writeSRI
+ ...(false
? [
new SubresourceIntegrityPlugin(),
new HtmlEditPlugin((tag) => {

diff --git a/packages/pack/webpack.config.js b/packages/pack/webpack.config.js
index a39cbea19..8069fc544 100644
--- a/packages/pack/webpack.config.js
Expand Down
Loading

0 comments on commit 69b6f63

Please sign in to comment.