index.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>Tauri</title>
  8. </head>
  9. <body>
  10. <h3>Counter</h3>
  11. <div>
  12. <button id="increment-btn">Increment counter</button>
  13. </div>
  14. <h3>Database</h3>
  15. <div>
  16. <input id="store-input" placeholder="The value to store">
  17. <button id="store-btn">Store</button>
  18. </div>
  19. <div>
  20. <button id="read-btn">Read</button>
  21. </div>
  22. <div id="response"></div>
  23. <script>
  24. const KEY = 'db-key'
  25. const storeBtn = document.querySelector('#store-btn')
  26. const readBtn = document.querySelector('#read-btn')
  27. const incrementBtn = document.querySelector('#increment-btn')
  28. const storeInput = document.querySelector('#store-input')
  29. const responseContainer = document.querySelector('#response')
  30. function updateResponse(response) {
  31. responseContainer.innerHTML = typeof response === "string" ? response : JSON.stringify(response)
  32. }
  33. incrementBtn.addEventListener('click', () => {
  34. window.__TAURI__.invoke('increment_counter').then(updateResponse).catch(updateResponse)
  35. })
  36. storeBtn.addEventListener('click', () => {
  37. window.__TAURI__.invoke('db_insert', {
  38. key: KEY,
  39. value: storeInput.value
  40. }).then(updateResponse).catch(updateResponse)
  41. })
  42. readBtn.addEventListener('click', () => {
  43. window.__TAURI__.invoke('db_read', {
  44. key: KEY
  45. }).then(updateResponse).catch(updateResponse)
  46. })
  47. </script>
  48. </body>
  49. </html>