mirror of
https://github.com/bitwarden/browser
synced 2025-12-21 02:33:46 +00:00
[PM-17658] Fix persist route to clear if service worker dies (#13382)
* Add way to convert TaskSchedulerService to RX Scheduler * Add docs to `toScheduler` * Rollback combined subscription change. * Move to barrel file * Expand `toScheduler` documentation * Add TaskName to Doc Example * Ensure register is called on service worker start
This commit is contained in:
@@ -607,6 +607,7 @@ export default class MainBackground {
|
||||
this.popupViewCacheBackgroundService = new PopupViewCacheBackgroundService(
|
||||
messageListener,
|
||||
this.globalStateProvider,
|
||||
this.taskSchedulerService,
|
||||
);
|
||||
|
||||
const migrationRunner = new MigrationRunner(
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
import { switchMap, merge, delay, filter, concatMap, map, first, of } from "rxjs";
|
||||
|
||||
import { CommandDefinition, MessageListener } from "@bitwarden/common/platform/messaging";
|
||||
import {
|
||||
ScheduledTaskNames,
|
||||
TaskSchedulerService,
|
||||
toScheduler,
|
||||
} from "@bitwarden/common/platform/scheduling";
|
||||
import {
|
||||
POPUP_VIEW_MEMORY,
|
||||
KeyDefinition,
|
||||
@@ -45,7 +50,15 @@ export class PopupViewCacheBackgroundService {
|
||||
constructor(
|
||||
private messageListener: MessageListener,
|
||||
private globalStateProvider: GlobalStateProvider,
|
||||
) {}
|
||||
private readonly taskSchedulerService: TaskSchedulerService,
|
||||
) {
|
||||
this.taskSchedulerService.registerTaskHandler(
|
||||
ScheduledTaskNames.clearPopupViewCache,
|
||||
async () => {
|
||||
await this.clearState();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
startObservingTabChanges() {
|
||||
this.messageListener
|
||||
@@ -87,7 +100,14 @@ export class PopupViewCacheBackgroundService {
|
||||
// on popup closed, with 2 minute delay that is cancelled by re-opening the popup
|
||||
fromChromeEvent(chrome.runtime.onConnect).pipe(
|
||||
filter(([port]) => port.name === popupClosedPortName),
|
||||
switchMap(([port]) => fromChromeEvent(port.onDisconnect).pipe(delay(1000 * 60 * 2))),
|
||||
switchMap(([port]) =>
|
||||
fromChromeEvent(port.onDisconnect).pipe(
|
||||
delay(
|
||||
1000 * 60 * 2,
|
||||
toScheduler(this.taskSchedulerService, ScheduledTaskNames.clearPopupViewCache),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
.pipe(switchMap(() => this.clearState()))
|
||||
|
||||
Reference in New Issue
Block a user