diff options
author | Maximilian Krambach <[email protected]> | 2018-04-24 16:44:30 +0000 |
---|---|---|
committer | Maximilian Krambach <[email protected]> | 2018-04-24 16:44:30 +0000 |
commit | 461dd0c8b41683a91073b362d100ee5217ec53f6 (patch) | |
tree | 15ab814b70a583db52f7f9e664aaa016057d98d0 /lang/js/testapplication.js | |
parent | js: don't allow message operation changes (diff) | |
download | gpgme-461dd0c8b41683a91073b362d100ee5217ec53f6.tar.gz gpgme-461dd0c8b41683a91073b362d100ee5217ec53f6.zip |
js: change in initialization ancd connection handling
--
* The Connection will now be started before an object is created, to
better account for failures.
* index.js: now exposes an init(), which returns a Promise of
configurable <GpgME | gpgmeGpgME_openPGPCompatibility> with an
established connection.
* TODO: There is currently no way to recover from a "connection lost"
* Connection.js offers Connection.isConnected, which toggles on port
closing.
Diffstat (limited to '')
-rw-r--r-- | lang/js/testapplication.js | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/lang/js/testapplication.js b/lang/js/testapplication.js index 97b35527..f47299e8 100644 --- a/lang/js/testapplication.js +++ b/lang/js/testapplication.js @@ -19,39 +19,37 @@ * */ -function encryptbuttonclicked(event){ - let data = document.getElementById('cleartext').value; - let keyId = document.getElementById('pubkey').value; - let communication = new Gpgmejs; - let enc = communication.encrypt(data, keyId).then( - function(answer){ - console.log(answer); - if (answer.data){ - console.log(answer.data); - document.getElementById('answer').value = answer.data; - } - }, function(errormsg){ - alert('Error: '+ errormsg); - }); -}; - -function decryptbuttonclicked(event){ - let data = document.getElementById("ciphertext").value; - let communication = new Gpgmejs; - let enc = communication.decrypt(data).then( - function(answer){ - console.log(answer); - if (answer.data){ - document.getElementById('answer').value = answer.data; - } - }, function(errormsg){ - alert('Error: '+ errormsg); - }); -}; - document.addEventListener('DOMContentLoaded', function() { - document.getElementById("buttonencrypt").addEventListener("click", - encryptbuttonclicked); - document.getElementById("buttondecrypt").addEventListener("click", - decryptbuttonclicked); + Gpgmejs.init().then(function(gpgmejs){ + document.getElementById("buttonencrypt").addEventListener("click", + function(){ + let data = document.getElementById('cleartext').value; + let keyId = document.getElementById('pubkey').value; + gpgmejs.encrypt(data, keyId).then( + function(answer){ + console.log(answer); + if (answer.data){ + console.log(answer.data); + document.getElementById('answer').value = answer.data; + } + }, function(errormsg){ + alert('Error: '+ errormsg); + }); + }); + + document.getElementById("buttondecrypt").addEventListener("click", + function(){ + let data = document.getElementById("ciphertext").value; + gpgmejs.decrypt(data).then( + function(answer){ + console.log(answer); + if (answer.data){ + document.getElementById('answer').value = answer.data; + } + }, function(errormsg){ + alert('Error: '+ errormsg); + }); + }); + }, + function(error){console.log(error)}); }); |