fix #30: clear clipboard password after timeout

This commit is contained in:
Antelle 2015-11-16 23:36:07 +03:00
parent 94fd93ab9d
commit 9111d396cd
9 changed files with 58 additions and 6 deletions

View File

@ -1,11 +1,17 @@
'use strict';
var FeatureDetector = require('./feature-detector');
var FeatureDetector = require('../util/feature-detector'),
Launcher = require('./launcher'),
AppSettingsModel = require('../models/app-settings-model');
var CopyPaste = {
tryCopy: function() {
try {
return document.execCommand('copy');
var success = document.execCommand('copy');
if (success) {
this.copied();
}
return success;
} catch (e) {
return false;
}
@ -31,6 +37,21 @@ 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);
}
}
}
};

View File

@ -71,6 +71,12 @@ if (window.process && window.process.versions && window.process.versions.electro
},
cancelRestart: function() {
this.restartPending = false;
},
getClipboardText: function() {
return this.req('clipboard').readText();
},
clearClipboardText: function() {
return this.req('clipboard').clear();
}
};
window.launcherOpen = function(path) {

View File

@ -12,7 +12,8 @@ var AppSettingsModel = Backbone.Model.extend({
listViewWidth: null,
menuViewWidth: null,
tagsViewHeight: null,
autoUpdate: 'install'
autoUpdate: 'install',
clipboradSeconds: 0
},
initialize: function() {

View File

@ -16,7 +16,7 @@ var Backbone = require('backbone'),
Keys = require('../../const/keys'),
KeyHandler = require('../../comp/key-handler'),
Alerts = require('../../comp/alerts'),
CopyPaste = require('../../util/copy-paste'),
CopyPaste = require('../../comp/copy-paste'),
Format = require('../../util/format'),
FileSaver = require('filesaver'),
baron = require('baron'),
@ -256,6 +256,7 @@ var DetailsView = Backbone.View.extend({
var pw = this.model.password;
var password = pw.getText ? pw.getText() : pw;
CopyPaste.createHiddenInput(password);
CopyPaste.copied();
}
},

View File

@ -2,7 +2,7 @@
var Backbone = require('backbone'),
FeatureDetector = require('../../util/feature-detector'),
CopyPaste = require('../../util/copy-paste');
CopyPaste = require('../../comp/copy-paste');
var FieldView = Backbone.View.extend({
template: require('templates/details/field.html'),

View File

@ -2,7 +2,7 @@
var Backbone = require('backbone'),
PasswordGenerator = require('../util/password-generator'),
CopyPaste = require('../util/copy-paste');
CopyPaste = require('../comp/copy-paste');
var DefaultGenOpts = {
length: 16, upper: true, lower: true, digits: true, special: false, brackets: false, high: false, ambiguous: false

View File

@ -16,6 +16,7 @@ var SettingsGeneralView = Backbone.View.extend({
'change .settings__general-theme': 'changeTheme',
'change .settings__general-expand': 'changeExpandGroups',
'change .settings__general-auto-update': 'changeAutoUpdate',
'change .settings__general-clipboard': 'changeClipboard',
'click .settings__general-update-btn': 'checkUpdate',
'click .settings__general-restart-btn': 'restartApp',
'click .settings__general-download-update-btn': 'downloadUpdate',
@ -39,6 +40,8 @@ var SettingsGeneralView = Backbone.View.extend({
themes: this.allThemes,
activeTheme: AppSettingsModel.instance.get('theme'),
expandGroups: AppSettingsModel.instance.get('expandGroups'),
canClearClipboard: !!Launcher,
clipboardSeconds: AppSettingsModel.instance.get('clipboardSeconds'),
devTools: Launcher && Launcher.devTools,
canAutoUpdate: !!Launcher,
autoUpdate: Updater.getAutoUpdateType(),
@ -92,6 +95,11 @@ var SettingsGeneralView = Backbone.View.extend({
AppSettingsModel.instance.set('theme', theme);
},
changeClipboard: function(e) {
var clipboardSeconds = +e.target.value;
AppSettingsModel.instance.set('clipboardSeconds', clipboardSeconds);
},
changeAutoUpdate: function(e) {
var autoUpdate = e.target.value || false;
AppSettingsModel.instance.set('autoUpdate', autoUpdate);

View File

@ -51,6 +51,20 @@
<label for="settings__general-expand">Show entries from all subgroups</label>
</div>
<% if (canClearClipboard) { %>
<h2>Function</h2>
<div>
<label for="settings__general-clipboard">Clear clipboard after copy:</label>
<select class="settings__general-clipboard settings__select input-base" id="settings__general-clipboard">
<option value="0" <%= clipboardSeconds ? '' : 'selected' %>>Don't clear</option>
<option value="5" <%= clipboardSeconds === 5 ? 'selected' : '' %>>In 5 seconds</option>
<option value="10" <%= clipboardSeconds === 10 ? 'selected' : '' %>>In 10 seconds</option>
<option value="15" <%= clipboardSeconds === 15 ? 'selected' : '' %>>In 15 seconds</option>
<option value="60" <%= clipboardSeconds === 60 ? 'selected' : '' %>>In a minute</option>
</select>
</div>
<% } %>
<% if (devTools) { %>
<h2>Advanced</h2>
<a class="settings__general-dev-tools-link">Show dev tools</a>

View File

@ -6,6 +6,7 @@ Bugfixes
`+` desktop Dropbox
`+` Dropbox notification in self-hosted apps
`+` option to check updates without install
`+` clear clipboard password after timeout
##### v0.3.0 (2015-11-14)
Auto-update