Skip to content

Commit

Permalink
enable "proton-vpn-settings" web client bundling, closes #470
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimiry committed Jan 4, 2022
1 parent a9431cf commit 5a0c606
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 15 deletions.
14 changes: 14 additions & 0 deletions patches/protonmail/common.patch
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,17 @@ index 2bd472b..52cf521 100644
name: 'ProtonCalendar',
bareName: 'Calendar',
clientID: 'WebCalendar',

diff --git a/packages/components/components/link/SettingsLink.tsx b/packages/components/components/link/SettingsLink.tsx
index ebce00d20..96498d8c8 100644
--- a/packages/components/components/link/SettingsLink.tsx
+++ b/packages/components/components/link/SettingsLink.tsx
@@ -37,7 +37,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={isGoingToSameSettings ? '_self' : '_blank'}
+ target={isGoingToSameSettings || app === APPS.PROTONVPN_SETTINGS ? '_self' : '_blank'}
{...rest}
>
{children}
7 changes: 7 additions & 0 deletions patches/protonmail/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,12 @@
"pack-api-arg.patch",
"session-storage-2.patch",
"proton-mail.patch"
],
"proton-vpn-settings": [
"common.patch",
"sentry-3.patch",
"captcha-2.patch",
"pack-api-arg.patch",
"session-storage-2.patch"
]
}
6 changes: 3 additions & 3 deletions scripts/prepare-webclient/webclients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ async function executeBuildFlow(
await state.buildingSetup();

const {configApiParam} = await configure({cwd: appDir, repoType}, folderAsDomainEntry);
const publicPath: string | undefined = repoType !== "proton-mail"
? `/${PROVIDER_REPO_MAP[repoType].baseDirName}/`
const publicPath: string | undefined = PROVIDER_REPO_MAP[repoType].basePath
? `/${PROVIDER_REPO_MAP[repoType].basePath}/`
: undefined;

if (repoType === "proton-mail" || repoType === "proton-calendar") {
Expand Down Expand Up @@ -404,7 +404,7 @@ export const buildProtonClients = async ({destDir}: { destDir: string }): Promis
await executeBuildFlow({
repoType,
destDir,
destSubFolder: PROVIDER_REPO_MAP[repoType].baseDirName,
destSubFolder: PROVIDER_REPO_MAP[repoType].basePath,
});
}
};
8 changes: 4 additions & 4 deletions src/electron-main/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const fsAsync = {
readFile: promisify(fs.readFile),
} as const;

const baseDirNames: readonly string[] = Object
const basePaths: readonly string[] = Object
.values(PROVIDER_REPO_MAP)
.map(({baseDirName}) => baseDirName);
.map(({basePath}) => basePath);

