From 0a647e4846912530874f4abb204cc049b7c7e819 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 2 Feb 2018 23:42:33 -0500 Subject: [PATCH] show dialog device util --- src/app/vault/add-edit.component.ts | 17 ++++++++---- src/app/vault/attachments.component.ts | 23 ++++++++++++++--- src/app/vault/folder-add-edit.component.ts | 9 +++++-- src/locales/en/messages.json | 27 ++++++++++++++++++++ src/services/desktopPlatformUtils.service.ts | 22 +++++++++++++++- 5 files changed, 86 insertions(+), 12 deletions(-) diff --git a/src/app/vault/add-edit.component.ts b/src/app/vault/add-edit.component.ts index 9a12c67001..075639aebb 100644 --- a/src/app/vault/add-edit.component.ts +++ b/src/app/vault/add-edit.component.ts @@ -175,7 +175,10 @@ export class AddEditComponent implements OnChanges { } async delete() { - if (!confirm(this.i18nService.t('deleteItemConfirmation'))) { + const confirmed = await this.platformUtilsService.showDialog( + this.i18nService.t('deleteItemConfirmation'), this.i18nService.t('deleteItem'), + this.i18nService.t('yes'), this.i18nService.t('no'), 'warning') + if (!confirmed) { return; } @@ -188,10 +191,14 @@ export class AddEditComponent implements OnChanges { } catch { } } - generatePassword() { - if (this.cipher.login != null && this.cipher.login.password != null && this.cipher.login.password.length && - !confirm(this.i18nService.t('overwritePasswordConfirmation'))) { - return; + async generatePassword() { + if (this.cipher.login != null && this.cipher.login.password != null && this.cipher.login.password.length) { + const confirmed = await this.platformUtilsService.showDialog( + this.i18nService.t('overwritePasswordConfirmation'), this.i18nService.t('overwritePassword'), + this.i18nService.t('yes'), this.i18nService.t('no')) + if (!confirmed) { + return; + } } this.onGeneratePassword.emit(); diff --git a/src/app/vault/attachments.component.ts b/src/app/vault/attachments.component.ts index 7b34b96d8d..231a481d73 100644 --- a/src/app/vault/attachments.component.ts +++ b/src/app/vault/attachments.component.ts @@ -14,6 +14,7 @@ import { ToasterService } from 'angular2-toaster'; import { CipherService } from 'jslib/abstractions/cipher.service'; import { CryptoService } from 'jslib/abstractions/crypto.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; +import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { TokenService } from 'jslib/abstractions/token.service'; import { Cipher } from 'jslib/models/domain/cipher'; @@ -37,7 +38,8 @@ export class AttachmentsComponent implements OnInit { constructor(private cipherService: CipherService, private analytics: Angulartics2, private toasterService: ToasterService, private i18nService: I18nService, - private cryptoService: CryptoService, private tokenService: TokenService) { } + private cryptoService: CryptoService, private tokenService: TokenService, + private platformUtilsService: PlatformUtilsService) { } async ngOnInit() { this.cipherDomain = await this.cipherService.get(this.cipherId); @@ -49,9 +51,19 @@ export class AttachmentsComponent implements OnInit { this.canAccessAttachments = isPremium || this.cipher.organizationId != null; if (!this.canAccessAttachments) { - alert(this.i18nService.t('premiumRequiredDesc')); + const confirmed = await this.platformUtilsService.showDialog( + this.i18nService.t('premiumRequiredDesc'), this.i18nService.t('premiumRequired'), + this.i18nService.t('learnMore'), this.i18nService.t('cancel')) + if (confirmed) { + this.platformUtilsService.launchUri('https://vault.bitwarden.com/#/?premium=purchase'); + } } else if (!this.hasUpdatedKey) { - alert(this.i18nService.t('updateKey')); + const confirmed = await this.platformUtilsService.showDialog( + this.i18nService.t('updateKey'), this.i18nService.t('featureUnavailable'), + this.i18nService.t('learnMore'), this.i18nService.t('cancel'), 'warning') + if (confirmed) { + this.platformUtilsService.launchUri('https://help.bitwarden.com/article/update-encryption-key/'); + } } } @@ -96,7 +108,10 @@ export class AttachmentsComponent implements OnInit { return; } - if (!confirm(this.i18nService.t('deleteAttachmentConfirmation'))) { + const confirmed = await this.platformUtilsService.showDialog( + this.i18nService.t('deleteAttachmentConfirmation'), this.i18nService.t('deleteAttachment'), + this.i18nService.t('yes'), this.i18nService.t('no'), 'warning') + if (!confirmed) { return; } diff --git a/src/app/vault/folder-add-edit.component.ts b/src/app/vault/folder-add-edit.component.ts index c939811382..45ec6cbb65 100644 --- a/src/app/vault/folder-add-edit.component.ts +++ b/src/app/vault/folder-add-edit.component.ts @@ -13,6 +13,7 @@ import { ToasterService } from 'angular2-toaster'; import { FolderService } from 'jslib/abstractions/folder.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; +import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { FolderView } from 'jslib/models/view/folderView'; @@ -32,7 +33,8 @@ export class FolderAddEditComponent implements OnInit { deletePromise: Promise; constructor(private folderService: FolderService, private i18nService: I18nService, - private analytics: Angulartics2, private toasterService: ToasterService) { } + private analytics: Angulartics2, private toasterService: ToasterService, + private platformUtilsService: PlatformUtilsService) { } async ngOnInit() { this.editMode = this.folderId != null; @@ -66,7 +68,10 @@ export class FolderAddEditComponent implements OnInit { } async delete() { - if (!confirm(this.i18nService.t('deleteFolderConfirmation'))) { + const confirmed = await this.platformUtilsService.showDialog( + this.i18nService.t('deleteFolderConfirmation'), this.i18nService.t('deleteFolder'), + this.i18nService.t('yes'), this.i18nService.t('no'), 'warning') + if (!confirmed) { return; } diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index d21d40cf64..f80ec7e843 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -284,6 +284,15 @@ "editedItem": { "message": "Edited item" }, + "deleteItem": { + "message": "Delete Item" + }, + "deleteFolder": { + "message": "Delete Folder" + }, + "deleteAttachment": { + "message": "Delete Attachment" + }, "deleteItemConfirmation": { "message": "Are you sure you want to delete this item?" }, @@ -567,5 +576,23 @@ }, "environmentSaved": { "message": "The environment URLs have been saved." + }, + "ok": { + "message": "Ok" + }, + "yes": { + "message": "Yes" + }, + "no": { + "message": "No" + }, + "overwritePassword": { + "message": "Overwrite Password" + }, + "learnMore": { + "message": "Learn more" + }, + "featureUnavailable": { + "message": "Feature Unavailable" } } diff --git a/src/services/desktopPlatformUtils.service.ts b/src/services/desktopPlatformUtils.service.ts index 355ab1bc28..44798dc8c4 100644 --- a/src/services/desktopPlatformUtils.service.ts +++ b/src/services/desktopPlatformUtils.service.ts @@ -1,4 +1,4 @@ -import { ipcRenderer, shell } from 'electron'; +import { remote, shell } from 'electron'; import { DeviceType } from 'jslib/enums'; @@ -123,4 +123,24 @@ export class DesktopPlatformUtilsService implements PlatformUtilsService { // ref: https://github.com/electron/electron/issues/3226 return false; } + + showDialog(text: string, title?: string, confirmText?: string, cancelText?: string, type?: string): + Promise { + const buttons = [confirmText == null ? this.i18nService.t('ok') : confirmText]; + if (cancelText != null) { + buttons.push(cancelText); + } + + const result = remote.dialog.showMessageBox(remote.getCurrentWindow(), { + type: type, + title: title, + message: text, + buttons: buttons, + cancelId: buttons.length === 2 ? 1 : null, + defaultId: 0, + noLink: true, + }); + + return Promise.resolve(result === 0); + } }