1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-30 12:54:31 +01:00

Replace toaster library (#1183)

This commit is contained in:
Oscar Hinton 2021-12-07 19:42:31 +00:00 committed by GitHub
parent 2822d748f1
commit 5fd1da0c58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 70 additions and 92 deletions

2
jslib

@ -1 +1 @@
Subproject commit 5db94cc9d06ba478a29e9b625993108dfa0d7ec8 Subproject commit a6b95b15e36737ccf2e7664ed3c881bc19366b84

45
package-lock.json generated
View File

@ -13,7 +13,7 @@
"@bitwarden/jslib-angular": "file:jslib/angular", "@bitwarden/jslib-angular": "file:jslib/angular",
"@bitwarden/jslib-common": "file:jslib/common", "@bitwarden/jslib-common": "file:jslib/common",
"@bitwarden/jslib-electron": "file:jslib/electron", "@bitwarden/jslib-electron": "file:jslib/electron",
"angular2-toaster": "^11.0.1", "ngx-toastr": "^13.2.1",
"node-ipc": "^9.1.4", "node-ipc": "^9.1.4",
"nord": "^0.2.1", "nord": "^0.2.1",
"regedit": "^3.0.3", "regedit": "^3.0.3",
@ -1740,20 +1740,6 @@
"ajv": "^6.9.1" "ajv": "^6.9.1"
} }
}, },
"node_modules/angular2-toaster": {
"version": "11.0.1",
"resolved": "https://registry.npmjs.org/angular2-toaster/-/angular2-toaster-11.0.1.tgz",
"integrity": "sha512-IRXE5zujPMNOhckcp+Hk2n+UrKSrlAviz55wGvSd9ECrqsSRjgh148UEtgsqkcYQ8leKcybZ4d0lrueDuQofNA==",
"dependencies": {
"tslib": "^2.0.0"
},
"peerDependencies": {
"@angular/common": "^11.0.0",
"@angular/compiler": "^11.0.0",
"@angular/core": "^11.0.0",
"rxjs": "^6.5.3"
}
},
"node_modules/ansi-align": { "node_modules/ansi-align": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz", "resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz",
@ -8478,6 +8464,19 @@
"integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==",
"dev": true "dev": true
}, },
"node_modules/ngx-toastr": {
"version": "13.2.1",
"resolved": "https://registry.npmjs.org/ngx-toastr/-/ngx-toastr-13.2.1.tgz",
"integrity": "sha512-UAzp7/xWK9IXA2LsOmhpaaIGCqscvJokoQpBNpAMrjEkDeSlFf8PWQAuQY795KW0mJb3qF9UG/s23nsXfMYKmg==",
"dependencies": {
"tslib": "^2.0.0"
},
"peerDependencies": {
"@angular/common": ">=10.0.0-0",
"@angular/core": ">=10.0.0-0",
"@angular/platform-browser": ">=10.0.0-0"
}
},
"node_modules/no-case": { "node_modules/no-case": {
"version": "3.0.4", "version": "3.0.4",
"resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz", "resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz",
@ -15472,14 +15471,6 @@
"dev": true, "dev": true,
"requires": {} "requires": {}
}, },
"angular2-toaster": {
"version": "11.0.1",
"resolved": "https://registry.npmjs.org/angular2-toaster/-/angular2-toaster-11.0.1.tgz",
"integrity": "sha512-IRXE5zujPMNOhckcp+Hk2n+UrKSrlAviz55wGvSd9ECrqsSRjgh148UEtgsqkcYQ8leKcybZ4d0lrueDuQofNA==",
"requires": {
"tslib": "^2.0.0"
}
},
"ansi-align": { "ansi-align": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz", "resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz",
@ -20732,6 +20723,14 @@
"integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==",
"dev": true "dev": true
}, },
"ngx-toastr": {
"version": "13.2.1",
"resolved": "https://registry.npmjs.org/ngx-toastr/-/ngx-toastr-13.2.1.tgz",
"integrity": "sha512-UAzp7/xWK9IXA2LsOmhpaaIGCqscvJokoQpBNpAMrjEkDeSlFf8PWQAuQY795KW0mJb3qF9UG/s23nsXfMYKmg==",
"requires": {
"tslib": "^2.0.0"
}
},
"no-case": { "no-case": {
"version": "3.0.4", "version": "3.0.4",
"resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz", "resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz",

View File

@ -285,7 +285,7 @@
"@bitwarden/jslib-angular": "file:jslib/angular", "@bitwarden/jslib-angular": "file:jslib/angular",
"@bitwarden/jslib-common": "file:jslib/common", "@bitwarden/jslib-common": "file:jslib/common",
"@bitwarden/jslib-electron": "file:jslib/electron", "@bitwarden/jslib-electron": "file:jslib/electron",
"angular2-toaster": "^11.0.1", "ngx-toastr": "^13.2.1",
"node-ipc": "^9.1.4", "node-ipc": "^9.1.4",
"nord": "^0.2.1", "nord": "^0.2.1",
"regedit": "^3.0.3", "regedit": "^3.0.3",

View File

@ -1,10 +1,3 @@
import {
BodyOutputType,
Toast,
ToasterConfig,
ToasterService,
} from 'angular2-toaster';
import { import {
Component, Component,
NgZone, NgZone,
@ -16,6 +9,10 @@ import {
} from '@angular/core'; } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser'; import { DomSanitizer } from '@angular/platform-browser';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import {
IndividualConfig,
ToastrService,
} from 'ngx-toastr';
import { PremiumComponent } from './accounts/premium.component'; import { PremiumComponent } from './accounts/premium.component';
import { SettingsComponent } from './accounts/settings.component'; import { SettingsComponent } from './accounts/settings.component';
@ -64,7 +61,6 @@ const SyncInterval = 6 * 60 * 60 * 1000; // 6 hours
selector: 'app-root', selector: 'app-root',
styles: [], styles: [],
template: ` template: `
<toaster-container [toasterconfig]="toasterConfig" aria-live="polite"></toaster-container>
<ng-template #settings></ng-template> <ng-template #settings></ng-template>
<ng-template #premium></ng-template> <ng-template #premium></ng-template>
<ng-template #passwordHistory></ng-template> <ng-template #passwordHistory></ng-template>
@ -83,13 +79,6 @@ export class AppComponent implements OnInit {
@ViewChild('appPasswordGenerator', { read: ViewContainerRef, static: true }) @ViewChild('appPasswordGenerator', { read: ViewContainerRef, static: true })
passwordGeneratorModalRef: ViewContainerRef; passwordGeneratorModalRef: ViewContainerRef;
toasterConfig: ToasterConfig = new ToasterConfig({
showCloseButton: true,
mouseoverTimerStop: true,
animation: 'flyRight',
limit: 5,
});
private lastActivity: number = null; private lastActivity: number = null;
private modal: ModalRef = null; private modal: ModalRef = null;
private idleTimer: number = null; private idleTimer: number = null;
@ -100,7 +89,7 @@ export class AppComponent implements OnInit {
private settingsService: SettingsService, private syncService: SyncService, private settingsService: SettingsService, private syncService: SyncService,
private passwordGenerationService: PasswordGenerationService, private cipherService: CipherService, private passwordGenerationService: PasswordGenerationService, private cipherService: CipherService,
private authService: AuthService, private router: Router, private authService: AuthService, private router: Router,
private toasterService: ToasterService, private i18nService: I18nService, private toastrService: ToastrService, private i18nService: I18nService,
private sanitizer: DomSanitizer, private ngZone: NgZone, private sanitizer: DomSanitizer, private ngZone: NgZone,
private vaultTimeoutService: VaultTimeoutService, private storageService: StorageService, private vaultTimeoutService: VaultTimeoutService, private storageService: StorageService,
private cryptoService: CryptoService, private logService: LogService, private cryptoService: CryptoService, private logService: LogService,
@ -224,9 +213,9 @@ export class AppComponent implements OnInit {
case 'syncVault': case 'syncVault':
try { try {
await this.syncService.fullSync(true, true); await this.syncService.fullSync(true, true);
this.toasterService.popAsync('success', null, this.i18nService.t('syncingComplete')); this.platformUtilsService.showToast('success', null, this.i18nService.t('syncingComplete'));
} catch { } catch {
this.toasterService.popAsync('error', null, this.i18nService.t('syncingFailed')); this.platformUtilsService.showToast('error', null, this.i18nService.t('syncingFailed'));
} }
break; break;
case 'checkSyncVault': case 'checkSyncVault':
@ -374,7 +363,7 @@ export class AppComponent implements OnInit {
this.searchService.clearIndex(); this.searchService.clearIndex();
this.authService.logOut(async () => { this.authService.logOut(async () => {
if (expired) { if (expired) {
this.toasterService.popAsync('warning', this.i18nService.t('loggedOut'), this.platformUtilsService.showToast('warning', this.i18nService.t('loggedOut'),
this.i18nService.t('loginExpired')); this.i18nService.t('loginExpired'));
} }
this.router.navigate(['login']); this.router.navigate(['login']);
@ -428,30 +417,29 @@ export class AppComponent implements OnInit {
} }
private showToast(msg: any) { private showToast(msg: any) {
const toast: Toast = {
type: msg.type,
title: msg.title,
};
if (typeof (msg.text) === 'string') {
toast.body = msg.text;
} else if (msg.text.length === 1) {
toast.body = msg.text[0];
} else {
let message = ''; let message = '';
const options: Partial<IndividualConfig> = {};
if (typeof (msg.text) === 'string') {
message = msg.text;
} else if (msg.text.length === 1) {
message = msg.text[0];
} else {
msg.text.forEach((t: string) => msg.text.forEach((t: string) =>
message += ('<p>' + this.sanitizer.sanitize(SecurityContext.HTML, t) + '</p>')); message += ('<p>' + this.sanitizer.sanitize(SecurityContext.HTML, t) + '</p>'));
toast.body = message; options.enableHtml = true;
toast.bodyOutputType = BodyOutputType.TrustedHtml;
} }
if (msg.options != null) { if (msg.options != null) {
if (msg.options.trustedHtml === true) { if (msg.options.trustedHtml === true) {
toast.bodyOutputType = BodyOutputType.TrustedHtml; options.enableHtml = true;
} }
if (msg.options.timeout != null && msg.options.timeout > 0) { if (msg.options.timeout != null && msg.options.timeout > 0) {
toast.timeout = msg.options.timeout; options.timeOut = msg.options.timeout;
} }
} }
this.toasterService.popAsync(toast);
this.toastrService.show(message, msg.title, options, 'toast-' + msg.type);
} }
private routeToVault(action: string, cipherType: CipherType) { private routeToVault(action: string, cipherType: CipherType) {

View File

@ -1,7 +1,5 @@
import 'zone.js/dist/zone'; import 'zone.js/dist/zone';
import { ToasterModule } from 'angular2-toaster';
import { AppRoutingModule } from './app-routing.module'; import { AppRoutingModule } from './app-routing.module';
import { ServicesModule } from './services.module'; import { ServicesModule } from './services.module';
@ -33,6 +31,7 @@ import { VaultTimeoutInputComponent } from './accounts/vault-timeout-input.compo
import { CalloutComponent } from 'jslib-angular/components/callout.component'; import { CalloutComponent } from 'jslib-angular/components/callout.component';
import { IconComponent } from 'jslib-angular/components/icon.component'; import { IconComponent } from 'jslib-angular/components/icon.component';
import { BitwardenToastModule } from 'jslib-angular/components/toastr.component';
import { A11yTitleDirective } from 'jslib-angular/directives/a11y-title.directive'; import { A11yTitleDirective } from 'jslib-angular/directives/a11y-title.directive';
import { ApiActionDirective } from 'jslib-angular/directives/api-action.directive'; import { ApiActionDirective } from 'jslib-angular/directives/api-action.directive';
@ -177,7 +176,11 @@ registerLocaleData(localeZhTw, 'zh-TW');
FormsModule, FormsModule,
ReactiveFormsModule, ReactiveFormsModule,
ServicesModule, ServicesModule,
ToasterModule.forRoot(), BitwardenToastModule.forRoot({
maxOpened: 5,
autoDismiss: true,
closeButton: true,
}),
ScrollingModule, ScrollingModule,
A11yModule, A11yModule,
], ],

View File

@ -14,8 +14,6 @@ import {
import { first } from 'rxjs/operators'; import { first } from 'rxjs/operators';
import { ToasterService } from 'angular2-toaster';
import { AddEditComponent } from './add-edit.component'; import { AddEditComponent } from './add-edit.component';
import { AttachmentsComponent } from './attachments.component'; import { AttachmentsComponent } from './attachments.component';
import { CiphersComponent } from './ciphers.component'; import { CiphersComponent } from './ciphers.component';
@ -86,7 +84,7 @@ export class VaultComponent implements OnInit, OnDestroy {
private i18nService: I18nService, private modalService: ModalService, private i18nService: I18nService, private modalService: ModalService,
private broadcasterService: BroadcasterService, private changeDetectorRef: ChangeDetectorRef, private broadcasterService: BroadcasterService, private changeDetectorRef: ChangeDetectorRef,
private ngZone: NgZone, private syncService: SyncService, private ngZone: NgZone, private syncService: SyncService,
private toasterService: ToasterService, private messagingService: MessagingService, private messagingService: MessagingService,
private platformUtilsService: PlatformUtilsService, private eventService: EventService, private platformUtilsService: PlatformUtilsService, private eventService: EventService,
private totpService: TotpService, private userService: UserService, private totpService: TotpService, private userService: UserService,
private passwordRepromptService: PasswordRepromptService) { } private passwordRepromptService: PasswordRepromptService) { }
@ -651,7 +649,7 @@ export class VaultComponent implements OnInit, OnDestroy {
} }
this.platformUtilsService.copyToClipboard(value); this.platformUtilsService.copyToClipboard(value);
this.toasterService.popAsync('info', null, this.platformUtilsService.showToast('info', null,
this.i18nService.t('valueCopied', this.i18nService.t(labelI18nKey))); this.i18nService.t('valueCopied', this.i18nService.t(labelI18nKey)));
if (this.action === 'view') { if (this.action === 'view') {
this.messagingService.send('minimizeOnCopy'); this.messagingService.send('minimizeOnCopy');

View File

@ -1,43 +1,41 @@
$fa-font-path: "~font-awesome/fonts"; $fa-font-path: "~font-awesome/fonts";
@import "~font-awesome/scss/font-awesome.scss"; @import "~font-awesome/scss/font-awesome.scss";
@import "~angular2-toaster/toaster"; @import '~ngx-toastr/toastr';
@import "~sweetalert2/src/sweetalert2.scss"; @import "~sweetalert2/src/sweetalert2.scss";
@import "variables.scss"; @import "variables.scss";
.toast-container { .toast-container {
.toast-close-button { .toast-close-button {
margin-right: 4px;
font-size: 18px; font-size: 18px;
margin-right: 4px;
} }
.toast { .ngx-toastr {
opacity: 1 !important; align-items: center;
background-image: none !important; background-image: none !important;
border-radius: $border-radius; border-radius: $border-radius;
box-shadow: 0 0 8px rgba(0, 0, 0, 0.35); box-shadow: 0 0 8px rgba(0, 0, 0, 0.35);
display: flex; display: flex;
align-items: center; padding: 15px;
.toast-close-button {
position: absolute;
right: 5px;
top: 0;
}
&:hover { &:hover {
box-shadow: 0 0 10px rgba(0, 0, 0, 0.6); box-shadow: 0 0 10px rgba(0, 0, 0, 0.6);
} }
&:before { .icon i::before {
float: left;
font-style: normal;
font-family: FontAwesome; font-family: FontAwesome;
font-size: 25px; font-size: 25px;
line-height: 20px; line-height: 20px;
float: left; padding-right: 15px;
color: #ffffff;
margin: auto 0 auto 15px;
}
.toast-content {
padding: 15px;
}
.toaster-icon {
display: none;
} }
.toast-message { .toast-message {
@ -51,49 +49,41 @@ $fa-font-path: "~font-awesome/fonts";
} }
&.toast-danger, &.toast-error { &.toast-danger, &.toast-error {
background-image: none !important;
@include themify($themes) { @include themify($themes) {
background-color: themed('dangerColor'); background-color: themed('dangerColor');
} }
&:before { .icon i::before {
content: "\f0e7"; content: "\f0e7";
} }
} }
&.toast-warning { &.toast-warning {
background-image: none !important;
@include themify($themes) { @include themify($themes) {
background-color: themed('warningColor'); background-color: themed('warningColor');
} }
&:before { .icon i::before {
content: "\f071"; content: "\f071";
} }
} }
&.toast-info { &.toast-info {
background-image: none !important;
@include themify($themes) { @include themify($themes) {
background-color: themed('infoColor'); background-color: themed('infoColor');
} }
&:before { .icon i:before {
content: "\f05a"; content: "\f05a";
} }
} }
&.toast-success { &.toast-success {
background-image: none !important;
@include themify($themes) { @include themify($themes) {
background-color: themed('successColor'); background-color: themed('successColor');
} }
&:before { .icon i:before {
content: "\f00C"; content: "\f00C";
} }
} }