uibinder.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * Initialize UI functions which depend on internal modules.
  3. * Loaded after core UI functions are initialized in uicore.js.
  4. */
  5. // Requirements
  6. const path = require('path')
  7. const ConfigManager = require('./assets/js/configmanager.js')
  8. let rscShouldLoad = false
  9. let fatalStartupError = false
  10. function showMainUI(){
  11. updateSelectedServer(AssetGuard.getServerById(ConfigManager.getLauncherDirectory(), ConfigManager.getSelectedServer()).name)
  12. refreshServerStatus()
  13. setTimeout(() => {
  14. document.getElementById('frameBar').style.backgroundColor = 'rgba(1, 2, 1, 0.5)'
  15. document.body.style.backgroundImage = `url('assets/images/backgrounds/${document.body.getAttribute('bkid')}.jpg')`
  16. $('#main').show()
  17. if(ConfigManager.isFirstLaunch()){
  18. $('#welcomeContainer').fadeIn(1000)
  19. } else {
  20. $('#landingContainer').fadeIn(1000)
  21. }
  22. setTimeout(() => {
  23. $('#loadingContainer').fadeOut(750, () => {
  24. $('#loadSpinnerImage').removeClass('rotating')
  25. })
  26. }, 500)
  27. }, 750)
  28. initNews()
  29. }
  30. function showFatalStartupError(){
  31. setTimeout(() => {
  32. $('#loadingContainer').fadeOut(250, () => {
  33. document.getElementById('overlayContainer').style.background = 'none'
  34. setOverlayContent(
  35. 'Fatal Error: Unable to Load Distribution Index',
  36. 'A connection could not be established to our servers to download the distribution index. No local copies were available to load. <br><br>The distribution index is an essential file which provides the latest server information. The launcher is unable to start without it. Ensure you are connected to the internet and relaunch the application.',
  37. 'Close'
  38. )
  39. setOverlayHandler(() => {
  40. const window = remote.getCurrentWindow()
  41. window.close()
  42. })
  43. toggleOverlay(true)
  44. })
  45. }, 750)
  46. }
  47. // Synchronous Listener
  48. document.addEventListener('readystatechange', function(){
  49. if (document.readyState === 'complete'){
  50. if(rscShouldLoad){
  51. if(!fatalStartupError){
  52. showMainUI()
  53. } else {
  54. showFatalStartupError()
  55. }
  56. }
  57. } else if(document.readyState === 'interactive'){
  58. //toggleOverlay(true, 'loadingContent')
  59. }
  60. /*if (document.readyState === 'interactive'){
  61. }*/
  62. }, false)
  63. // Actions that must be performed after the distribution index is downloaded.
  64. ipcRenderer.on('distributionIndexDone', (event, data) => {
  65. if(data != null) {
  66. if(document.readyState === 'complete'){
  67. showMainUI()
  68. } else {
  69. rscShouldLoad = true
  70. }
  71. } else {
  72. fatalStartupError = true
  73. if(document.readyState === 'complete'){
  74. showFatalStartupError()
  75. } else {
  76. rscShouldLoad = true
  77. }
  78. }
  79. })