use standard Clipboard API when available
parent
eb899ddf21
commit
4bb9d30d05
|
@ -2259,6 +2259,9 @@
|
|||
"cliCopyToClipboardBtn": {
|
||||
"message": "Copy to clipboard"
|
||||
},
|
||||
"cliCopySuccessful": {
|
||||
"message": "Content has been copied to clipboard!"
|
||||
},
|
||||
|
||||
"loggingNote": {
|
||||
"message": "Data will be logged in this tab <span class=\"message-negative\">only</span>, leaving the tab will <span class=\"message-negative\">cancel</span> logging and application will return to its normal <strong>\"configurator\"</strong> state.<br /> You are free to select the global update period, data will be written into the log file every <strong>1</strong> second for performance reasons."
|
||||
|
|
|
@ -41,6 +41,35 @@ function getCliCommand(command, cliBuffer) {
|
|||
return commandWithBackSpaces(command, buffer, noOfCharsToDelete);
|
||||
}
|
||||
|
||||
function copyToClipboard(text) {
|
||||
function onCopySuccessful() {
|
||||
writeLineToOutput("* " + i18n.getMessage("cliCopySuccessful"));
|
||||
}
|
||||
|
||||
function onCopyFailed(ex) {
|
||||
console.warn(ex);
|
||||
}
|
||||
|
||||
function nwCopy(text) {
|
||||
try {
|
||||
let gui = require('nw.gui'),
|
||||
clipboard = gui.Clipboard.get();
|
||||
clipboard.set(text, "text");
|
||||
onCopySuccessful();
|
||||
} catch (ex) {
|
||||
onCopyFailed(ex);
|
||||
}
|
||||
}
|
||||
|
||||
function webCopy(text) {
|
||||
navigator.clipboard.writeText(text)
|
||||
.then(onCopySuccessful, onCopyFailed);
|
||||
}
|
||||
|
||||
let copyFunc = !navigator.clipboard ? nwCopy : webCopy;
|
||||
copyFunc(text);
|
||||
}
|
||||
|
||||
TABS.cli.initialize = function (callback) {
|
||||
var self = this;
|
||||
|
||||
|
@ -108,13 +137,7 @@ TABS.cli.initialize = function (callback) {
|
|||
});
|
||||
|
||||
$('.tab-cli .copy').click(function() {
|
||||
try {
|
||||
let gui = require('nw.gui'),
|
||||
clipboard = gui.Clipboard.get();
|
||||
clipboard.set(self.outputHistory, "text");
|
||||
} catch (ex) {
|
||||
console.warn(ex);
|
||||
}
|
||||
copyToClipboard(self.outputHistory);
|
||||
});
|
||||
|
||||
// Tab key detection must be on keydown,
|
||||
|
|
Loading…
Reference in New Issue