1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-18 02:41:15 +02:00

Refactor Send 'copy link' functionality (#373)

This commit is contained in:
Thomas Rittson 2021-05-12 06:39:31 +10:00 committed by GitHub
parent 2cf5d767b5
commit 8244971026
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 15 deletions

View File

@ -29,7 +29,7 @@ export abstract class PlatformUtilsService {
showPasswordDialog: (title: string, body: string, passwordValidation: (value: string) => Promise<boolean>) => Promise<boolean>;
isDev: () => boolean;
isSelfHost: () => boolean;
copyToClipboard: (text: string, options?: any) => void;
copyToClipboard: (text: string, options?: any) => void | boolean;
readFromClipboard: (options?: any) => Promise<string>;
supportsBiometric: () => Promise<boolean>;
authenticateBiometric: () => Promise<boolean>;

View File

@ -302,8 +302,6 @@ export class AddEditComponent implements OnInit {
this.formPromise = this.encryptSend(file)
.then(async encSend => {
const uploadPromise = this.sendService.saveWithServer(encSend);
let inactive = false;
setTimeout(() => inactive = true, 4500);
await uploadPromise;
if (this.send.id == null) {
this.send.id = encSend[0].id;
@ -312,9 +310,17 @@ export class AddEditComponent implements OnInit {
this.send.accessId = encSend[0].accessId;
}
this.onSavedSend.emit(this.send);
await this.showSuccessMessage(inactive);
if (this.copyLink) {
this.copyLinkToClipboard(this.link);
if (this.copyLink && this.link != null) {
const copySuccess = await this.copyLinkToClipboard(this.link);
if (copySuccess ?? true) {
this.platformUtilsService.showToast('success', null,
this.i18nService.t(this.editMode ? 'editedSend' : 'createdSend'));
} else {
await this.platformUtilsService.showDialog(
this.i18nService.t(this.editMode ? 'editedSend' : 'createdSend'), null,
this.i18nService.t('ok'), null, 'success', null);
await this.copyLinkToClipboard(this.link);
}
}
});
@ -325,11 +331,6 @@ export class AddEditComponent implements OnInit {
return false;
}
async showSuccessMessage(inactive: boolean) {
this.platformUtilsService.showToast('success', null,
this.i18nService.t(this.editMode ? 'editedSend' : 'createdSend'));
}
clearExpiration() {
this.expirationDate = null;
this.expirationDateFallback = null;
@ -337,10 +338,8 @@ export class AddEditComponent implements OnInit {
this.safariExpirationTime = null;
}
copyLinkToClipboard(link: string) {
if (link != null) {
this.platformUtilsService.copyToClipboard(link);
}
async copyLinkToClipboard(link: string): Promise<void | boolean> {
return Promise.resolve(this.platformUtilsService.copyToClipboard(link));
}
async delete(): Promise<boolean> {