Skip to content

Commit

Permalink
allow selecting mail/calendar/drive entry web app, #502
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimiry committed Dec 8, 2024
1 parent f436b7e commit 9a1465c
Showing 82 changed files with 972 additions and 931 deletions.
2 changes: 1 addition & 1 deletion import-sorter.json
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
"quoteMark": "double",
"groupRules": [
{},
"^(scripts/|src/|webpack-configs/|webpack-configs/|\\./|\\.\\./)"
"^(scripts/|src/|webpack-configs/|\\./|\\.\\./)"
],
"wrappingStyle": {
"maxBindingNamesPerLine": 0,
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "electron-mail",
"description": "Unofficial ProtonMail Desktop App",
"version": "5.2.4",
"version": "5.3.0",
"author": "Vladimir Yakovlev <desktop-app@protonmail.ch>",
"license": "GPL-3.0",
"homepage": "https://github.com/vladimiry/ElectronMail",
@@ -32,16 +32,14 @@
"build:electron-main:dev": "cross-env NODE_ENV=development npm-run-all build:electron-main",
"build:electron-main:watch": "cross-env WEBPACK_ENV_WATCH=1 npm-run-all build:electron-main",
"build:electron-main:watch:dev": "cross-env WEBPACK_ENV_WATCH=1 npm-run-all build:electron-main:dev",
"build:electron-preload": "npm-run-all build:electron-preload:about build:electron-preload:browser-window build:electron-preload:database-indexer build:electron-preload:search-in-page-browser-view build:electron-preload:webview-primary build:electron-preload:webview-calendar",
"build:electron-preload": "npm-run-all build:electron-preload:about build:electron-preload:browser-window build:electron-preload:database-indexer build:electron-preload:search-in-page-browser-view build:electron-preload:webview-primary",
"build:electron-preload:dev": "cross-env NODE_ENV=development npm-run-all build:electron-preload",
"build:electron-preload:about": "pnpm run webpack:shortcut -- --config ./webpack-configs/preload/about.ts",
"build:electron-preload:browser-window": "pnpm run webpack:shortcut -- --config ./webpack-configs/preload/browser-window.ts",
"build:electron-preload:database-indexer": "pnpm run webpack:shortcut -- --config ./webpack-configs/preload/database-indexer.ts",
"build:electron-preload:search-in-page-browser-view": "pnpm run webpack:shortcut -- --config ./webpack-configs/preload/search-in-page-browser-view.ts",
"build:electron-preload:webview-primary": "pnpm run webpack:shortcut -- --config ./webpack-configs/preload/webview-primary.ts",
"build:electron-preload:webview-primary:dev": "cross-env NODE_ENV=development npm-run-all build:electron-preload:webview-primary",
"build:electron-preload:webview-calendar": "pnpm run webpack:shortcut -- --config ./webpack-configs/preload/webview-calendar.ts",
"build:electron-preload:webview-calendar:dev": "cross-env NODE_ENV=development npm-run-all build:electron-preload:webview-calendar",
"build:web": "npm-run-all build:web:browser-window build:web:about build:web:search",
"build:web:dev": "cross-env NODE_ENV=development npm-run-all build:web",
"build:web:about": "pnpm run webpack:shortcut -- --config ./webpack-configs/web/about.ts",
@@ -79,7 +77,7 @@
"lint:ts:eslint": "pnpm run lint:ts:base:eslint \"./src/**/*.ts\" \"./scripts/**/*.ts\" \"./webpack-configs/**/*.ts\"",
"start:electron": "electron ./app/electron-main/index.cjs",
"start:electron:dev": "electron --inspect-brk- ./app-dev/electron-main/index.cjs",
"test:e2e:build-code": "cross-env NODE_ENV=e2e npm-run-all build:electron-main build:electron-preload:browser-window build:electron-preload:webview-primary build:electron-preload:webview-calendar",
"test:e2e:build-code": "cross-env NODE_ENV=e2e npm-run-all build:electron-main build:electron-preload:browser-window build:electron-preload:webview-primary",
"test:e2e:run": "cross-env DEBUG=pw:api node ./node_modules/@playwright/test/cli.js test --timeout 1200000",
"test:e2e": "npm-run-all test:e2e:build-code test:e2e:run",
"scripts/prepare-native-deps": "pnpm run ts-node:shortcut ./scripts/prepare-native-deps.ts",
31 changes: 27 additions & 4 deletions patches/protonmail/session-storage-8.patch
Original file line number Diff line number Diff line change
@@ -121,21 +121,44 @@ index f24616faf9..6c05699766 100644
+/* </electron-mail-mark> */

diff --git a/packages/shared/lib/authentication/createAuthenticationStore.ts b/packages/shared/lib/authentication/createAuthenticationStore.ts
index b5cbba6cf7..21c710ab33 100644
index aab52552ad..149992dfa7 100644
--- a/packages/shared/lib/authentication/createAuthenticationStore.ts
+++ b/packages/shared/lib/authentication/createAuthenticationStore.ts
@@ -48,8 +48,8 @@ const defaultAuthData = {
@@ -6,6 +6,7 @@ import { stripLeadingAndTrailingSlash } from '../helpers/string';
import { appMode } from '../webpack.constants';
import { getBasename, getLocalIDFromPathname, stripLocalBasenameFromPathname } from './pathnameHelper';
import { getPersistedSession } from './persistedSessionStorage';
+import { APPS_CONFIGURATION } from '@proton/shared/lib/constants';

const MAILBOX_PASSWORD_KEY = 'proton:mailbox_pwd';
const UID_KEY = 'proton:oauth:UID';
@@ -51,8 +52,8 @@ const defaultAuthData = {
basename: undefined,
};

-const getInitialState = (mode: 'sso' | 'standalone', oldUID?: string, oldLocalID?: number): AuthData => {
- if (mode === 'standalone') {
+const getInitialState = (mode: 'sso' | 'standalone' | 'bundle', oldUID?: string, oldLocalID?: number): AuthData => {
+ if (mode === 'bundle') {
return {
UID: oldUID,
localID: undefined,
@@ -215,7 +215,7 @@ const createAuthenticationStore = ({ mode = appMode, initialAuth, store: { set,
@@ -175,6 +176,14 @@ const createAuthenticationStore = ({ mode = appMode, initialAuth, store: { set,
basename = undefined;
}

+ {
+ const protonApp = window.sessionStorage.getItem("electron_mail:proton_app_name");
+ if (protonApp && protonApp in APPS_CONFIGURATION) {
+ const {publicPath} = APPS_CONFIGURATION[protonApp as keyof typeof APPS_CONFIGURATION];
+ return publicPath || "/";
+ }
+ }
+
return getPath(basename, window.location.href, path);
};

@@ -218,7 +227,7 @@ const createAuthenticationStore = ({ mode = appMode, initialAuth, store: { set,
return basename;
},
get ready(): boolean {
5 changes: 2 additions & 3 deletions scripts/prepare-webclient/webclients.ts
Original file line number Diff line number Diff line change
@@ -263,10 +263,9 @@ async function executeBuildFlow(
: undefined;

{
const webpackIndexEntryItems = repoType === "proton-mail" || repoType === "proton-calendar"
const webpackIndexEntryItems = "webpackIndexEntryItems" in PROVIDER_REPO_MAP[repoType].protonPack
? PROVIDER_REPO_MAP[repoType].protonPack.webpackIndexEntryItems
: undefined;

: null;
// https://github.com/ProtonMail/proton-pack/tree/2e44d5fd9d2df39787202fc08a90757ea47fe480#how-to-configure
writeFile(
path.join(appDir, "./proton.config.js"),
29 changes: 16 additions & 13 deletions src/e2e/lib/workflow.ts
Original file line number Diff line number Diff line change
@@ -7,17 +7,10 @@ import {CONF, ENV, GLOBAL_STATE} from "src/e2e/lib/const";
import {ONE_SECOND_MS} from "src/shared/const";
import {PROTON_API_ENTRY_URLS} from "src/shared/const/proton-url";
import {TestContext} from "./model";
import {WEBVIEW_PRIMARY_INTERNALS_APP_TYPES} from "src/electron-preload/webview/primary/common/provider-api/const";

const {expect} = playwrightTest;

const resolveEntryUrlIndexByValue = (entryUrl: string): number => {
const index = PROTON_API_ENTRY_URLS.findIndex((url) => url === entryUrl);
if (index === -1) {
throw new Error(`Failed to resolve entry url index by "${entryUrl}" value`);
}
return index;
};

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const buildWorkflow = (testContext: TestContext) => {
const workflow = {
@@ -178,7 +171,9 @@ export const buildWorkflow = (testContext: TestContext) => {
}
},

async addAccount(account: {login?: string; password?: string; twoFactorCode?: string; entryUrlValue?: string}): Promise<void> {
async addAccount(
account: {login?: string; password?: string; twoFactorCode?: string; entryUrlValue?: string; entryProtonApp?: string},
): Promise<void> {
const login = account.login
? account.login
: `${ENV.loginPrefix}-${GLOBAL_STATE.loginPrefixCount++}`;
@@ -189,17 +184,25 @@ export const buildWorkflow = (testContext: TestContext) => {
await testContext.firstWindowPage.click("#goToAccountsSettingsLink");

{
const el = await testContext.firstWindowPage.waitForSelector("#accountEditFormEntryUrlField .ng-select-container", {
const valueIndex = account.entryProtonApp
? WEBVIEW_PRIMARY_INTERNALS_APP_TYPES.findIndex((value) => value === account.entryProtonApp)
: 0;
const el = await testContext.firstWindowPage.waitForSelector("#entryProtonAppField .ng-select-container", {
state: "visible",
});
await el.dispatchEvent("mousedown");
await testContext.firstWindowPage.click(`[entry-proton-app-option-index="${valueIndex}"]`);
}

{
const entryUrlIndex = account.entryUrlValue
? resolveEntryUrlIndexByValue(account.entryUrlValue)
const valueIndex = account.entryUrlValue
? PROTON_API_ENTRY_URLS.findIndex((value) => value === account.entryUrlValue)
: 0;
await testContext.firstWindowPage.click(`[entry-url-option-index="${entryUrlIndex}"]`);
const el = await testContext.firstWindowPage.waitForSelector("#accountEditFormEntryUrlField .ng-select-container", {
state: "visible",
});
await el.dispatchEvent("mousedown");
await testContext.firstWindowPage.click(`[entry-url-option-index="${valueIndex}"]`);
}

await testContext.firstWindowPage.fill("[formControlName=login]", login);
4 changes: 4 additions & 0 deletions src/electron-main/api/endpoints-builders/account.ts
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@ export async function buildEndpoints(
proxy,
loginDelayUntilSelected,
loginDelaySecondsRange,
entryProtonApp,
},
) {
assertEntryUrl(entryUrl);
@@ -80,6 +81,7 @@ export async function buildEndpoints(
proxy,
loginDelayUntilSelected,
loginDelaySecondsRange,
entryProtonApp,
};
const result = await ctx.settingsStoreQueue.q(async () => {
const settings = await ctx.settingsStore.readExisting();
@@ -114,6 +116,7 @@ export async function buildEndpoints(
proxy,
loginDelayUntilSelected,
loginDelaySecondsRange,
entryProtonApp,
},
) {
assertEntryUrl(entryUrl);
@@ -151,6 +154,7 @@ export async function buildEndpoints(
account.proxy = proxy;
account.loginDelayUntilSelected = loginDelayUntilSelected;
account.loginDelaySecondsRange = loginDelaySecondsRange;
account.entryProtonApp = entryProtonApp;

if (credentials) {
const {credentials: existingCredentials} = account;
3 changes: 0 additions & 3 deletions src/electron-main/context.ts
Original file line number Diff line number Diff line change
@@ -106,9 +106,6 @@ function initLocations(storeFs: StoreModel.StoreFs, paths?: ContextInitOptionsPa
primary: formatFileUrl(
appRelativePath(`./electron-preload/webview/primary/index${BUILD_ENVIRONMENT === "e2e" ? "-e2e" : ""}.js`),
),
calendar: formatFileUrl(
appRelativePath(`./electron-preload/webview/calendar/index${BUILD_ENVIRONMENT === "e2e" ? "-e2e" : ""}.js`),
),
},
// TODO electron: get rid of "baseURLForDataURL" workaround, see https://github.com/electron/electron/issues/20700
vendorsAppCssLinkHrefs: ["shared-vendor-dark", "shared-vendor-light"].map((value) =>
8 changes: 8 additions & 0 deletions src/electron-main/storage-upgrade.ts
Original file line number Diff line number Diff line change
@@ -360,6 +360,9 @@ const CONFIG_UPGRADES: Record<string, (config: Config) => void> = {
}
}
},
"5.2.4": (config) => {
delete (config as {calendarNotification?: unknown}).calendarNotification;
},
// last updater
"100.0.0": (config) => {
// ensuring default base props are set
@@ -514,6 +517,11 @@ export const upgradeSettings: upgradeSettingsType = ((): upgradeSettingsType =>
}
}
},
"5.2.4": (settings) => {
for (const account of settings.accounts) {
if (!account.entryProtonApp) account.entryProtonApp = "proton-mail";
}
},
// last updater
"100.0.0": (settings): void => {
settings.accounts.forEach((account, index) => {
8 changes: 4 additions & 4 deletions src/electron-preload/lib/electron-exposure/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {ElectronWindow} from "src/shared/model/electron";
import {IPC_MAIN_API} from "src/shared/api/main-process";
import {LOGGER} from "src/electron-preload/lib/electron-exposure/logger";
import {PROTON_CALENDAR_IPC_WEBVIEW_API} from "src/shared/api/webview/calendar";
import {PROTON_PRIMARY_IPC_WEBVIEW_API} from "src/shared/api/webview/primary";
import {PROTON_PRIMARY_COMMON_IPC_WEBVIEW_API} from "src/shared/api/webview/primary-common";
import {PROTON_PRIMARY_LOGIN_IPC_WEBVIEW_API} from "src/shared/api/webview/primary-login";
import {PROTON_PRIMARY_MAIL_IPC_WEBVIEW_API} from "src/shared/api/webview/primary-mail";
import {registerDocumentClickEventListener} from "src/electron-preload/lib/events-handling";

export const ELECTRON_WINDOW: Readonly<ElectronWindow> = Object.freeze({
__ELECTRON_EXPOSURE__: Object.freeze({
buildIpcMainClient: IPC_MAIN_API.client.bind(IPC_MAIN_API),
buildIpcPrimaryWebViewClient: PROTON_PRIMARY_IPC_WEBVIEW_API.client.bind(PROTON_PRIMARY_IPC_WEBVIEW_API),
buildIpcPrimaryCommonWebViewClient: PROTON_PRIMARY_COMMON_IPC_WEBVIEW_API.client.bind(PROTON_PRIMARY_COMMON_IPC_WEBVIEW_API),
buildIpcPrimaryLoginWebViewClient: PROTON_PRIMARY_LOGIN_IPC_WEBVIEW_API.client.bind(PROTON_PRIMARY_LOGIN_IPC_WEBVIEW_API),
buildIpcCalendarWebViewClient: PROTON_CALENDAR_IPC_WEBVIEW_API.client.bind(PROTON_CALENDAR_IPC_WEBVIEW_API),
buildIpcPrimaryMailWebViewClient: PROTON_PRIMARY_MAIL_IPC_WEBVIEW_API.client.bind(PROTON_PRIMARY_MAIL_IPC_WEBVIEW_API),
registerDocumentClickEventListener,
Logger: LOGGER,
}),
3 changes: 2 additions & 1 deletion src/electron-preload/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"include": [
"../../src/@types/**/*"
"../../src/@types/**/*",
"./**/*"
]
}
28 changes: 0 additions & 28 deletions src/electron-preload/webview/calendar/api.ts

This file was deleted.

31 changes: 0 additions & 31 deletions src/electron-preload/webview/calendar/index.ts

This file was deleted.

Loading

0 comments on commit 9a1465c

Please sign in to comment.