Wallet/src/js/services/clipboardService.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-06-28 10:52:06 +02:00
'use strict';
2018-07-19 17:13:19 +02:00
angular.module('copayApp.services').factory('clipboardService', function ($http, $log, $timeout, platformInfo, nodeWebkitService, gettextCatalog, ionicToast, clipboard) {
2018-06-28 10:52:06 +02:00
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 (navigator && navigator.clipboard) {
$log.debug("Use navigator clipboard.")
2018-08-09 11:42:25 +12:00
navigator.clipboard.writeText(data).catch(function onClipboardError(err) {
$log.debug("Clipboard writing is not supported in your browser..");
});
2018-06-28 10:52:06 +02:00
} else if (clipboard.supported) {
clipboard.copyText(data);
} else {
// Not supported
2018-06-28 10:52:06 +02:00
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) {
2018-07-19 17:11:24 +02:00
$timeout(function() {
cb(nodeWebkitService.readFromClipboard());
},0);
2018-07-09 18:22:11 +02:00
} else {
navigator.clipboard.readText()
2018-07-17 18:37:46 +09:00
.then(function (text) {
2018-07-09 18:22:11 +02:00
cb(text);
})
2018-07-17 18:37:46 +09:00
.catch(function (err) {
2018-07-09 18:22:11 +02:00
$log.debug("Clipboard reading is not supported in browser..");
});
return;
}
2018-06-28 10:52:06 +02:00
};
return root;
});