main.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict'
  2. import { marshalActionButtonsJsonToHtml } from './js/marshaller.js'
  3. function showBigError (type, friendlyType, message) {
  4. clearInterval(window.buttonInterval)
  5. console.error('Error ' + type + ': ', message)
  6. const domErr = document.createElement('div')
  7. domErr.classList.add('error')
  8. domErr.innerHTML = '<h1>Error ' + friendlyType + '</h1><p>' + message + "</p><p><a href = 'http://docs.olivetin.app/troubleshooting.html' target = 'blank'/>OliveTin Documentation</a></p>"
  9. document.getElementById('rootGroup').appendChild(domErr)
  10. }
  11. function fetchGetButtons() {
  12. window.fetch(window.restBaseUrl + 'GetButtons', {
  13. cors: 'cors'
  14. // No fetch options
  15. }).then(res => {
  16. return res.json()
  17. }).then(res => {
  18. marshalActionButtonsJsonToHtml(res)
  19. }).catch(err => {
  20. showBigError('fetch-buttons', 'getting buttons', err, 'blat')
  21. })
  22. }
  23. function processWebuiSettingsJson (settings) {
  24. window.restBaseUrl = settings.Rest
  25. if (settings.ThemeName) {
  26. var themeCss = document.createElement('link')
  27. themeCss.setAttribute('rel', 'stylesheet');
  28. themeCss.setAttribute('type', 'text/css')
  29. themeCss.setAttribute('href', '/themes/' + settings.ThemeName + '/theme.css');
  30. document.head.appendChild(themeCss);
  31. }
  32. }
  33. window.fetch('webUiSettings.json').then(res => {
  34. return res.json()
  35. }).then(res => {
  36. processWebuiSettingsJson(res)
  37. fetchGetButtons()
  38. window.buttonInterval = setInterval(fetchGetButtons, 3000);
  39. }).catch(err => {
  40. showBigError('fetch-webui-settings', 'getting webui settings', err)
  41. })