fix issues with clipboard clear

This commit is contained in:
Antelle 2016-01-22 20:51:36 +03:00
parent 6b301d8040
commit d8e3b67d0a
6 changed files with 39 additions and 31 deletions

View File

@ -5,14 +5,28 @@ var FeatureDetector = require('../util/feature-detector'),
AppSettingsModel = require('../models/app-settings-model');
var CopyPaste = {
tryCopy: function() {
try {
var success = document.execCommand('copy');
if (success) {
this.copied();
simpleCopy: !!Launcher,
copy: function(text) {
if (Launcher) {
Launcher.setClipboardText(text);
var clipboardSeconds = AppSettingsModel.instance.get('clipboardSeconds');
if (clipboardSeconds > 0) {
setTimeout(function () {
console.log('compare', Launcher.getClipboardText(), text);
if (Launcher.getClipboardText() === text) {
console.log('cleared clipboard');
Launcher.clearClipboardText();
}
}, clipboardSeconds * 1000);
}
return success;
} catch (e) {
return {success: true, seconds: clipboardSeconds};
} else {
try {
if (document.execCommand('copy')) {
return {success: true};
}
} catch (e) { }
return false;
}
},
@ -37,22 +51,6 @@ var CopyPaste = {
'copy cut paste': function() { setTimeout(function() { hiddenInput.blur(); }, 0); },
blur: function() { hiddenInput.remove(); }
});
},
copied: function() {
if (Launcher) {
var clipboardSeconds = AppSettingsModel.instance.get('clipboardSeconds');
if (clipboardSeconds > 0) {
setTimeout(function() {
setTimeout((function (prevText) {
if (Launcher.getClipboardText() === prevText) {
Launcher.clearClipboardText();
}
}).bind(null, Launcher.getClipboardText()), clipboardSeconds * 1000);
}, 0);
}
return clipboardSeconds;
}
}
};

View File

@ -76,6 +76,9 @@ if (window.process && window.process.versions && window.process.versions.electro
cancelRestart: function() {
this.restartPending = false;
},
setClipboardText: function(text) {
return this.req('clipboard').writeText(text);
},
getClipboardText: function() {
return this.req('clipboard').readText();
},

View File

@ -272,10 +272,13 @@ var DetailsView = Backbone.View.extend({
if (!window.getSelection().toString()) {
var pw = this.model.password;
var password = pw.isProtected ? pw.getText() : pw;
CopyPaste.createHiddenInput(password);
var clipboardTime = CopyPaste.copied();
if (!this.passCopyTip) {
if (!CopyPaste.simpleCopy) {
CopyPaste.createHiddenInput(password);
}
var copyRes = CopyPaste.copy(password);
if (copyRes && !this.passCopyTip) {
var passLabel = this.passEditView.labelEl;
var clipboardTime = copyRes.seconds;
var msg = clipboardTime ? Locale.detPassCopiedTime.replace('{}', clipboardTime)
: Locale.detPassCopied;
var tip = new Tip(passLabel, { title: msg, placement: 'right', fast: true });

View File

@ -41,14 +41,17 @@ var FieldView = Backbone.View.extend({
return;
}
CopyPaste.createHiddenInput(textValue, box);
//CopyPaste.tryCopy(); // maybe Apple will ever support this?
//CopyPaste.copy(); // maybe Apple will ever support this?
return;
}
if (field) {
var value = this.value || '';
if (value && value.isProtected) {
CopyPaste.createHiddenInput(value.getText());
CopyPaste.tryCopy();
var text = value.getText();
if (!CopyPaste.simpleCopy) {
CopyPaste.createHiddenInput(text);
}
CopyPaste.copy(text);
return;
}
}
@ -57,7 +60,7 @@ var FieldView = Backbone.View.extend({
range.selectNodeContents(this.valueEl[0]);
selection.removeAllRanges();
selection.addRange(range);
if (CopyPaste.tryCopy()) {
if (CopyPaste.copy(this.valueEl.text())) {
selection.removeAllRanges();
}
},

View File

@ -74,7 +74,7 @@ var GeneratorView = Backbone.View.extend({
range.selectNodeContents(this.resultEl[0]);
selection.removeAllRanges();
selection.addRange(range);
CopyPaste.tryCopy();
CopyPaste.copy(this.password);
this.trigger('result', this.password);
this.remove();
}

View File

@ -3,6 +3,7 @@ Release notes
##### v0.6.0 (not released yet)
Performance, stability and quality improvements
`-` #80: prevent data loss on group move
`-` issues with clipboard clear fixed
##### v0.6.0 (2016-01-19)
Improvements