mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 22:03:36 +00:00
fix(browser): restore timer based background syncs (#14031)
* docs: fix a typo * fix(browser): restore timer-based background syncs The browser extension was not performing scheduled background syncs every 30 minutes as expected. This was due to missing task scheduling code that was accidentally removed during the web push implementation (PR #11346). This commit: - Creates a new BackgroundSyncService to manage sync scheduling - Properly initializes the sync interval in main.background.ts - Adds a test to ensure the sync initialization code isn't accidentally removed again - Organizes platform module structure to support the new service Fixes PM-19396 * review: remove unecassary await keyword
This commit is contained in:
13
apps/browser/src/background/main.background.spec.ts
Normal file
13
apps/browser/src/background/main.background.spec.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
// This test skips all the initilization of the background script and just
|
||||
// focuses on making sure we don't accidently delete the initilization of
|
||||
// background vault syncing. This has happened before!
|
||||
describe("MainBackground sync task scheduling", () => {
|
||||
it("includes code to schedule the sync interval task", () => {
|
||||
// Get the bootstrap method source code as string
|
||||
const { default: MainBackground } = jest.requireActual("./main.background");
|
||||
const bootstrapSource = MainBackground.prototype.bootstrap.toString();
|
||||
|
||||
// Check that the source includes the critical sync interval scheduling code
|
||||
expect(bootstrapSource).toContain("this.backgroundSyncService.init();");
|
||||
});
|
||||
});
|
||||
@@ -127,7 +127,6 @@ import {
|
||||
WebPushNotificationsApiService,
|
||||
WorkerWebPushConnectionService,
|
||||
} from "@bitwarden/common/platform/notifications/internal";
|
||||
import { ScheduledTaskNames } from "@bitwarden/common/platform/scheduling";
|
||||
import { AppIdService } from "@bitwarden/common/platform/services/app-id.service";
|
||||
import { ConfigApiService } from "@bitwarden/common/platform/services/config/config-api.service";
|
||||
import { DefaultConfigService } from "@bitwarden/common/platform/services/config/default-config.service";
|
||||
@@ -222,6 +221,7 @@ import {
|
||||
KdfConfigService,
|
||||
KeyService as KeyServiceAbstraction,
|
||||
} from "@bitwarden/key-management";
|
||||
import { BackgroundSyncService } from "@bitwarden/platform/background-sync";
|
||||
import {
|
||||
IndividualVaultExportService,
|
||||
IndividualVaultExportServiceAbstraction,
|
||||
@@ -391,6 +391,7 @@ export default class MainBackground {
|
||||
offscreenDocumentService: OffscreenDocumentService;
|
||||
syncServiceListener: SyncServiceListener;
|
||||
browserInitialInstallService: BrowserInitialInstallService;
|
||||
backgroundSyncService: BackgroundSyncService;
|
||||
|
||||
webPushConnectionService: WorkerWebPushConnectionService | UnsupportedWebPushConnectionService;
|
||||
themeStateService: DefaultThemeStateService;
|
||||
@@ -585,9 +586,9 @@ export default class MainBackground {
|
||||
this.logService,
|
||||
this.stateProvider,
|
||||
);
|
||||
this.taskSchedulerService.registerTaskHandler(ScheduledTaskNames.scheduleNextSyncInterval, () =>
|
||||
this.fullSync(),
|
||||
);
|
||||
|
||||
this.backgroundSyncService = new BackgroundSyncService(this.taskSchedulerService);
|
||||
this.backgroundSyncService.register(() => this.fullSync());
|
||||
|
||||
this.environmentService = new BrowserEnvironmentService(
|
||||
this.logService,
|
||||
@@ -1368,6 +1369,7 @@ export default class MainBackground {
|
||||
setTimeout(async () => {
|
||||
await this.refreshBadge();
|
||||
await this.fullSync(false);
|
||||
this.backgroundSyncService.init();
|
||||
this.notificationsService.startListening();
|
||||
resolve();
|
||||
}, 500);
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
"@bitwarden/key-management": ["../../libs/key-management/src"],
|
||||
"@bitwarden/key-management-ui": ["../../libs/key-management-ui/src"],
|
||||
"@bitwarden/platform": ["../../libs/platform/src"],
|
||||
"@bitwarden/platform/*": ["../../libs/platform/src/*"],
|
||||
"@bitwarden/send-ui": ["../../libs/tools/send/send-ui/src"],
|
||||
"@bitwarden/tools-card": ["../../libs/tools/card/src"],
|
||||
"@bitwarden/ui-common": ["../../libs/ui/common/src"],
|
||||
|
||||
Reference in New Issue
Block a user