From b3a4f833a1fd72c7dad97b9a4e372552c1d0cea8 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Wed, 28 Apr 2021 07:40:36 +1000 Subject: [PATCH] Fix "copy link to clipboard" for large file Sends (#949) * Throw error if execCommand('copy') is disabled * Use dialog for file Send creation success * Show popup modal after long Send file uploads * fix linting * bump jslib --- jslib | 2 +- src/app/send/add-edit.component.ts | 11 +++++++++++ src/services/webPlatformUtils.service.ts | 5 ++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/jslib b/jslib index 5b751d38a0..4eb50d757d 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 5b751d38a00ef529e801a63547fb214c31962761 +Subproject commit 4eb50d757d03343ee842ea68a6b2c8282ef3f382 diff --git a/src/app/send/add-edit.component.ts b/src/app/send/add-edit.component.ts index 5a4bf99030..9a13d77e08 100644 --- a/src/app/send/add-edit.component.ts +++ b/src/app/send/add-edit.component.ts @@ -12,6 +12,8 @@ import { UserService } from 'jslib/abstractions/user.service'; import { AddEditComponent as BaseAddEditComponent } from 'jslib/angular/components/send/add-edit.component'; +import { SendType } from 'jslib/enums/sendType'; + @Component({ selector: 'app-send-add-edit', templateUrl: 'add-edit.component.html', @@ -25,6 +27,15 @@ export class AddEditComponent extends BaseAddEditComponent { messagingService, policyService); } + async showSuccessMessage(inactive: boolean) { + if (inactive && this.copyLink && this.send.type === SendType.File) { + await this.platformUtilsService.showDialog(this.i18nService.t('createdSend'), null, + this.i18nService.t('ok'), null, 'success', null); + } else { + await super.showSuccessMessage(inactive); + } + } + copyLinkToClipboard(link: string) { // Copy function on web depends on the modal being open or not. Since this event occurs during a transition // of the modal closing we need to add a small delay to make sure state of the DOM is consistent. diff --git a/src/services/webPlatformUtils.service.ts b/src/services/webPlatformUtils.service.ts index 0a443ed397..ae1dbf8a3e 100644 --- a/src/services/webPlatformUtils.service.ts +++ b/src/services/webPlatformUtils.service.ts @@ -245,7 +245,10 @@ export class WebPlatformUtilsService implements PlatformUtilsService { textarea.select(); try { // Security exception may be thrown by some browsers. - doc.execCommand('copy'); + const copyEnabled = doc.execCommand('copy'); + if (!copyEnabled) { + throw new Error('Command unsupported or disabled'); + } } catch (e) { // tslint:disable-next-line console.warn('Copy to clipboard failed.', e);