mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-15 20:11:30 +01:00
Refactor Send 'copy link' functionality (#960)
* Refactor Send 'copy link' functionality * bump jslib * Print debug message if copyToClipboard fails * fix linting
This commit is contained in:
parent
97e1c7a2ea
commit
3ac2ce079a
2
jslib
2
jslib
@ -1 +1 @@
|
|||||||
Subproject commit a72c8a60c1b7a6980bceee456c53a9ea7b9b3451
|
Subproject commit 8244971026ffefb962e235a79c5cb219163bead9
|
@ -12,8 +12,6 @@ import { UserService } from 'jslib/abstractions/user.service';
|
|||||||
|
|
||||||
import { AddEditComponent as BaseAddEditComponent } from 'jslib/angular/components/send/add-edit.component';
|
import { AddEditComponent as BaseAddEditComponent } from 'jslib/angular/components/send/add-edit.component';
|
||||||
|
|
||||||
import { SendType } from 'jslib/enums/sendType';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-send-add-edit',
|
selector: 'app-send-add-edit',
|
||||||
templateUrl: 'add-edit.component.html',
|
templateUrl: 'add-edit.component.html',
|
||||||
@ -27,18 +25,11 @@ export class AddEditComponent extends BaseAddEditComponent {
|
|||||||
messagingService, policyService);
|
messagingService, policyService);
|
||||||
}
|
}
|
||||||
|
|
||||||
async showSuccessMessage(inactive: boolean) {
|
async copyLinkToClipboard(link: string): Promise<void | 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
|
// 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.
|
// of the modal closing we need to add a small delay to make sure state of the DOM is consistent.
|
||||||
window.setTimeout(() => super.copyLinkToClipboard(link), 500);
|
return new Promise(resolve => {
|
||||||
|
window.setTimeout(() => resolve(super.copyLinkToClipboard(link)), 500);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,12 +91,12 @@ const i18nService = new I18nService(window.navigator.language, 'locales');
|
|||||||
const stateService = new StateService();
|
const stateService = new StateService();
|
||||||
const broadcasterService = new BroadcasterService();
|
const broadcasterService = new BroadcasterService();
|
||||||
const messagingService = new BroadcasterMessagingService(broadcasterService);
|
const messagingService = new BroadcasterMessagingService(broadcasterService);
|
||||||
const platformUtilsService = new WebPlatformUtilsService(i18nService, messagingService);
|
const consoleLogService = new ConsoleLogService(false);
|
||||||
|
const platformUtilsService = new WebPlatformUtilsService(i18nService, messagingService, consoleLogService);
|
||||||
const storageService: StorageServiceAbstraction = new HtmlStorageService(platformUtilsService);
|
const storageService: StorageServiceAbstraction = new HtmlStorageService(platformUtilsService);
|
||||||
const secureStorageService: StorageServiceAbstraction = new MemoryStorageService();
|
const secureStorageService: StorageServiceAbstraction = new MemoryStorageService();
|
||||||
const cryptoFunctionService: CryptoFunctionServiceAbstraction = new WebCryptoFunctionService(window,
|
const cryptoFunctionService: CryptoFunctionServiceAbstraction = new WebCryptoFunctionService(window,
|
||||||
platformUtilsService);
|
platformUtilsService);
|
||||||
const consoleLogService = new ConsoleLogService(false);
|
|
||||||
const cryptoService = new CryptoService(storageService,
|
const cryptoService = new CryptoService(storageService,
|
||||||
platformUtilsService.isDev() ? storageService : secureStorageService, cryptoFunctionService, platformUtilsService,
|
platformUtilsService.isDev() ? storageService : secureStorageService, cryptoFunctionService, platformUtilsService,
|
||||||
consoleLogService);
|
consoleLogService);
|
||||||
|
@ -3,6 +3,7 @@ import Swal, { SweetAlertIcon } from 'sweetalert2';
|
|||||||
import { DeviceType } from 'jslib/enums/deviceType';
|
import { DeviceType } from 'jslib/enums/deviceType';
|
||||||
|
|
||||||
import { I18nService } from 'jslib/abstractions/i18n.service';
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||||
|
import { LogService } from 'jslib/abstractions/log.service';
|
||||||
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
||||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||||
|
|
||||||
@ -11,7 +12,8 @@ export class WebPlatformUtilsService implements PlatformUtilsService {
|
|||||||
|
|
||||||
private browserCache: DeviceType = null;
|
private browserCache: DeviceType = null;
|
||||||
|
|
||||||
constructor(private i18nService: I18nService, private messagingService: MessagingService) { }
|
constructor(private i18nService: I18nService, private messagingService: MessagingService,
|
||||||
|
private logService: LogService) { }
|
||||||
|
|
||||||
getDevice(): DeviceType {
|
getDevice(): DeviceType {
|
||||||
if (this.browserCache != null) {
|
if (this.browserCache != null) {
|
||||||
@ -245,7 +247,7 @@ export class WebPlatformUtilsService implements PlatformUtilsService {
|
|||||||
return process.env.SELF_HOST.toString() === 'true';
|
return process.env.SELF_HOST.toString() === 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
copyToClipboard(text: string, options?: any): void {
|
copyToClipboard(text: string, options?: any): void | boolean {
|
||||||
let win = window;
|
let win = window;
|
||||||
let doc = window.document;
|
let doc = window.document;
|
||||||
if (options && (options.window || options.win)) {
|
if (options && (options.window || options.win)) {
|
||||||
@ -269,11 +271,12 @@ export class WebPlatformUtilsService implements PlatformUtilsService {
|
|||||||
}
|
}
|
||||||
copyEl.appendChild(textarea);
|
copyEl.appendChild(textarea);
|
||||||
textarea.select();
|
textarea.select();
|
||||||
|
let success = false;
|
||||||
try {
|
try {
|
||||||
// Security exception may be thrown by some browsers.
|
// Security exception may be thrown by some browsers.
|
||||||
const copyEnabled = doc.execCommand('copy');
|
success = doc.execCommand('copy');
|
||||||
if (!copyEnabled) {
|
if (!success) {
|
||||||
throw new Error('Command unsupported or disabled');
|
this.logService.debug('Copy command unsupported or disabled.');
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// tslint:disable-next-line
|
// tslint:disable-next-line
|
||||||
@ -281,6 +284,7 @@ export class WebPlatformUtilsService implements PlatformUtilsService {
|
|||||||
} finally {
|
} finally {
|
||||||
copyEl.removeChild(textarea);
|
copyEl.removeChild(textarea);
|
||||||
}
|
}
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user