mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-27 12:36:14 +01:00
automatic sync intervals
This commit is contained in:
parent
ac647f3184
commit
3b3750734b
@ -36,8 +36,11 @@ import { CollectionView } from 'jslib/models/view/collectionView';
|
|||||||
import { FolderView } from 'jslib/models/view/folderView';
|
import { FolderView } from 'jslib/models/view/folderView';
|
||||||
|
|
||||||
import { I18nService } from 'jslib/abstractions/i18n.service';
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||||
|
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
||||||
import { SyncService } from 'jslib/abstractions/sync.service';
|
import { SyncService } from 'jslib/abstractions/sync.service';
|
||||||
|
|
||||||
|
const SyncInterval = 6 * 60 * 60 * 1000; // 6 hours
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-vault',
|
selector: 'app-vault',
|
||||||
template: template,
|
template: template,
|
||||||
@ -64,7 +67,7 @@ export class VaultComponent implements OnInit {
|
|||||||
private componentFactoryResolver: ComponentFactoryResolver, private i18nService: I18nService,
|
private componentFactoryResolver: ComponentFactoryResolver, private i18nService: I18nService,
|
||||||
private broadcasterService: BroadcasterService, private changeDetectorRef: ChangeDetectorRef,
|
private broadcasterService: BroadcasterService, private changeDetectorRef: ChangeDetectorRef,
|
||||||
private ngZone: NgZone, private syncService: SyncService, private analytics: Angulartics2,
|
private ngZone: NgZone, private syncService: SyncService, private analytics: Angulartics2,
|
||||||
private toasterService: ToasterService) {
|
private toasterService: ToasterService, private messagingService: MessagingService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
@ -104,8 +107,25 @@ export class VaultComponent implements OnInit {
|
|||||||
this.toasterService.popAsync('error', null, this.i18nService.t('syncingFailed'));
|
this.toasterService.popAsync('error', null, this.i18nService.t('syncingFailed'));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'checkSyncVault':
|
||||||
|
try {
|
||||||
|
const lastSync = await this.syncService.getLastSync();
|
||||||
|
let lastSyncAgo = SyncInterval + 1;
|
||||||
|
if (lastSync != null) {
|
||||||
|
lastSyncAgo = new Date().getTime() - lastSync.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastSyncAgo >= SyncInterval) {
|
||||||
|
await this.syncService.fullSync(false);
|
||||||
|
}
|
||||||
|
} catch { }
|
||||||
|
|
||||||
|
this.messagingService.send('scheduleNextSync');
|
||||||
|
break;
|
||||||
case 'syncCompleted':
|
case 'syncCompleted':
|
||||||
|
if (message.successfully) {
|
||||||
await this.load();
|
await this.load();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
detectChanges = false;
|
detectChanges = false;
|
||||||
|
@ -16,7 +16,7 @@ if (watch) {
|
|||||||
|
|
||||||
const i18nService = new I18nService('en', './locales/');
|
const i18nService = new I18nService('en', './locales/');
|
||||||
const windowMain = new WindowMain(dev);
|
const windowMain = new WindowMain(dev);
|
||||||
const messagingMain = new MessagingMain();
|
const messagingMain = new MessagingMain(windowMain);
|
||||||
const menuMain = new MenuMain(windowMain, i18nService);
|
const menuMain = new MenuMain(windowMain, i18nService);
|
||||||
|
|
||||||
windowMain.init();
|
windowMain.init();
|
||||||
|
@ -1,10 +1,19 @@
|
|||||||
import { app, ipcMain } from 'electron';
|
import { app, ipcMain } from 'electron';
|
||||||
// import { getPassword, setPassword, deletePassword } from 'keytar';
|
// import { getPassword, setPassword, deletePassword } from 'keytar';
|
||||||
|
|
||||||
|
import { WindowMain } from './window.main';
|
||||||
|
|
||||||
const KeytarService = 'bitwarden';
|
const KeytarService = 'bitwarden';
|
||||||
|
const SyncInterval = 5 * 60 * 1000; // 5 minutes
|
||||||
|
|
||||||
export class MessagingMain {
|
export class MessagingMain {
|
||||||
|
private syncTimeout: NodeJS.Timer;
|
||||||
|
|
||||||
|
constructor(private windowMain: WindowMain) { }
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
this.scheduleNextSync();
|
||||||
|
|
||||||
ipcMain.on('messagingService', async (event: any, message: any) => {
|
ipcMain.on('messagingService', async (event: any, message: any) => {
|
||||||
switch (message.command) {
|
switch (message.command) {
|
||||||
case 'loggedIn':
|
case 'loggedIn':
|
||||||
@ -13,6 +22,9 @@ export class MessagingMain {
|
|||||||
break;
|
break;
|
||||||
case 'syncCompleted':
|
case 'syncCompleted':
|
||||||
break;
|
break;
|
||||||
|
case 'scheduleNextSync':
|
||||||
|
this.scheduleNextSync();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -40,4 +52,16 @@ export class MessagingMain {
|
|||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private scheduleNextSync() {
|
||||||
|
if (this.syncTimeout) {
|
||||||
|
global.clearTimeout(this.syncTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.syncTimeout = global.setTimeout(() => {
|
||||||
|
this.windowMain.win.webContents.send('messagingService', {
|
||||||
|
command: 'checkSyncVault',
|
||||||
|
});
|
||||||
|
}, SyncInterval);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user