Fix clipboard for cordova to use existing hidden input

This commit is contained in:
Alex Shpak 2018-06-01 09:39:02 +02:00
parent bd33a72ddc
commit adeb58bd6b
3 changed files with 15 additions and 20 deletions

View File

@ -3,10 +3,10 @@ const Launcher = require('./launcher');
const AppSettingsModel = require('../models/app-settings-model');
const CopyPaste = {
simpleCopy: !!Launcher,
simpleCopy: !!(Launcher && Launcher.clipboardSupported),
copy: function(text) {
if (Launcher) {
if (this.simpleCopy) {
Launcher.setClipboardText(text);
const clipboardSeconds = AppSettingsModel.instance.get('clipboardSeconds');
if (clipboardSeconds > 0) {

View File

@ -5,8 +5,12 @@ const Launcher = {
version: '6.0.0',
autoTypeSupported: false,
thirdPartyStoragesSupported: false,
clipboardSupported: false,
ready: function(callback) {
document.addEventListener('deviceready', callback, false);
document.addEventListener('deviceready', () => {
navigator.splashscreen && navigator.splashscreen.hide();
callback();
}, false);
},
platform: function() {
return 'cordova';
@ -130,6 +134,7 @@ const Launcher = {
return null; // not in android with content provider
},
// ensureRunnable: function(path) { },
preventExit: function(e) {
e.returnValue = false;
return false;
@ -137,29 +142,17 @@ const Launcher = {
exit: function() {
this.hideApp();
},
requestExit: function() { /* skip in cordova */ },
requestRestart: function() {
window.location.reload();
},
cancelRestart: function() { /* skip in cordova */ },
setClipboardText: function(text) {
const detachedInput = document.createElement('textarea');
detachedInput.style.height = 0;
detachedInput.style.width = 0;
detachedInput.value = text;
document.body.appendChild(detachedInput);
detachedInput.select();
document.execCommand('copy');
document.body.removeChild(detachedInput);
},
getClipboardText: function() {
/* Used for clipboard cleaning
would not work in cordova */
},
clearClipboardText: function() {
this.setClipboardText('');
},
setClipboardText: function(text) {},
getClipboardText: function() {},
clearClipboardText: function() {},
minimizeApp: function() {
this.hideApp();
},
@ -172,6 +165,7 @@ const Launcher = {
updaterEnabled: function() {
return false;
},
// getMainWindow: function() { },
resolveProxy: function(url, callback) { /* skip in cordova */ },
openWindow: function(opts) { /* skip in cordova */ },

View File

@ -9,6 +9,7 @@ const Launcher = {
version: window.process.versions.electron,
autoTypeSupported: true,
thirdPartyStoragesSupported: true,
clipboardSupported: true,
req: window.require,
platform: function() {
return process.platform;