implement notifications service

This commit is contained in:
Kyle Spearrin 2018-08-20 17:40:39 -04:00
parent ce61e62cf0
commit 50c94f587d
12 changed files with 61 additions and 18 deletions

2
jslib

@ -1 +1 @@
Subproject commit b64757132faf1ebb5438bec00720c58604fd29f6 Subproject commit 21e09535896078c4716205e8141f6d3b2182a981

5
package-lock.json generated
View File

@ -96,6 +96,11 @@
"tslib": "^1.7.1" "tslib": "^1.7.1"
} }
}, },
"@aspnet/signalr": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@aspnet/signalr/-/signalr-1.0.2.tgz",
"integrity": "sha512-sXleqUCCbodCOqUA8MjLSvtAgDTvDhEq6j3JyAq/w4RMJhpZ+dXK9+6xEMbzag2hisq5e/8vDC82JYutkcOISQ=="
},
"@ngtools/webpack": { "@ngtools/webpack": {
"version": "1.10.2", "version": "1.10.2",
"resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-1.10.2.tgz", "resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-1.10.2.tgz",

View File

@ -81,6 +81,7 @@
"@angular/platform-browser-dynamic": "5.2.0", "@angular/platform-browser-dynamic": "5.2.0",
"@angular/router": "5.2.0", "@angular/router": "5.2.0",
"@angular/upgrade": "5.2.0", "@angular/upgrade": "5.2.0",
"@aspnet/signalr": "1.0.2",
"angular2-toaster": "4.0.2", "angular2-toaster": "4.0.2",
"angulartics2": "5.0.1", "angulartics2": "5.0.1",
"core-js": "2.4.1", "core-js": "2.4.1",

View File

@ -767,6 +767,9 @@
"identityUrl": { "identityUrl": {
"message": "Identity Server URL" "message": "Identity Server URL"
}, },
"notificationsUrl": {
"message": "Notifications Server URL"
},
"iconsUrl": { "iconsUrl": {
"message": "Icons Server URL" "message": "Icons Server URL"
}, },

View File

@ -20,6 +20,7 @@ import {
UserService, UserService,
} from 'jslib/services'; } from 'jslib/services';
import { ExportService } from 'jslib/services/export.service'; import { ExportService } from 'jslib/services/export.service';
import { NotificationsService } from 'jslib/services/notifications.service';
import { SearchService } from 'jslib/services/search.service'; import { SearchService } from 'jslib/services/search.service';
import { WebCryptoFunctionService } from 'jslib/services/webCryptoFunction.service'; import { WebCryptoFunctionService } from 'jslib/services/webCryptoFunction.service';
@ -45,6 +46,7 @@ import {
UserService as UserServiceAbstraction, UserService as UserServiceAbstraction,
} from 'jslib/abstractions'; } from 'jslib/abstractions';
import { ExportService as ExportServiceAbstraction } from 'jslib/abstractions/export.service'; import { ExportService as ExportServiceAbstraction } from 'jslib/abstractions/export.service';
import { NotificationsService as NotificationsServiceAbstraction } from 'jslib/abstractions/notifications.service';
import { SearchService as SearchServiceAbstraction } from 'jslib/abstractions/search.service'; import { SearchService as SearchServiceAbstraction } from 'jslib/abstractions/search.service';
import { Analytics } from 'jslib/misc'; import { Analytics } from 'jslib/misc';
@ -93,6 +95,7 @@ export default class MainBackground {
auditService: AuditServiceAbstraction; auditService: AuditServiceAbstraction;
exportService: ExportServiceAbstraction; exportService: ExportServiceAbstraction;
searchService: SearchServiceAbstraction; searchService: SearchServiceAbstraction;
notificationsService: NotificationsServiceAbstraction;
analytics: Analytics; analytics: Analytics;
onUpdatedRan: boolean; onUpdatedRan: boolean;
@ -128,7 +131,6 @@ export default class MainBackground {
this.appIdService = new AppIdService(this.storageService); this.appIdService = new AppIdService(this.storageService);
this.apiService = new ApiService(this.tokenService, this.platformUtilsService, this.apiService = new ApiService(this.tokenService, this.platformUtilsService,
async (expired: boolean) => await this.logout(expired)); async (expired: boolean) => await this.logout(expired));
this.environmentService = new EnvironmentService(this.apiService, this.storageService);
this.userService = new UserService(this.tokenService, this.storageService); this.userService = new UserService(this.tokenService, this.storageService);
this.settingsService = new SettingsService(this.userService, this.storageService); this.settingsService = new SettingsService(this.userService, this.storageService);
this.cipherService = new CipherService(this.cryptoService, this.userService, this.settingsService, this.cipherService = new CipherService(this.cryptoService, this.userService, this.settingsService,
@ -155,6 +157,10 @@ export default class MainBackground {
this.containerService = new ContainerService(this.cryptoService, this.platformUtilsService); this.containerService = new ContainerService(this.cryptoService, this.platformUtilsService);
this.auditService = new AuditService(cryptoFunctionService, this.apiService); this.auditService = new AuditService(cryptoFunctionService, this.apiService);
this.exportService = new ExportService(this.folderService, this.cipherService, this.apiService); this.exportService = new ExportService(this.folderService, this.cipherService, this.apiService);
this.notificationsService = new NotificationsService(this.userService, this.tokenService,
this.syncService, this.appIdService);
this.environmentService = new EnvironmentService(this.apiService, this.storageService,
this.notificationsService);
this.analytics = new Analytics(window, () => BrowserApi.gaFilter(), this.platformUtilsService, this.analytics = new Analytics(window, () => BrowserApi.gaFilter(), this.platformUtilsService,
this.storageService, this.appIdService); this.storageService, this.appIdService);
@ -166,7 +172,7 @@ export default class MainBackground {
// Background // Background
this.runtimeBackground = new RuntimeBackground(this, this.autofillService, this.cipherService, this.runtimeBackground = new RuntimeBackground(this, this.autofillService, this.cipherService,
this.platformUtilsService as BrowserPlatformUtilsService, this.storageService, this.i18nService, this.platformUtilsService as BrowserPlatformUtilsService, this.storageService, this.i18nService,
this.analytics); this.analytics, this.notificationsService);
this.tabsBackground = new TabsBackground(this, this.platformUtilsService); this.tabsBackground = new TabsBackground(this, this.platformUtilsService);
this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService, this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService,
this.platformUtilsService, this.analytics); this.platformUtilsService, this.analytics);
@ -202,7 +208,8 @@ export default class MainBackground {
await this.environmentService.setUrlsFromStorage(); await this.environmentService.setUrlsFromStorage();
await this.setIcon(); await this.setIcon();
this.cleanupNotificationQueue(); this.cleanupNotificationQueue();
await this.fullSync(true); this.fullSync(true);
setTimeout(() => this.notificationsService.init(this.environmentService), 2500);
resolve(); resolve();
}, 500); }, 500);
}); });
@ -271,6 +278,7 @@ export default class MainBackground {
await this.setIcon(); await this.setIcon();
await this.refreshBadgeAndMenu(); await this.refreshBadgeAndMenu();
this.notificationsService.updateConnection();
} }
collectPageDetailsForContentScript(tab: any, sender: string, frameId: number = null) { collectPageDetailsForContentScript(tab: any, sender: string, frameId: number = null) {

View File

@ -22,6 +22,8 @@ import MainBackground from './main.background';
import { AutofillService } from '../services/abstractions/autofill.service'; import { AutofillService } from '../services/abstractions/autofill.service';
import BrowserPlatformUtilsService from '../services/browserPlatformUtils.service'; import BrowserPlatformUtilsService from '../services/browserPlatformUtils.service';
import { NotificationsService } from 'jslib/abstractions/notifications.service';
import { Utils } from 'jslib/misc/utils'; import { Utils } from 'jslib/misc/utils';
export default class RuntimeBackground { export default class RuntimeBackground {
@ -33,7 +35,8 @@ export default class RuntimeBackground {
constructor(private main: MainBackground, private autofillService: AutofillService, constructor(private main: MainBackground, private autofillService: AutofillService,
private cipherService: CipherService, private platformUtilsService: BrowserPlatformUtilsService, private cipherService: CipherService, private platformUtilsService: BrowserPlatformUtilsService,
private storageService: StorageService, private i18nService: I18nService, private analytics: Analytics) { private storageService: StorageService, private i18nService: I18nService,
private analytics: Analytics, private notificationsService: NotificationsService) {
this.isSafari = this.platformUtilsService.isSafari(); this.isSafari = this.platformUtilsService.isSafari();
this.runtime = this.isSafari ? safari.application : chrome.runtime; this.runtime = this.isSafari ? safari.application : chrome.runtime;
@ -77,6 +80,10 @@ export default class RuntimeBackground {
async processMessage(msg: any, sender: any, sendResponse: any) { async processMessage(msg: any, sender: any, sendResponse: any) {
switch (msg.command) { switch (msg.command) {
case 'loggedIn': case 'loggedIn':
await this.main.setIcon();
await this.main.refreshBadgeAndMenu(false);
this.notificationsService.updateConnection();
break;
case 'unlocked': case 'unlocked':
case 'locked': case 'locked':
await this.main.setIcon(); await this.main.setIcon();

View File

@ -48,6 +48,11 @@
<input id="identityUrl" type="text" name="IdentityUrl" [(ngModel)]="identityUrl" inputmode="url" <input id="identityUrl" type="text" name="IdentityUrl" [(ngModel)]="identityUrl" inputmode="url"
appInputVerbatim> appInputVerbatim>
</div> </div>
<div class="box-content-row" appBoxRow>
<label for="notificationsUrl">{{'notificationsUrl' | i18n}}</label>
<input id="notificationsUrl" type="text" name="NotificationsUrl" inputmode="url"
[(ngModel)]="notificationsUrl" appInputVerbatim>
</div>
<div class="box-content-row" appBoxRow> <div class="box-content-row" appBoxRow>
<label for="iconsUrl">{{'iconsUrl' | i18n}}</label> <label for="iconsUrl">{{'iconsUrl' | i18n}}</label>
<input id="iconsUrl" type="text" name="IconsUrl" [(ngModel)]="iconsUrl" inputmode="url" <input id="iconsUrl" type="text" name="IconsUrl" [(ngModel)]="iconsUrl" inputmode="url"

View File

@ -27,6 +27,7 @@ import { FolderService } from 'jslib/abstractions/folder.service';
import { I18nService } from 'jslib/abstractions/i18n.service'; import { I18nService } from 'jslib/abstractions/i18n.service';
import { LockService } from 'jslib/abstractions/lock.service'; import { LockService } from 'jslib/abstractions/lock.service';
import { MessagingService } from 'jslib/abstractions/messaging.service'; import { MessagingService } from 'jslib/abstractions/messaging.service';
import { NotificationsService } from 'jslib/abstractions/notifications.service';
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service'; import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { SearchService as SearchServiceAbstraction } from 'jslib/abstractions/search.service'; import { SearchService as SearchServiceAbstraction } from 'jslib/abstractions/search.service';
@ -146,6 +147,11 @@ export function initFactory(i18nService: I18nService, storageService: StorageSer
{ provide: AppIdService, useFactory: getBgService<AppIdService>('appIdService'), deps: [] }, { provide: AppIdService, useFactory: getBgService<AppIdService>('appIdService'), deps: [] },
{ provide: AutofillService, useFactory: getBgService<AutofillService>('autofillService'), deps: [] }, { provide: AutofillService, useFactory: getBgService<AutofillService>('autofillService'), deps: [] },
{ provide: ExportService, useFactory: getBgService<ExportService>('exportService'), deps: [] }, { provide: ExportService, useFactory: getBgService<ExportService>('exportService'), deps: [] },
{
provide: NotificationsService,
useFactory: getBgService<NotificationsService>('notificationsService'),
deps: [],
},
{ {
provide: APP_INITIALIZER, provide: APP_INITIALIZER,
useFactory: initFactory, useFactory: initFactory,

View File

@ -121,9 +121,11 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On
this.ngZone.run(async () => { this.ngZone.run(async () => {
switch (message.command) { switch (message.command) {
case 'syncCompleted': case 'syncCompleted':
if (message.successfully) {
window.setTimeout(() => { window.setTimeout(() => {
this.refresh(); this.refresh();
}, 500); }, 500);
}
break; break;
default: default:
break; break;

View File

@ -94,9 +94,11 @@ export class GroupingsComponent extends BaseGroupingsComponent implements OnInit
this.ngZone.run(async () => { this.ngZone.run(async () => {
switch (message.command) { switch (message.command) {
case 'syncCompleted': case 'syncCompleted':
if (message.successfully) {
window.setTimeout(() => { window.setTimeout(() => {
this.load(); this.load();
}, 500); }, 500);
}
break; break;
default: default:
break; break;

View File

@ -268,7 +268,7 @@
<div *ngIf="cipher.hasPasswordHistory"> <div *ngIf="cipher.hasPasswordHistory">
<b class="font-weight-semibold">{{'passwordHistory' | i18n}}:</b> <b class="font-weight-semibold">{{'passwordHistory' | i18n}}:</b>
<a routerLink="/cipher-password-history" [queryParams]="{cipherId: cipher.id}" <a routerLink="/cipher-password-history" [queryParams]="{cipherId: cipher.id}"
appStopClick title="{{'passwordHistory' | i18n}}" class="text-muted"> appStopClick title="{{'passwordHistory' | i18n}}">
{{cipher.passwordHistory.length}} {{cipher.passwordHistory.length}}
</a> </a>
</div> </div>

View File

@ -1,7 +1,8 @@
import { Location } from '@angular/common'; import { Location } from '@angular/common';
import { import {
ChangeDetectorRef,
Component, Component,
OnInit, NgZone,
} from '@angular/core'; } from '@angular/core';
import { import {
ActivatedRoute, ActivatedRoute,
@ -11,8 +12,6 @@ import {
import { ToasterService } from 'angular2-toaster'; import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { BrowserApi } from '../../browser/browserApi';
import { AuditService } from 'jslib/abstractions/audit.service'; import { AuditService } from 'jslib/abstractions/audit.service';
import { CipherService } from 'jslib/abstractions/cipher.service'; import { CipherService } from 'jslib/abstractions/cipher.service';
import { CryptoService } from 'jslib/abstractions/crypto.service'; import { CryptoService } from 'jslib/abstractions/crypto.service';
@ -21,13 +20,15 @@ import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { TokenService } from 'jslib/abstractions/token.service'; import { TokenService } from 'jslib/abstractions/token.service';
import { TotpService } from 'jslib/abstractions/totp.service'; import { TotpService } from 'jslib/abstractions/totp.service';
import { BroadcasterService } from 'jslib/angular/services/broadcaster.service';
import { ViewComponent as BaseViewComponent } from 'jslib/angular/components/view.component'; import { ViewComponent as BaseViewComponent } from 'jslib/angular/components/view.component';
@Component({ @Component({
selector: 'app-vault-view', selector: 'app-vault-view',
templateUrl: 'view.component.html', templateUrl: 'view.component.html',
}) })
export class ViewComponent extends BaseViewComponent implements OnInit { export class ViewComponent extends BaseViewComponent {
showAttachments = true; showAttachments = true;
constructor(cipherService: CipherService, totpService: TotpService, constructor(cipherService: CipherService, totpService: TotpService,
@ -35,9 +36,11 @@ export class ViewComponent extends BaseViewComponent implements OnInit {
cryptoService: CryptoService, platformUtilsService: PlatformUtilsService, cryptoService: CryptoService, platformUtilsService: PlatformUtilsService,
i18nService: I18nService, analytics: Angulartics2, i18nService: I18nService, analytics: Angulartics2,
auditService: AuditService, private route: ActivatedRoute, auditService: AuditService, private route: ActivatedRoute,
private router: Router, private location: Location) { private router: Router, private location: Location,
broadcasterService: BroadcasterService, ngZone: NgZone,
changeDetectorRef: ChangeDetectorRef) {
super(cipherService, totpService, tokenService, toasterService, cryptoService, platformUtilsService, super(cipherService, totpService, tokenService, toasterService, cryptoService, platformUtilsService,
i18nService, analytics, auditService, window); i18nService, analytics, auditService, window, broadcasterService, ngZone, changeDetectorRef);
} }
ngOnInit() { ngOnInit() {
@ -51,6 +54,7 @@ export class ViewComponent extends BaseViewComponent implements OnInit {
await this.load(); await this.load();
}); });
super.ngOnInit();
} }
edit() { edit() {