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 Oct 5, 2023
1 parent 98865ed commit c4f835f
Show file tree
Hide file tree
Showing 5 changed files with 323 additions and 11 deletions.
63 changes: 63 additions & 0 deletions patches/protonmail/common-5.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
diff --git a/packages/components/containers/unleash/UnleashFlagProvider.tsx b/packages/components/containers/unleash/UnleashFlagProvider.tsx
index 1531d1450b..a8a8d44677 100644
--- a/packages/components/containers/unleash/UnleashFlagProvider.tsx
+++ b/packages/components/containers/unleash/UnleashFlagProvider.tsx
@@ -3,20 +3,21 @@ import { ReactNode } from 'react';
import FlagProvider from '@unleash/proxy-client-react';
import { IConfig } from 'unleash-proxy-client';

-import { Api } from '@proton/shared/lib/interfaces';
+import { Api, ProtonConfig } from '@proton/shared/lib/interfaces';

import useApi from '../../hooks/useApi';
+import { useConfig } from '@proton/components/hooks';

// Just something dummy to have a valid domain because the library does new URL
const prefix = 'https://proton.me/';
const url = new URL(prefix);

const customFetch =
- (api: Api): typeof window.fetch =>
+ (api: Api, {API_URL}: ProtonConfig): typeof window.fetch =>
(url, config) => {
if (typeof url === 'string') {
return api({
- url: `feature/v2/frontend${url.replace(prefix, '')}`,
+ url: `${API_URL}/feature/v2/frontend${url.replace(prefix, '')}`,
headers: config?.headers,
silence: true,
output: 'raw',
@@ -30,6 +31,7 @@ interface Props {
}

const UnleashFlagProvider = ({ children }: Props) => {
+ const config = useConfig();
const api = useApi();
const unleashConfig: IConfig = {
url,
@@ -37,7 +39,7 @@ const UnleashFlagProvider = ({ children }: Props) => {
appName: '-', // set by the server
refreshInterval: 600, // refreshInterval in seconds, 10 mins
disableMetrics: true,
- fetch: customFetch(api),
+ fetch: customFetch(api, config),
};

return <FlagProvider config={unleashConfig}>{children}</FlagProvider>;

diff --git a/packages/pack/scripts/validate.sh b/packages/pack/scripts/validate.sh
index 1a2ea64..bae388c 100755
--- a/packages/pack/scripts/validate.sh
Expand Down Expand Up @@ -106,6 +153,22 @@ index 36bd0c712..c2fb3681c 100644
return;
}

diff --git a/applications/mail/src/app/components/list/auto-delete/variations/AutoDeleteFreeBanner.tsx b/applications/mail/src/app/components/list/auto-delete/variations/AutoDeleteFreeBanner.tsx
index 24c56ef6fe..a6046b391c 100644
--- a/applications/mail/src/app/components/list/auto-delete/variations/AutoDeleteFreeBanner.tsx
+++ b/applications/mail/src/app/components/list/auto-delete/variations/AutoDeleteFreeBanner.tsx
@@ -7,6 +7,10 @@ import { AutoDeleteUpsellModal, useModalState } from '@proton/components/compone
import { PromotionBanner } from '@proton/components/containers';

const AutoDeleteFreeBanner = () => {
+ if (___ELECTRON_MAIL_PROTON_SUPPRESS_UPSELL_ADS_PLACEHOLDER___) {
+ return null;
+ }
+
const [upsellModalProps, toggleUpsellModal, renderUpsellModal] = useModalState();

return (

diff --git a/applications/mail/src/app/hooks/useShowUpsellBanner.ts b/applications/mail/src/app/hooks/useShowUpsellBanner.ts
index d203f913fa..178153c592 100644
--- a/applications/mail/src/app/hooks/useShowUpsellBanner.ts
Expand Down
16 changes: 16 additions & 0 deletions patches/protonmail/common-6.patch
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@ index 36bd0c712..c2fb3681c 100644
return;
}

diff --git a/applications/mail/src/app/components/list/auto-delete/variations/AutoDeleteFreeBanner.tsx b/applications/mail/src/app/components/list/auto-delete/variations/AutoDeleteFreeBanner.tsx
index 24c56ef6fe..a6046b391c 100644
--- a/applications/mail/src/app/components/list/auto-delete/variations/AutoDeleteFreeBanner.tsx
+++ b/applications/mail/src/app/components/list/auto-delete/variations/AutoDeleteFreeBanner.tsx
@@ -7,6 +7,10 @@ import { AutoDeleteUpsellModal, useModalState } from '@proton/components/compone
import { PromotionBanner } from '@proton/components/containers';

const AutoDeleteFreeBanner = () => {
+ if (___ELECTRON_MAIL_PROTON_SUPPRESS_UPSELL_ADS_PLACEHOLDER___) {
+ return null;
+ }
+
const [upsellModalProps, toggleUpsellModal, renderUpsellModal] = useModalState();

return (

diff --git a/applications/mail/src/app/hooks/useShowUpsellBanner.ts b/applications/mail/src/app/hooks/useShowUpsellBanner.ts
index d203f913fa..178153c592 100644
--- a/applications/mail/src/app/hooks/useShowUpsellBanner.ts
Expand Down
233 changes: 233 additions & 0 deletions patches/protonmail/common-7.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
diff --git a/packages/components/containers/unleash/UnleashFlagProvider.tsx b/packages/components/containers/unleash/UnleashFlagProvider.tsx
index 1531d1450b..a8a8d44677 100644
--- a/packages/components/containers/unleash/UnleashFlagProvider.tsx
+++ b/packages/components/containers/unleash/UnleashFlagProvider.tsx
@@ -3,20 +3,21 @@ import { ReactNode } from 'react';
import FlagProvider from '@unleash/proxy-client-react';
import { IConfig } from 'unleash-proxy-client';

-import { Api } from '@proton/shared/lib/interfaces';
+import { Api, ProtonConfig } from '@proton/shared/lib/interfaces';

import useApi from '../../hooks/useApi';
+import { useConfig } from '@proton/components/hooks';

// Just something dummy to have a valid domain because the library does new URL
const prefix = 'https://proton.me/';
const url = new URL(prefix);

const customFetch =
- (api: Api): typeof window.fetch =>
+ (api: Api, {API_URL}: ProtonConfig): typeof window.fetch =>
(url, config) => {
if (typeof url === 'string') {
return api({
- url: `feature/v2/frontend${url.replace(prefix, '')}`,
+ url: `${API_URL}/feature/v2/frontend${url.replace(prefix, '')}`,
headers: config?.headers,
silence: true,
output: 'raw',
@@ -30,6 +31,7 @@ interface Props {
}

const UnleashFlagProvider = ({ children }: Props) => {
+ const config = useConfig();
const api = useApi();
const unleashConfig: IConfig = {
url,
@@ -37,7 +39,7 @@ const UnleashFlagProvider = ({ children }: Props) => {
appName: '-', // set by the server
refreshInterval: 600, // refreshInterval in seconds, 10 mins
disableMetrics: true,
- fetch: customFetch(api),
+ fetch: customFetch(api, config),
};

return <FlagProvider config={unleashConfig}>{children}</FlagProvider>;

diff --git a/packages/pack/scripts/validate.sh b/packages/pack/scripts/validate.sh
index 1a2ea64..bae388c 100755
--- a/packages/pack/scripts/validate.sh
+++ b/packages/pack/scripts/validate.sh
@@ -58,7 +58,7 @@ function main {
fi;

if [ "$hasSourceMap" -eq 0 ]; then
- hasError=true;
+ #hasError=true;
echo "[error] no SourceMaps found inside the directory: $OUTPUT_DIR";
fi;

diff --git a/packages/pack/bin/protonPack.js b/packages/pack/bin/protonPack.js
index 55715b89d..c87879ad4 100755
--- a/packages/pack/bin/protonPack.js
+++ b/packages/pack/bin/protonPack.js
@@ -81,7 +81,7 @@ addGlobalOptions(program.command('build').description('create an optimized produ
const outputPath = path.resolve('./dist');
await commandWithLog(`rm -rf ${outputPath}`);
await commandWithLog(
- `${require.resolve('webpack-cli/bin/cli.js')} --progress --output-path=${outputPath} ${webpackArgs}`,
+ `${require.resolve('webpack-cli/bin/cli.js')} --output-path=${outputPath} ${webpackArgs}`,
{
stdio: 'inherit',
}

diff --git a/packages/shared/lib/helpers/browser.ts b/packages/shared/lib/helpers/browser.ts
index 9aaa78a28..f3d24b47c 100644
--- a/packages/shared/lib/helpers/browser.ts
+++ b/packages/shared/lib/helpers/browser.ts
@@ -1,6 +1,21 @@
import UAParser from 'ua-parser-js';

const uaParser = new UAParser();
+{
+ const platform = String(navigator.platform);
+ const userAgents = {
+ linux: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
+ windows: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
+ macos: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
+ } as const;
+ uaParser.setUA(
+ platform.startsWith("Linux")
+ ? userAgents.linux
+ : platform.startsWith("Win")
+ ? userAgents.windows
+ : userAgents.macos
+ );
+}
const ua = uaParser.getResult();

export const hasModulesSupport = () => {
@@ -89,20 +104,10 @@ export const requireDirectAction = () => isSafari() || isFirefox() || isEdge();
* @links { https://mathiasbynens.github.io/rel-noopener/}
*/
export const openNewTab = (url: string) => {
- if (isIE11()) {
- const otherWindow = window.open();
- if (!otherWindow) {
- return;
- }
- otherWindow.opener = null;
- otherWindow.location.href = url;
- return;
- }
- const anchor = document.createElement('a');
-
- anchor.setAttribute('rel', 'noreferrer nofollow noopener');
- anchor.setAttribute('target', '_blank');
- anchor.href = url;
-
- return anchor.click();
+ window.dispatchEvent(
+ new CustomEvent(
+ "electron-mail:packages/shared/lib/helpers/browser.ts:openNewTab",
+ {detail: {url}},
+ ),
+ );
};

diff --git a/packages/components/components/link/SettingsLink.tsx b/packages/components/components/link/SettingsLink.tsx
index 5081c4003..cde37c0cb 100644
--- a/packages/components/components/link/SettingsLink.tsx
+++ b/packages/components/components/link/SettingsLink.tsx
@@ -48,7 +48,7 @@ const SettingsLink = ({ path, app, children, ...rest }: Props, ref: Ref<HTMLAnch
ref={ref}
toApp={APPS.PROTONACCOUNT}
// If going to settings for the same app
- target={canOpenInSameTab(APP_NAME, settingsApp, toSettingsForApp) ? '_self' : '_blank'}
+ target={canOpenInSameTab(APP_NAME, settingsApp, toSettingsForApp) || app === APPS.PROTONVPN_SETTINGS ? '_self' : '_blank'}
{...rest}
>
{children}

diff --git a/packages/components/helpers/earlyAccessDesynchronization.ts b/packages/components/helpers/earlyAccessDesynchronization.ts
index 36bd0c712..c2fb3681c 100644
--- a/packages/components/helpers/earlyAccessDesynchronization.ts
+++ b/packages/components/helpers/earlyAccessDesynchronization.ts
@@ -42,6 +42,7 @@ export const handleEarlyAccessDesynchronization = ({
earlyAccessScope: Feature<Environment> | undefined;
appName: APP_NAMES;
}) => {
+ return;
if (doesNotSupportEarlyAccessVersion()) {
return;
}

diff --git a/applications/mail/src/app/components/list/banners/auto-delete/variations/AutoDeleteFreeBanner.tsx b/applications/mail/src/app/components/list/banners/auto-delete/variations/AutoDeleteFreeBanner.tsx
index 24c56ef6fe..a6046b391c 100644
--- a/applications/mail/src/app/components/list/banners/auto-delete/variations/AutoDeleteFreeBanner.tsx
+++ b/applications/mail/src/app/components/list/banners/auto-delete/variations/AutoDeleteFreeBanner.tsx
@@ -7,6 +7,10 @@ import { AutoDeleteUpsellModal, useModalState } from '@proton/components/compone
import { PromotionBanner } from '@proton/components/containers';

const AutoDeleteFreeBanner = () => {
+ if (___ELECTRON_MAIL_PROTON_SUPPRESS_UPSELL_ADS_PLACEHOLDER___) {
+ return null;
+ }
+
const [upsellModalProps, toggleUpsellModal, renderUpsellModal] = useModalState();

return (

diff --git a/applications/mail/src/app/hooks/useShowUpsellBanner.ts b/applications/mail/src/app/hooks/useShowUpsellBanner.ts
index b82b7ae976..0907c85ec6 100644
--- a/applications/mail/src/app/hooks/useShowUpsellBanner.ts
+++ b/applications/mail/src/app/hooks/useShowUpsellBanner.ts
@@ -33,12 +33,14 @@ const useShowUpsellBanner = (labelID: string) => {
- No other banner is shown in the message list
- If a value is found in the localStorage that should trigger a new display
*/
+ /* <electron-mail-mark> */
const canDisplayUpsellBanner =
user.isFree &&
Date.now() > threeDaysAfterCreationDate &&
isInbox &&
needToShowUpsellBanner.current &&
showAgain;
+ /* </electron-mail-mark> */

const handleDismissBanner = () => {
// Set the ref to false so that we hide the banner and update the localStorage value
@@ -71,6 +73,10 @@ const useShowUpsellBanner = (labelID: string) => {
}
}, []);

+ if (___ELECTRON_MAIL_PROTON_SUPPRESS_UPSELL_ADS_PLACEHOLDER___) {
+ return { canDisplayUpsellBanner: false, needToShowUpsellBanner, handleDismissBanner };
+ }
+
return { canDisplayUpsellBanner, needToShowUpsellBanner, handleDismissBanner };
};

diff --git a/packages/components/containers/heading/PrivateHeader.tsx b/packages/components/containers/heading/PrivateHeader.tsx
index a7d2452313..73ad8a6828 100644
--- a/packages/components/containers/heading/PrivateHeader.tsx
+++ b/packages/components/containers/heading/PrivateHeader.tsx
@@ -49,7 +49,10 @@ const PrivateHeader = ({

<TopNavbar>
<TopNavbarList>
- {upsellButton !== undefined ? upsellButton : !hideUpsellButton && <TopNavbarUpsell app={app} />}
+ {___ELECTRON_MAIL_PROTON_SUPPRESS_UPSELL_ADS_PLACEHOLDER___
+ ? null
+ : (upsellButton !== undefined ? upsellButton : !hideUpsellButton && <TopNavbarUpsell app={app} />)
+ }
{feedbackButton ? <TopNavbarListItem noShrink>{feedbackButton}</TopNavbarListItem> : null}
{settingsButton ? (
<TopNavbarListItem noShrink className="no-mobile">

diff --git a/packages/components/containers/api/ApiProvider.js b/packages/components/containers/api/ApiProvider.js
index 3d1b81941c..6ac2f748fa 100644
--- a/packages/components/containers/api/ApiProvider.js
+++ b/packages/components/containers/api/ApiProvider.js
@@ -120,7 +120,9 @@ const ApiProvider = ({ config, onLogout, children, UID, noErrorState }) => {
error.cancel = true;
reject(error);
}}
- />
+ />,
+ // trying to force single instance, see https://github.com/vladimiry/ElectronMail/issues/621#issuecomment-1627389416
+ "HumanVerificationModal_ID",
);
});
};
12 changes: 6 additions & 6 deletions patches/protonmail/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"proton-mail": [
"common-5.patch",
"drop-circular-dependency-2.patch",
"url-5.patch",
"url-6.patch",
"constants-10.patch",
"sentry-15.patch",
"sentry-16.patch",
"pack-api-arg-5.patch",
"pack-webpack-8.patch",
"session-storage-5.patch",
Expand All @@ -13,7 +13,7 @@
"proton-mail.patch"
],
"proton-account": [
"common-6.patch",
"common-7.patch",
"drop-circular-dependency-2.patch",
"url-6.patch",
"constants-10.patch",
Expand All @@ -28,9 +28,9 @@
"proton-calendar": [
"common-5.patch",
"drop-circular-dependency-2.patch",
"url-5.patch",
"url-6.patch",
"constants-10.patch",
"sentry-15.patch",
"sentry-16.patch",
"pack-api-arg-5.patch",
"pack-webpack-8.patch",
"session-storage-5.patch",
Expand All @@ -52,7 +52,7 @@
"proton-drive.patch"
],
"proton-vpn-settings": [
"common-6.patch",
"common-7.patch",
"drop-circular-dependency-2.patch",
"url-6.patch",
"constants-10.patch",
Expand Down
Loading

0 comments on commit c4f835f

Please sign in to comment.