diff --git a/src/frontend/app/service/notification.service.ts b/src/frontend/app/service/notification.service.ts index ccd235e1ff3bff073b25bc5a16b9a22bc84af1c1..a1b0fa175b12839a0d983d9ac111cb0dc5256148 100644 --- a/src/frontend/app/service/notification.service.ts +++ b/src/frontend/app/service/notification.service.ts @@ -34,8 +34,11 @@ export class NotificationService { toast.present(); } - async error(message: string) { - const msg = message.includes('lang.') ? this.translate.instant(message) : message; + async error(message: any) { + if (typeof message === 'object') { + message = message.toString(); + } + const msg = message.indexOf('lang.') > -1 ? this.translate.instant(message) : message; const toast = await this.toastController.create({ cssClass: 'notif-error', duration: 3000, diff --git a/src/frontend/app/service/signature-method/signature-method-modal.component.html b/src/frontend/app/service/signature-method/signature-method-modal.component.html index b779d18068b2702b4a54c3c44ff3c620d44c817b..52c27d6b6f9d8f80a79b164a9d4b3f6e17baefa7 100644 --- a/src/frontend/app/service/signature-method/signature-method-modal.component.html +++ b/src/frontend/app/service/signature-method/signature-method-modal.component.html @@ -1,4 +1,4 @@ <ion-content> - <peculiar-fortify-certificates style="height: 100%;width: 100%;" language="fr" [filters]="filters" + <peculiar-fortify-certificates *ngIf="!signaturesService.mustRefreshCerts" style="height: 100%;width: 100%;" language="fr" [filters]="filters" (selectionSuccess)="certificateChosen($event)" (selectionCancel)="cancelSign()" hide-footer></peculiar-fortify-certificates> </ion-content> diff --git a/src/frontend/app/service/signature-method/signature-method-modal.component.ts b/src/frontend/app/service/signature-method/signature-method-modal.component.ts index ba69dafa54ec270eda38948df660eafb521ac0d0..3b9c9fd57e82ea840c67b499132dbcf8d33c1f5a 100644 --- a/src/frontend/app/service/signature-method/signature-method-modal.component.ts +++ b/src/frontend/app/service/signature-method/signature-method-modal.component.ts @@ -41,7 +41,6 @@ export class SignatureMethodModalComponent implements OnInit, OnDestroy { certificate: any; signatureLength: any = null; - server: any = null; api: FortifyAPI = null; constructor( @@ -68,7 +67,7 @@ export class SignatureMethodModalComponent implements OnInit, OnDestroy { this.filters.keyUsage.push(signatureModeData.keyUsage); } - await this.initFortify(); + await this.processInitFortify(); } async ngOnDestroy(): Promise<void> { @@ -88,11 +87,30 @@ export class SignatureMethodModalComponent implements OnInit, OnDestroy { if (challenge) { await this.api.login(); } + + if (this.signaturesService.mustRefreshCerts) { + await this.updateProvider(null); + } this.api.server.cardReader .on('insert', (event: any) => this.updateProvider(event)) .on('remove', (event: any) => this.updateProvider(event)); } + async processInitFortify() { + if (this.signaturesService.mustRefreshCerts) { + this.loadingController.create({ + message: this.translate.instant('lang.waiting'), + spinner: 'dots' + }).then(async (load: HTMLIonLoadingElement) => { + load.present(); + await this.initFortify(); + load.dismiss(); + }); + } else { + await this.initFortify(); + } + } + async waitFortifyStart() { let fortifyState: boolean = false; while (!fortifyState) { @@ -120,9 +138,8 @@ export class SignatureMethodModalComponent implements OnInit, OnDestroy { load.present(); try { - this.server = certData.detail.socketProvider; this.checkWebsocketSession(); - this.provider = await this.server.getCrypto(certData.detail.providerId); + this.provider = await this.api.server.getCrypto(certData.detail.providerId); this.checkWebsocketSession(); this.cert = await this.provider.certStorage.getItem(certData.detail.certificateId); this.checkWebsocketSession(); @@ -147,14 +164,17 @@ export class SignatureMethodModalComponent implements OnInit, OnDestroy { result = await this.sendAndSign(this.idsToProcess[index]); } load.dismiss(); + setTimeout(() => { + this.signaturesService.mustRefreshCerts = true; + }, 500); this.modalController.dismiss(result); }); } async checkWebsocketSession() { // session closed?! - while (this.server.client.state !== WebSocket.OPEN) { - await this.server.connect(); + while (this.api.server.state !== WebSocket.OPEN) { + await this.api.server.connect(); await new Promise(resolve => setTimeout(resolve, 150)); } } @@ -172,6 +192,9 @@ export class SignatureMethodModalComponent implements OnInit, OnDestroy { } else if (!this.functionsService.empty(event?.action) && event?.action.includes('remove')) { this.notificationService.message('lang.outputCardReaderUpdateCerts'); this.modalController.dismiss('refresh_certs'); + } else if (this.signaturesService.mustRefreshCerts && event === null) { + this.modalController.dismiss('refresh_certs'); + this.signaturesService.mustRefreshCerts = false; } } @@ -261,6 +284,7 @@ export class SignatureMethodModalComponent implements OnInit, OnDestroy { } cancelSign() { + this.signaturesService.mustRefreshCerts = true; this.modalController.dismiss(false); } diff --git a/src/frontend/app/service/signatures.service.ts b/src/frontend/app/service/signatures.service.ts index 15568b71092953dfcbcb731bf92b944e7bc4d4ff..1272d4aac4a4e0e34d7dad3a855c7d933c96cb9b 100755 --- a/src/frontend/app/service/signatures.service.ts +++ b/src/frontend/app/service/signatures.service.ts @@ -36,6 +36,8 @@ export class SignaturesContentService { appSession: any; + mustRefreshCerts: boolean = true; + private portalHost: DomPortalOutlet; constructor(