mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-25 01:05:15 +03:00
use standard Clipboard API when available
This commit is contained in:
parent
eb899ddf21
commit
4bb9d30d05
2 changed files with 33 additions and 7 deletions
|
@ -2259,6 +2259,9 @@
|
||||||
"cliCopyToClipboardBtn": {
|
"cliCopyToClipboardBtn": {
|
||||||
"message": "Copy to clipboard"
|
"message": "Copy to clipboard"
|
||||||
},
|
},
|
||||||
|
"cliCopySuccessful": {
|
||||||
|
"message": "Content has been copied to clipboard!"
|
||||||
|
},
|
||||||
|
|
||||||
"loggingNote": {
|
"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."
|
"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);
|
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) {
|
TABS.cli.initialize = function (callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
@ -108,13 +137,7 @@ TABS.cli.initialize = function (callback) {
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.tab-cli .copy').click(function() {
|
$('.tab-cli .copy').click(function() {
|
||||||
try {
|
copyToClipboard(self.outputHistory);
|
||||||
let gui = require('nw.gui'),
|
|
||||||
clipboard = gui.Clipboard.get();
|
|
||||||
clipboard.set(self.outputHistory, "text");
|
|
||||||
} catch (ex) {
|
|
||||||
console.warn(ex);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Tab key detection must be on keydown,
|
// Tab key detection must be on keydown,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue