Wallet/src/js/services/clipboardService.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-06-28 10:52:06 +02:00
'use strict';
angular.module('copayApp.services').factory('clipboardService', function ($http, $log, platformInfo, nodeWebkitService, gettextCatalog, ionicToast, clipboard) {
var root = {};
root.copyToClipboard = function (data) {
2018-06-28 10:52:06 +02:00
if (!data) return;
$log.debug("Copy '"+data+"' to clipboard");
2018-06-28 10:52:06 +02:00
if (platformInfo.isCordova) {
cordova.plugins.clipboard.copy(data);
} else if (platformInfo.isNW) {
nodeWebkitService.writeToClipboard(data);
} else if (clipboard.supported) {
clipboard.copyText(data);
} else {
// No supported
return;
}
2018-07-09 18:22:11 +02:00
};
2018-06-28 10:52:06 +02:00
2018-07-09 18:22:11 +02:00
root.readFromClipboard = function (cb) {
$log.debug("Read from clipboard");
if (platformInfo.isCordova) {
cordova.plugins.clipboard.paste(function(text) {
cb(text);
})
} else if (platformInfo.isNW) {
cb(nodeWebkitService.readFromClipboard());
} else {
navigator.clipboard.readText()
.then(text => {
cb(text);
})
.catch(err => {
$log.debug("Clipboard reading is not supported in browser..");
});
return;
}
2018-06-28 10:52:06 +02:00
};
return root;
});