mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
sync on reconnect
This commit is contained in:
@@ -2,7 +2,7 @@ import { EnvironmentService } from './environment.service';
|
|||||||
|
|
||||||
export abstract class NotificationsService {
|
export abstract class NotificationsService {
|
||||||
init: (environmentService: EnvironmentService) => Promise<void>;
|
init: (environmentService: EnvironmentService) => Promise<void>;
|
||||||
updateConnection: () => Promise<void>;
|
updateConnection: (sync?: boolean) => Promise<void>;
|
||||||
reconnectFromActivity: () => Promise<void>;
|
reconnectFromActivity: () => Promise<void>;
|
||||||
disconnectFromInactivity: () => Promise<void>;
|
disconnectFromInactivity: () => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,18 +55,18 @@ export class NotificationsService implements NotificationsServiceAbstraction {
|
|||||||
(data: any) => this.processNotification(new NotificationResponse(data)));
|
(data: any) => this.processNotification(new NotificationResponse(data)));
|
||||||
this.signalrConnection.onclose(() => {
|
this.signalrConnection.onclose(() => {
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
this.reconnect();
|
this.reconnect(true);
|
||||||
});
|
});
|
||||||
this.inited = true;
|
this.inited = true;
|
||||||
if (await this.isAuthedAndUnlocked()) {
|
if (await this.isAuthedAndUnlocked()) {
|
||||||
await this.connect();
|
await this.reconnect(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateConnection(): Promise<void> {
|
async updateConnection(sync = false): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (await this.isAuthedAndUnlocked()) {
|
if (await this.isAuthedAndUnlocked()) {
|
||||||
await this.connect();
|
await this.reconnect(sync);
|
||||||
} else {
|
} else {
|
||||||
await this.signalrConnection.stop();
|
await this.signalrConnection.stop();
|
||||||
}
|
}
|
||||||
@@ -77,16 +77,19 @@ export class NotificationsService implements NotificationsServiceAbstraction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async reconnectFromActivity(): Promise<void> {
|
async reconnectFromActivity(): Promise<void> {
|
||||||
|
if (!this.inited) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.inactive = false;
|
this.inactive = false;
|
||||||
if (!this.connected) {
|
if (!this.connected) {
|
||||||
if (await this.isAuthedAndUnlocked()) {
|
await this.reconnect(true);
|
||||||
await this.reconnect();
|
|
||||||
await this.syncService.fullSync(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async disconnectFromInactivity(): Promise<void> {
|
async disconnectFromInactivity(): Promise<void> {
|
||||||
|
if (!this.inited) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.inactive = true;
|
this.inactive = true;
|
||||||
if (this.connected) {
|
if (this.connected) {
|
||||||
await this.signalrConnection.stop();
|
await this.signalrConnection.stop();
|
||||||
@@ -133,12 +136,7 @@ export class NotificationsService implements NotificationsServiceAbstraction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async connect() {
|
private async reconnect(sync: boolean) {
|
||||||
await this.signalrConnection.start();
|
|
||||||
this.connected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async reconnect() {
|
|
||||||
if (this.reconnectTimer != null) {
|
if (this.reconnectTimer != null) {
|
||||||
clearTimeout(this.reconnectTimer);
|
clearTimeout(this.reconnectTimer);
|
||||||
this.reconnectTimer = null;
|
this.reconnectTimer = null;
|
||||||
@@ -152,11 +150,15 @@ export class NotificationsService implements NotificationsServiceAbstraction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.connect();
|
await this.signalrConnection.start();
|
||||||
|
this.connected = true;
|
||||||
|
if (sync) {
|
||||||
|
await this.syncService.fullSync(false);
|
||||||
|
}
|
||||||
} catch { }
|
} catch { }
|
||||||
|
|
||||||
if (!this.connected) {
|
if (!this.connected) {
|
||||||
this.reconnectTimer = setTimeout(() => this.reconnect(), 120000);
|
this.reconnectTimer = setTimeout(() => this.reconnect(sync), 120000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user