uicore.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * Core UI functions are initialized in this file. This prevents
  3. * unexpected errors from breaking the core features. Specifically,
  4. * actions in this file should not require the usage of any internal
  5. * modules, excluding dependencies.
  6. */
  7. // Requirements
  8. const $ = require('jquery');
  9. const {remote, shell, webFrame} = require('electron')
  10. // Disable eval function.
  11. // eslint-disable-next-line
  12. window.eval = global.eval = function () {
  13. throw new Error('Sorry, this app does not support window.eval().')
  14. }
  15. // Display warning when devtools window is opened.
  16. remote.getCurrentWebContents().on('devtools-opened', () => {
  17. console.log('%cThe console is dark and full of terrors.', 'color: white; -webkit-text-stroke: 4px #a02d2a; font-size: 60px; font-weight: bold')
  18. console.log('%cIf you\'ve been told to paste something here, you\'re being scammed.', 'font-size: 16px')
  19. console.log('%cUnless you know exactly what you\'re doing, close this window.', 'font-size: 16px')
  20. })
  21. // Disable zoom, needed for darwin.
  22. webFrame.setZoomLevel(0)
  23. webFrame.setVisualZoomLevelLimits(1, 1)
  24. webFrame.setLayoutZoomLevelLimits(0, 0)
  25. /* jQuery Example
  26. $(function(){
  27. console.log('UICore Initialized');
  28. })*/
  29. document.addEventListener('readystatechange', function () {
  30. if (document.readyState === 'interactive'){
  31. console.log('UICore Initializing..');
  32. // Bind close button.
  33. Array.from(document.getElementsByClassName('fCb')).map((val) => {
  34. val.addEventListener('click', e => {
  35. const window = remote.getCurrentWindow()
  36. window.close()
  37. })
  38. })
  39. // Bind restore down button.
  40. Array.from(document.getElementsByClassName('fRb')).map((val) => {
  41. val.addEventListener('click', e => {
  42. const window = remote.getCurrentWindow()
  43. if(window.isMaximized()){
  44. window.unmaximize()
  45. } else {
  46. window.maximize()
  47. }
  48. document.activeElement.blur()
  49. })
  50. })
  51. // Bind minimize button.
  52. Array.from(document.getElementsByClassName('fMb')).map((val) => {
  53. val.addEventListener('click', e => {
  54. const window = remote.getCurrentWindow()
  55. window.minimize()
  56. document.activeElement.blur()
  57. })
  58. })
  59. } else if(document.readyState === 'complete'){
  60. //266.01
  61. //170.8
  62. //53.21
  63. // Bind progress bar length to length of bot wrapper
  64. //const targetWidth = document.getElementById("launch_content").getBoundingClientRect().width
  65. //const targetWidth2 = document.getElementById("server_selection").getBoundingClientRect().width
  66. //const targetWidth3 = document.getElementById("launch_button").getBoundingClientRect().width
  67. document.getElementById("launch_details").style.maxWidth = 266.01
  68. document.getElementById("launch_progress").style.width = 170.8
  69. document.getElementById("launch_details_right").style.maxWidth = 170.8
  70. document.getElementById("launch_progress_label").style.width = 53.21
  71. }
  72. }, false)
  73. /**
  74. * Open web links in the user's default browser.
  75. */
  76. $(document).on('click', 'a[href^="http"]', function(event) {
  77. event.preventDefault();
  78. //console.log(os.homedir())
  79. shell.openExternal(this.href)
  80. })
  81. /**
  82. * Opens DevTools window if you hold (ctrl + shift + i).
  83. * This will crash the program if you are using multiple
  84. * DevTools, for example the chrome debugger in VS Code.
  85. */
  86. document.addEventListener('keydown', function (e) {
  87. if(e.key === 'I' && e.ctrlKey && e.shiftKey){
  88. let window = remote.getCurrentWindow()
  89. window.toggleDevTools()
  90. }
  91. })