export function registerStandardSchemes(ctx: Context): void {
// WARN: "protocol.registerStandardSchemes" needs to be called once, see https://github.com/electron/electron/issues/15943
Expand Down Expand Up @@ -75,7 +75,7 @@ async function resolveFileSystemResourceLocation(
.relative(directory, urlBasedResource)
.split(path.sep)
.shift();
return leadingFolder && baseDirNames.includes(leadingFolder)
return leadingFolder && basePaths.includes(leadingFolder)
? path.join(directory, leadingFolder)
: directory;
})();
Expand Down Expand Up @@ -129,7 +129,7 @@ export async function registerSessionProtocols(ctx: DeepReadonly<Context>, sessi
// TODO tweak e2e test: navigate to "/drive" (requires to be signed-in into the mail account)
// so the scope misconfiguration-related error get printed to "log.log" file and the test gets failed then
if (resourceLocation.startsWith(
path.join(directory, PROVIDER_REPO_MAP["proton-drive"].baseDirName, "downloadSW."),
path.join(directory, PROVIDER_REPO_MAP["proton-drive"].basePath, "downloadSW."),
)) {
/* eslint-disable max-len */
// https://github.com/ProtonMail/proton-drive/blob/04d30ae6c9fbfbc33cfc91499831e2e6458a99b1/src/.htaccess#L42-L45
Expand Down
15 changes: 11 additions & 4 deletions src/shared/proton-apps-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const PROVIDER_APP_NAMES = [
"proton-account",
"proton-calendar",
"proton-drive",
"proton-vpn-settings",
] as const;

export const PROVIDER_REPO_STANDARD_SETUP_WEBPACK_INDEX_ENTRY_ITEMS = [
Expand All @@ -19,7 +20,7 @@ export const PROVIDER_REPO_STANDARD_SETUP_WEBPACK_INDEX_ENTRY_ITEMS = [
export const PROVIDER_REPO_MAP = {
[PROVIDER_APP_NAMES[0]]: {
repoRelativeDistDir: "./dist",
baseDirName: "",
basePath: "",
tag: "proton-mail@4.13.6",
protonPack: {
appConfig: {clientId: "WebMail"},
Expand All @@ -46,13 +47,13 @@ export const PROVIDER_REPO_MAP = {
},
[PROVIDER_APP_NAMES[1]]: {
repoRelativeDistDir: "./dist",
baseDirName: "account",
basePath: "account",
tag: "proton-account@4.16.1",
protonPack: {appConfig: {clientId: "WebAccount"}}
},
[PROVIDER_APP_NAMES[2]]: {
repoRelativeDistDir: "./dist",
baseDirName: "calendar",
basePath: "calendar",
tag: "proton-calendar@4.9.2",
protonPack: {
appConfig: {clientId: "WebCalendar"},
Expand All @@ -65,10 +66,16 @@ export const PROVIDER_REPO_MAP = {
},
[PROVIDER_APP_NAMES[3]]: {
repoRelativeDistDir: "./dist",
baseDirName: "drive",
basePath: "drive",
tag: "proton-drive@4.8.0",
protonPack: {appConfig: {clientId: "WebDrive"}},
},
[PROVIDER_APP_NAMES[4]]: {
repoRelativeDistDir: "./dist",
basePath: "account/vpn",
tag: "proton-vpn-settings@4.13.0",
protonPack: {appConfig: {clientId: "WebVPNSettings"}},
},
} as const;

export const PROTON_SHARED_MESSAGE_INTERFACE = {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ export const resolvePackagedWebClientApp: (
const result: typeof resolvePackagedWebClientApp = (url) => {
const pathname = `${url.pathname}/`;
const foundSubProject = subProjects.find((subProject) => {
return pathname.startsWith(`/${PROVIDER_REPO_MAP[subProject].baseDirName}/`);
return pathname.startsWith(`/${PROVIDER_REPO_MAP[subProject].basePath}/`);
});
const project = foundSubProject || "proton-mail";
const [
Expand Down
6 changes: 3 additions & 3 deletions src/web/browser-window/app/_core/core.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export class CoreService {
if (!bundle) {
throw new Error(`Invalid "entryUrl" value: "${JSON.stringify(bundle)}"`);
}
const {baseDirName} = PROVIDER_REPO_MAP[repoType];
const entryUrl = `${bundle.entryUrl}${baseDirName ? "/" + baseDirName : ""}`;
const {basePath} = PROVIDER_REPO_MAP[repoType];
const entryUrl = `${bundle.entryUrl}${basePath ? "/" + basePath : ""}`;

return {
entryUrl,
Expand Down Expand Up @@ -122,7 +122,7 @@ export class CoreService {
};
const finalCodePart = `(() => {
window.sessionStorage.setItem(${JSON.stringify(WEB_VIEW_SESSION_STORAGE_KEY_SKIP_LOGIN_DELAYS)}, 1);
window.location.assign("./${PROVIDER_REPO_MAP[repoType].baseDirName}")
window.location.assign("./${PROVIDER_REPO_MAP[repoType].basePath}")
})()`;
const prependCodeParts: string[] = [];
if (savedSessionData?.clientSession) {
Expand Down

0 comments on commit 5a0c606

Please sign in to comment.