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 6, 2024
1 parent f436b7e commit bf6bc61
Show file tree
Hide file tree
Showing 81 changed files with 931 additions and 916 deletions.
2 changes: 1 addition & 1 deletion import-sorter.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"quoteMark": "double",
"groupRules": [
{},
"^(scripts/|src/|webpack-configs/|webpack-configs/|\\./|\\.\\./)"
"^(scripts/|src/|webpack-configs/|\\./|\\.\\./)"
],
"wrappingStyle": {
"maxBindingNamesPerLine": 0,
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
31 changes: 27 additions & 4 deletions patches/protonmail/session-storage-8.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions scripts/prepare-webclient/webclients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
4 changes: 4 additions & 0 deletions src/electron-main/api/endpoints-builders/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export async function buildEndpoints(
proxy,
loginDelayUntilSelected,
loginDelaySecondsRange,
entryProtonApp,
},
) {
assertEntryUrl(entryUrl);
Expand All @@ -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();
Expand Down Expand Up @@ -114,6 +116,7 @@ export async function buildEndpoints(
proxy,
loginDelayUntilSelected,
loginDelaySecondsRange,
entryProtonApp,
},
) {
assertEntryUrl(entryUrl);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/electron-main/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
8 changes: 8 additions & 0 deletions src/electron-main/storage-upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down
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,
}),
Expand Down
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.

70 changes: 0 additions & 70 deletions src/electron-preload/webview/calendar/provider-api/internals.ts

This file was deleted.

24 changes: 0 additions & 24 deletions src/electron-preload/webview/calendar/provider-api/model.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/electron-preload/webview/calendar/tsconfig.json

This file was deleted.

3 changes: 1 addition & 2 deletions src/electron-preload/webview/lib/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import {buildLoggerBundle} from "src/electron-preload/lib/util";
import {Logger} from "src/shared/model/common";
import {PACKAGE_NAME} from "src/shared/const";

export const WEBVIEW_LOGGERS: Readonly<Record<"primary" | "calendar", Logger>> = {
export const WEBVIEW_LOGGERS: Readonly<Record<"primary", Logger>> = {
primary: buildLoggerBundle(`${__filename} [preload: webview/primary]`),
calendar: buildLoggerBundle(`${__filename} [preload: webview/calendar]`),
};

export const RATE_LIMITED_METHOD_CALL_MESSAGE = `${PACKAGE_NAME}_RATE_LIMITED_METHOD_CALL_MESSAGE`;
Expand Down
2 changes: 1 addition & 1 deletion src/electron-preload/webview/lib/database-entity/mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {lzutf8Util} from "src/shared/util/entity";
import {MessagesResponse} from "src/electron-preload/webview/lib/rest-model";
import {MIME_TYPES} from "src/shared/model/database";
import {ONE_SECOND_MS, PACKAGE_VERSION} from "src/shared/const";
import {ProviderApi} from "src/electron-preload/webview/primary/provider-api/model";
import {ProviderApi} from "src/electron-preload/webview/primary/mail/provider-api/model";
import * as RestModel from "src/electron-preload/webview/lib/rest-model";

const logger = buildLoggerBundle(__filename);
Expand Down
Loading

0 comments on commit bf6bc61

Please sign in to comment.