1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-24 11:55:50 +01:00

show dialog device util

This commit is contained in:
Kyle Spearrin 2018-02-02 23:42:33 -05:00
parent 269cacec45
commit 0a647e4846
5 changed files with 86 additions and 12 deletions

View File

@ -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();

View File

@ -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;
}

View File

@ -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<any>;
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;
}

View File

@ -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"
}
}

View File

@ -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<boolean> {
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);
}
}