1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-07-05 12:04:45 +02:00

copy totp to clipboard from popup document in ff

This commit is contained in:
Kyle Spearrin 2017-09-22 15:31:31 -04:00
parent 5089cbded6
commit eace0f32f0
3 changed files with 15 additions and 9 deletions

View File

@ -72,8 +72,11 @@ angular
toastr.error(i18nService.autofillError);
}
autofillService.doAutoFill(login, pageDetails, false).then(function () {
autofillService.doAutoFill(login, pageDetails, false).then(function (totpCode) {
$analytics.eventTrack('Autofilled');
if (totpCode && utilsService.isFirefox()) {
utilsService.copyToClipboard(totpCode, document);
}
$window.close();
}, function () {
$analytics.eventTrack('Autofilled Error');

View File

@ -260,13 +260,15 @@ function initAutofill() {
if (code) {
self.utilsService.copyToClipboard(code);
}
return code;
});
}
if (didAutofill) {
if (totpPromise) {
totpPromise.then(function () {
deferred.resolve();
totpPromise.then(function (totpCode) {
deferred.resolve(totpCode);
});
}
else {

View File

@ -200,29 +200,30 @@ function initUtilsService() {
return null;
};
UtilsService.prototype.copyToClipboard = function (text) {
UtilsService.prototype.copyToClipboard = function (text, doc) {
doc = doc || document;
if (window.clipboardData && window.clipboardData.setData) {
// IE specific code path to prevent textarea being shown while dialog is visible.
return clipboardData.setData('Text', text);
}
else if (document.queryCommandSupported && document.queryCommandSupported('copy')) {
var textarea = document.createElement('textarea');
else if (doc.queryCommandSupported && doc.queryCommandSupported('copy')) {
var textarea = doc.createElement('textarea');
textarea.textContent = text;
// Prevent scrolling to bottom of page in MS Edge.
textarea.style.position = 'fixed';
document.body.appendChild(textarea);
doc.body.appendChild(textarea);
textarea.select();
try {
// Security exception may be thrown by some browsers.
return document.execCommand('copy');
return doc.execCommand('copy');
}
catch (ex) {
console.warn('Copy to clipboard failed.', ex);
return false;
}
finally {
document.body.removeChild(textarea);
doc.body.removeChild(textarea);
}
}
};