From e40ee1e3a8c6f1226fa7cad13f110889bdc7b83d Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 3 May 2018 15:46:20 -0400 Subject: [PATCH] get sync status. clear sync cache --- src/app/app.component.ts | 4 ++++ src/app/tabs/dashboard.component.html | 1 + src/app/tabs/dashboard.component.ts | 5 ++++- src/app/tabs/more.component.html | 3 +++ src/app/tabs/more.component.ts | 11 ++++++++++- src/app/tabs/settings.component.ts | 8 ++++++++ src/locales/en/messages.json | 6 ++++++ src/main/messaging.main.ts | 7 +++++++ src/services/configuration.service.ts | 5 ++++- 9 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 6b240e56..7be18abc 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -81,6 +81,10 @@ export class AppComponent implements OnInit { this.stateService.save('profileOrganizations', profile.organizations); } break; + case 'syncScheduleStarted': + case 'syncScheduleStopped': + this.stateService.save('syncingDir', message.command === 'syncScheduleStarted'); + break; case 'logout': this.logOut(!!message.expired); break; diff --git a/src/app/tabs/dashboard.component.html b/src/app/tabs/dashboard.component.html index f9f9759d..73507288 100644 --- a/src/app/tabs/dashboard.component.html +++ b/src/app/tabs/dashboard.component.html @@ -32,6 +32,7 @@

Testing

+

You can run tests to see how your directory and sync settings are working. Tests will not sync to your Bitwarden organization.

+
diff --git a/src/app/tabs/more.component.ts b/src/app/tabs/more.component.ts index 4305fcef..af2e7848 100644 --- a/src/app/tabs/more.component.ts +++ b/src/app/tabs/more.component.ts @@ -3,9 +3,12 @@ import { OnInit, } from '@angular/core'; +import { ToasterService } from 'angular2-toaster'; + import { I18nService } from 'jslib/abstractions/i18n.service'; import { MessagingService } from 'jslib/abstractions/messaging.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; +import { ConfigurationService } from '../../services/configuration.service'; @Component({ selector: 'app-more', @@ -16,7 +19,8 @@ export class MoreComponent implements OnInit { year: string; constructor(private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, - private messagingService: MessagingService) { } + private messagingService: MessagingService, private configurationService: ConfigurationService, + private toasterService: ToasterService) { } ngOnInit() { this.year = new Date().getFullYear().toString(); @@ -33,4 +37,9 @@ export class MoreComponent implements OnInit { this.messagingService.send('logout'); } } + + async clearCache() { + await this.configurationService.clearStatefulSettings(true); + this.toasterService.popAsync('success', null, this.i18nService.t('syncCacheCleared')); + } } diff --git a/src/app/tabs/settings.component.ts b/src/app/tabs/settings.component.ts index 83d2ba10..f1a90fe4 100644 --- a/src/app/tabs/settings.component.ts +++ b/src/app/tabs/settings.component.ts @@ -89,6 +89,14 @@ export class SettingsComponent implements OnInit, OnDestroy { this.sync.groupNameAttribute = 'name'; } + if (this.sync.interval != null) { + if (this.sync.interval <= 0) { + this.sync.interval = null; + } else if (this.sync.interval < 5) { + this.sync.interval = 5; + } + } + await this.configurationService.saveOrganizationId(this.organizationId); await this.configurationService.saveDirectoryType(this.directory); await this.configurationService.saveDirectory(DirectoryType.Ldap, this.ldap); diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index e58e7528..afd6b103 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -440,5 +440,11 @@ }, "token": { "message": "Token" + }, + "clearSyncCache": { + "message": "Clear Sync Cache" + }, + "syncCacheCleared": { + "message": "The sync cache has been cleared." } } diff --git a/src/main/messaging.main.ts b/src/main/messaging.main.ts index 0fe9faf3..dd48e5b0 100644 --- a/src/main/messaging.main.ts +++ b/src/main/messaging.main.ts @@ -25,6 +25,9 @@ export class MessagingMain { this.scheduleNextSync(); break; case 'cancelDirSync': + this.windowMain.win.webContents.send('messagingService', { + command: 'syncScheduleStopped', + }); if (this.syncTimeout) { global.clearTimeout(this.syncTimeout); } @@ -35,6 +38,10 @@ export class MessagingMain { } private scheduleNextSync() { + this.windowMain.win.webContents.send('messagingService', { + command: 'syncScheduleStarted', + }); + if (this.syncTimeout) { global.clearTimeout(this.syncTimeout); } diff --git a/src/services/configuration.service.ts b/src/services/configuration.service.ts index e5cffdde..e92cfb6d 100644 --- a/src/services/configuration.service.ts +++ b/src/services/configuration.service.ts @@ -198,10 +198,13 @@ export class ConfigurationService { } } - private async clearStatefulSettings() { + async clearStatefulSettings(hashToo = false) { await this.saveUserDeltaToken(null); await this.saveGroupDeltaToken(null); await this.saveLastGroupSyncDate(null); await this.saveLastUserSyncDate(null); + if (hashToo) { + await this.saveLastSyncHash(null); + } } }