Skip to content

Commit

Permalink
additionally save the "proton session" on interval, #227
Browse files Browse the repository at this point in the history
* every 15 minutes by default (interval value is configurable in "config.json")
* this should improve preserving by the app actually alive session
  • Loading branch information
vladimiry committed Nov 12, 2020
1 parent cd1a0c6 commit a4e8ee7
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 19 deletions.
14 changes: 14 additions & 0 deletions src/electron-main/storage-upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,20 @@ const CONFIG_UPGRADES: Record<string, (config: Config) => void> = {
}
}
},
"4.9.3": (config) => {
for (
const key of [
"persistentSessionSavingInterval",
"dbSyncingIntervalTrigger",
"dbSyncingOnlineTriggerDelay",
"dbSyncingFiredTriggerDebounce",
] as const
) {
if (typeof config[key] === "undefined") {
config[key] = INITIAL_STORES.config()[key];
}
}
},
// WARN needs to be the last updater
"100.0.0": (config) => {
// ensuring default base props are set
Expand Down
4 changes: 4 additions & 0 deletions src/shared/model/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export interface Config extends BaseConfig, Partial<StoreModel.StoreEntity> {
localDbMailsListViewMode: "plain" | "conversation"
userAgents: string[]
zoomFactorDisabled: boolean;
persistentSessionSavingInterval: number;
dbSyncingIntervalTrigger: number;
dbSyncingOnlineTriggerDelay: number;
dbSyncingFiredTriggerDebounce: number;
// base
calendarNotification: boolean
checkUpdateAndNotify: boolean
Expand Down
4 changes: 4 additions & 0 deletions src/shared/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export function initialConfig(): Config {
/* eslint-enable max-len */
],
zoomFactorDisabled: false,
persistentSessionSavingInterval: ONE_MINUTE_MS * 15,
dbSyncingIntervalTrigger: ONE_MINUTE_MS * 5,
dbSyncingOnlineTriggerDelay: ONE_SECOND_MS * 3,
dbSyncingFiredTriggerDebounce: ONE_SECOND_MS * 5,
// base
calendarNotification: false,
checkUpdateAndNotify: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ export abstract class AccountViewAbstractComponent extends NgChangesObservableCo
})(),
);

this.subscription.add(
this.filterDomReadyEvent()
.pipe(take(1))
.subscribe(({webView}) => {
if ((BUILD_ENVIRONMENT === "development")) {
webView.openDevTools();
}
}),
);
// this.subscription.add(
// this.filterDomReadyEvent()
// .pipe(take(1))
// .subscribe(({webView}) => {
// if ((BUILD_ENVIRONMENT === "development")) {
// webView.openDevTools();
// }
// }),
// );
}

ngOnDestroy(): void {
Expand Down
20 changes: 14 additions & 6 deletions src/web/browser-window/app/_accounts/account.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,21 @@ export class AccountComponent extends NgChangesObservableComponent implements On
};

this.subscription.add(
combineLatest([
this.loggedIn$,
this.persistentSession$,
]).pipe(
filter(([loggedIn, persistentSession]) => persistentSession && loggedIn),
withLatestFrom(this.account$),
this.store.pipe(
select(OptionsSelectors.CONFIG.persistentSessionSavingInterval),
switchMap((persistentSessionSavingInterval) => {
return combineLatest([
this.loggedIn$,
this.persistentSession$,
timer(0, persistentSessionSavingInterval),
]).pipe(
filter(([loggedIn, persistentSession]) => persistentSession && loggedIn),
withLatestFrom(this.account$),
);
}),
).subscribe(([, {accountConfig}]) => {
this.logger.verbose("saving proton session");

(async () => {
await this.ipcMainClient("saveProtonSession")({
login: accountConfig.login,
Expand Down
15 changes: 11 additions & 4 deletions src/web/browser-window/app/_accounts/accounts.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,15 +420,22 @@ export class AccountsEffects {

// syncing
this.api.primaryWebViewClient(webView, {finishPromise}).pipe(
mergeMap((webViewClient) => {
withLatestFrom(
this.store.pipe(
select(OptionsSelectors.FEATURED.config),
),
),
mergeMap((
[webViewClient, {dbSyncingIntervalTrigger, dbSyncingOnlineTriggerDelay, dbSyncingFiredTriggerDebounce}],
) => {
const syncingIterationTrigger$: Observable<null> = merge(
timer(0, ONE_MINUTE_MS * 5).pipe(
timer(0, dbSyncingIntervalTrigger).pipe(
tap(() => logger.verbose(`triggered by: timer`)),
map(() => null),
),
fromEvent(window, "online").pipe(
tap(() => logger.verbose(`triggered by: "window.online" event`)),
delay(ONE_SECOND_MS * 3),
delay(dbSyncingOnlineTriggerDelay),
map(() => null),
),
FIRE_SYNCING_ITERATION$.pipe(
Expand All @@ -437,7 +444,7 @@ export class AccountsEffects {
// user might be moving emails from here to there while syncing/"buildDbPatch" cycle is in progress
// debounce call reduces 404 fetch errors as we don't trigger fetching until user got settled down
// debouncing the fetching signal we strive to process larger group of events in a single sync iteration
debounceTime(ONE_SECOND_MS * 5),
debounceTime(dbSyncingFiredTriggerDebounce),
),
).pipe(
map(() => null),
Expand Down
1 change: 1 addition & 0 deletions src/web/browser-window/app/store/selectors/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const CONFIG = {
localDbMailsListViewMode: createSelector(FEATURED.config, (config) => config.localDbMailsListViewMode),
doNotRenderNotificationBadgeValue: createSelector(FEATURED.config, (config) => config.doNotRenderNotificationBadgeValue),
zoomFactorDisabled: createSelector(FEATURED.config, (config) => config.zoomFactorDisabled),
persistentSessionSavingInterval: createSelector(FEATURED.config, (config) => config.persistentSessionSavingInterval),
} as const;

export const SETTINGS = (
Expand Down

0 comments on commit a4e8ee7

Please sign in to comment.