uicore.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. // Disable zoom, needed for darwin.
  16. webFrame.setZoomLevel(0)
  17. webFrame.setVisualZoomLevelLimits(1, 1)
  18. webFrame.setLayoutZoomLevelLimits(0, 0)
  19. /* jQuery Example
  20. $(function(){
  21. console.log('UICore Initialized');
  22. })*/
  23. document.addEventListener('readystatechange', function () {
  24. if (document.readyState === 'interactive'){
  25. console.log('UICore Initializing..');
  26. // Bind close button.
  27. Array.from(document.getElementsByClassName('fCb')).map((val) => {
  28. val.addEventListener('click', e => {
  29. const window = remote.getCurrentWindow()
  30. window.close()
  31. })
  32. })
  33. // Bind restore down button.
  34. Array.from(document.getElementsByClassName('fRb')).map((val) => {
  35. val.addEventListener('click', e => {
  36. const window = remote.getCurrentWindow()
  37. if(window.isMaximized()){
  38. window.unmaximize()
  39. } else {
  40. window.maximize()
  41. }
  42. document.activeElement.blur()
  43. })
  44. })
  45. // Bind minimize button.
  46. Array.from(document.getElementsByClassName('fMb')).map((val) => {
  47. val.addEventListener('click', e => {
  48. const window = remote.getCurrentWindow()
  49. window.minimize()
  50. document.activeElement.blur()
  51. })
  52. })
  53. } else if(document.readyState === 'complete'){
  54. //266.01
  55. //170.8
  56. //53.21
  57. // Bind progress bar length to length of bot wrapper
  58. //const targetWidth = document.getElementById("launch_content").getBoundingClientRect().width
  59. //const targetWidth2 = document.getElementById("server_selection").getBoundingClientRect().width
  60. //const targetWidth3 = document.getElementById("launch_button").getBoundingClientRect().width
  61. document.getElementById("launch_details").style.maxWidth = 266.01
  62. document.getElementById("launch_progress").style.width = 170.8
  63. document.getElementById("launch_details_right").style.maxWidth = 170.8
  64. document.getElementById("launch_progress_label").style.width = 53.21
  65. }
  66. }, false)
  67. /**
  68. * Open web links in the user's default browser.
  69. */
  70. $(document).on('click', 'a[href^="http"]', function(event) {
  71. event.preventDefault();
  72. //console.log(os.homedir())
  73. shell.openExternal(this.href)
  74. })
  75. /**
  76. * Opens DevTools window if you hold (ctrl + shift + i).
  77. * This will crash the program if you are using multiple
  78. * DevTools, for example the chrome debugger in VS Code.
  79. */
  80. document.addEventListener('keydown', function (e) {
  81. if(e.keyCode == 73 && e.ctrlKey && e.shiftKey){
  82. let window = remote.getCurrentWindow()
  83. window.toggleDevTools()
  84. }
  85. })