1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-24 16:55:24 +03:00

use standard Clipboard API when available

This commit is contained in:
Károly Kiripolszky 2018-11-21 11:23:28 +01:00
parent eb899ddf21
commit 4bb9d30d05
2 changed files with 33 additions and 7 deletions

View file

@ -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,