mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-13 01:58:44 +02:00
[PM-6426] Implementing nextSync timeout using TaskScheduler
This commit is contained in:
parent
66ebdc04c8
commit
b165849cd9
@ -91,6 +91,7 @@ import {
|
|||||||
BiometricStateService,
|
BiometricStateService,
|
||||||
DefaultBiometricStateService,
|
DefaultBiometricStateService,
|
||||||
} from "@bitwarden/common/platform/biometrics/biometric-state.service";
|
} from "@bitwarden/common/platform/biometrics/biometric-state.service";
|
||||||
|
import { ScheduledTaskNames } from "@bitwarden/common/platform/enums/scheduled-task-name.enum";
|
||||||
import { StateFactory } from "@bitwarden/common/platform/factories/state-factory";
|
import { StateFactory } from "@bitwarden/common/platform/factories/state-factory";
|
||||||
import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state";
|
import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state";
|
||||||
import { AppIdService } from "@bitwarden/common/platform/services/app-id.service";
|
import { AppIdService } from "@bitwarden/common/platform/services/app-id.service";
|
||||||
@ -210,6 +211,7 @@ import BrowserLocalStorageService from "../platform/services/browser-local-stora
|
|||||||
import BrowserMessagingPrivateModeBackgroundService from "../platform/services/browser-messaging-private-mode-background.service";
|
import BrowserMessagingPrivateModeBackgroundService from "../platform/services/browser-messaging-private-mode-background.service";
|
||||||
import BrowserMessagingService from "../platform/services/browser-messaging.service";
|
import BrowserMessagingService from "../platform/services/browser-messaging.service";
|
||||||
import { BrowserStateService } from "../platform/services/browser-state.service";
|
import { BrowserStateService } from "../platform/services/browser-state.service";
|
||||||
|
import { BrowserTaskSchedulerService } from "../platform/services/browser-task-scheduler.service";
|
||||||
import I18nService from "../platform/services/i18n.service";
|
import I18nService from "../platform/services/i18n.service";
|
||||||
import { LocalBackedSessionStorageService } from "../platform/services/local-backed-session-storage.service";
|
import { LocalBackedSessionStorageService } from "../platform/services/local-backed-session-storage.service";
|
||||||
import { BackgroundPlatformUtilsService } from "../platform/services/platform-utils/background-platform-utils.service";
|
import { BackgroundPlatformUtilsService } from "../platform/services/platform-utils/background-platform-utils.service";
|
||||||
@ -309,6 +311,7 @@ export default class MainBackground {
|
|||||||
activeUserStateProvider: ActiveUserStateProvider;
|
activeUserStateProvider: ActiveUserStateProvider;
|
||||||
derivedStateProvider: DerivedStateProvider;
|
derivedStateProvider: DerivedStateProvider;
|
||||||
stateProvider: StateProvider;
|
stateProvider: StateProvider;
|
||||||
|
taskSchedulerService: BrowserTaskSchedulerService;
|
||||||
fido2Service: Fido2ServiceAbstraction;
|
fido2Service: Fido2ServiceAbstraction;
|
||||||
individualVaultExportService: IndividualVaultExportServiceAbstraction;
|
individualVaultExportService: IndividualVaultExportServiceAbstraction;
|
||||||
organizationVaultExportService: OrganizationVaultExportServiceAbstraction;
|
organizationVaultExportService: OrganizationVaultExportServiceAbstraction;
|
||||||
@ -426,6 +429,10 @@ export default class MainBackground {
|
|||||||
this.globalStateProvider,
|
this.globalStateProvider,
|
||||||
this.derivedStateProvider,
|
this.derivedStateProvider,
|
||||||
);
|
);
|
||||||
|
this.taskSchedulerService = new BrowserTaskSchedulerService(
|
||||||
|
this.logService,
|
||||||
|
this.stateProvider,
|
||||||
|
);
|
||||||
this.environmentService = new BrowserEnvironmentService(
|
this.environmentService = new BrowserEnvironmentService(
|
||||||
this.logService,
|
this.logService,
|
||||||
this.stateProvider,
|
this.stateProvider,
|
||||||
@ -1274,17 +1281,19 @@ export default class MainBackground {
|
|||||||
|
|
||||||
if (override || lastSyncAgo >= syncInternal) {
|
if (override || lastSyncAgo >= syncInternal) {
|
||||||
await this.syncService.fullSync(override);
|
await this.syncService.fullSync(override);
|
||||||
this.scheduleNextSync();
|
|
||||||
} else {
|
|
||||||
this.scheduleNextSync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.scheduleNextSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private scheduleNextSync() {
|
private async scheduleNextSync() {
|
||||||
if (this.syncTimeout) {
|
await this.taskSchedulerService.clearScheduledTask({
|
||||||
clearTimeout(this.syncTimeout);
|
taskName: ScheduledTaskNames.scheduleNextSyncTimeout,
|
||||||
}
|
});
|
||||||
|
await this.taskSchedulerService.setTimeout(
|
||||||
this.syncTimeout = setTimeout(async () => await this.fullSync(), 5 * 60 * 1000); // check every 5 minutes
|
() => this.fullSync(),
|
||||||
|
5 * 60 * 1000, // check every 5 minutes
|
||||||
|
ScheduledTaskNames.scheduleNextSyncTimeout,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,7 @@
|
|||||||
"clipboardRead",
|
"clipboardRead",
|
||||||
"clipboardWrite",
|
"clipboardWrite",
|
||||||
"idle",
|
"idle",
|
||||||
|
"alarms",
|
||||||
"webRequest",
|
"webRequest",
|
||||||
"webRequestBlocking"
|
"webRequestBlocking"
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user