actionbinder.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // Requirements
  2. const path = require('path')
  3. const ConfigManager = require(path.join(__dirname, 'assets', 'js', 'configmanager.js'))
  4. // Synchronous Listener
  5. document.addEventListener('readystatechange', function(){
  6. if (document.readyState === 'complete'){
  7. if(ConfigManager.isFirstLaunch()){
  8. $('#welcomeContainer').fadeIn(500)
  9. } else {
  10. $('#landingContainer').fadeIn(500)
  11. }
  12. }
  13. if (document.readyState === 'interactive'){
  14. }
  15. }, false)
  16. /* Overlay Wrapper Functions */
  17. /**
  18. * Toggle the visibility of the overlay.
  19. *
  20. * @param {boolean} toggleState True to display, false to hide.
  21. * @param {boolean} dismissable Optional. True to show the dismiss option, otherwise false.
  22. * @param {string} content Optional. The content div to be shown.
  23. */
  24. function toggleOverlay(toggleState, dismissable = false, content = 'overlayContent'){
  25. if(toggleState == null){
  26. toggleState = !document.getElementById('main').hasAttribute('overlay')
  27. }
  28. if(typeof dismissable === 'string'){
  29. content = dismissable
  30. }
  31. if(toggleState){
  32. document.getElementById('main').setAttribute('overlay', true)
  33. $('#' + content).parent().children().hide()
  34. $('#' + content).show()
  35. if(dismissable){
  36. $('#overlayDismiss').show()
  37. } else {
  38. $('#overlayDismiss').hide()
  39. }
  40. $('#overlayContainer').fadeIn(250)
  41. } else {
  42. document.getElementById('main').removeAttribute('overlay')
  43. $('#overlayContainer').fadeOut(250, () => {
  44. $('#' + content).parent().children().hide()
  45. $('#' + content).show()
  46. if(dismissable){
  47. $('#overlayDismiss').show()
  48. } else {
  49. $('#overlayDismiss').hide()
  50. }
  51. })
  52. }
  53. }
  54. /**
  55. * Set the content of the overlay.
  56. *
  57. * @param {string} title Overlay title text.
  58. * @param {string} description Overlay description text.
  59. * @param {string} acknowledge Acknowledge button text.
  60. * @param {string} dismiss Dismiss button text.
  61. */
  62. function setOverlayContent(title, description, acknowledge, dismiss = 'Dismiss'){
  63. document.getElementById('overlayTitle').innerHTML = title
  64. document.getElementById('overlayDesc').innerHTML = description
  65. document.getElementById('overlayAcknowledge').innerHTML = acknowledge
  66. document.getElementById('overlayDismiss').innerHTML = dismiss
  67. }
  68. /**
  69. * Set the onclick handler of the overlay acknowledge button.
  70. * If the handler is null, a default handler will be added.
  71. *
  72. * @param {function} handler
  73. */
  74. function setOverlayHandler(handler){
  75. if(handler == null){
  76. document.getElementById('overlayAcknowledge').onclick = () => {
  77. toggleOverlay(false)
  78. }
  79. } else {
  80. document.getElementById('overlayAcknowledge').onclick = handler
  81. }
  82. }
  83. /**
  84. * Set the onclick handler of the overlay dismiss button.
  85. * If the handler is null, a default handler will be added.
  86. *
  87. * @param {function} handler
  88. */
  89. function setDismissHandler(handler){
  90. if(handler == null){
  91. document.getElementById('overlayDismiss').onclick = () => {
  92. toggleOverlay(false)
  93. }
  94. } else {
  95. document.getElementById('overlayDismiss').onclick = handler
  96. }
  97. }
  98. /* Launch Progress Wrapper Functions */
  99. /**
  100. * Show/hide the loading area.
  101. *
  102. * @param {boolean} loading True if the loading area should be shown, otherwise false.
  103. */
  104. function toggleLaunchArea(loading){
  105. if(loading){
  106. launch_details.style.display = 'flex'
  107. launch_content.style.display = 'none'
  108. } else {
  109. launch_details.style.display = 'none'
  110. launch_content.style.display = 'inline-flex'
  111. }
  112. }
  113. /**
  114. * Set the details text of the loading area.
  115. *
  116. * @param {string} details The new text for the loading details.
  117. */
  118. function setLaunchDetails(details){
  119. launch_details_text.innerHTML = details
  120. }
  121. /**
  122. * Set the value of the loading progress bar and display that value.
  123. *
  124. * @param {number} value The progress value.
  125. * @param {number} max The total size.
  126. * @param {number|string} percent Optional. The percentage to display on the progress label.
  127. */
  128. function setLaunchPercentage(value, max, percent = ((value/max)*100)){
  129. launch_progress.setAttribute('max', max)
  130. launch_progress.setAttribute('value', value)
  131. launch_progress_label.innerHTML = percent + '%'
  132. }
  133. /**
  134. * Set the value of the OS progress bar and display that on the UI.
  135. *
  136. * @param {number} value The progress value.
  137. * @param {number} max The total download size.
  138. * @param {number|string} percent Optional. The percentage to display on the progress label.
  139. */
  140. function setDownloadPercentage(value, max, percent = ((value/max)*100)){
  141. remote.getCurrentWindow().setProgressBar(value/max)
  142. setLaunchPercentage(value, max, percent)
  143. }