uicore.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * Core UI functions are initialized in this file. This prevents
  3. * unexpected errors from breaking the core features.
  4. */
  5. const $ = require('jquery');
  6. const {remote, shell} = require('electron')
  7. /* jQuery Example
  8. $(function(){
  9. console.log('UICore Initialized');
  10. })*/
  11. document.onreadystatechange = function () {
  12. if (document.readyState === "interactive") {
  13. console.log('UICore Initializing..');
  14. // Bind close button.
  15. document.getElementById("frame_btn_close").addEventListener("click", function (e) {
  16. const window = remote.getCurrentWindow()
  17. window.close()
  18. })
  19. // Bind restore down button.
  20. document.getElementById("frame_btn_restoredown").addEventListener("click", function (e) {
  21. const window = remote.getCurrentWindow()
  22. if(window.isMaximized()){
  23. window.unmaximize();
  24. } else {
  25. window.maximize()
  26. }
  27. })
  28. // Bind minimize button.
  29. document.getElementById("frame_btn_minimize").addEventListener("click", function (e) {
  30. const window = remote.getCurrentWindow()
  31. window.minimize()
  32. })
  33. // Bind progress bar length to length of bot wrapper
  34. const targetWidth = document.getElementById("launch_content").getBoundingClientRect().width
  35. const targetWidth2 = document.getElementById("server_selection").getBoundingClientRect().width
  36. const targetWidth3 = document.getElementById("launch_button").getBoundingClientRect().width
  37. document.getElementById("launch_details").style.maxWidth = targetWidth
  38. document.getElementById("launch_progress").style.width = targetWidth2
  39. document.getElementById("launch_details_right").style.maxWidth = targetWidth2
  40. document.getElementById("launch_progress_label").style.width = targetWidth3
  41. }
  42. }
  43. /**
  44. * Open web links in the user's default browser.
  45. */
  46. $(document).on('click', 'a[href^="http"]', function(event) {
  47. event.preventDefault();
  48. //console.log(os.homedir())
  49. shell.openExternal(this.href)
  50. })
  51. /**
  52. * Opens DevTools window if you type "wcdev" in sequence.
  53. * This will crash the program if you are using multiple
  54. * DevTools, for example the chrome debugger in VS Code.
  55. */
  56. const match = [87, 67, 68, 69, 86]
  57. let at = 0;
  58. document.addEventListener('keydown', function (e) {
  59. switch(e.keyCode){
  60. case match[0]:
  61. if(at === 0) ++at
  62. break
  63. case match[1]:
  64. if(at === 1) ++at
  65. break
  66. case match[2]:
  67. if(at === 2) ++at
  68. break
  69. case match[3]:
  70. if(at === 3) ++at
  71. break
  72. case match[4]:
  73. if(at === 4) ++at
  74. break
  75. default:
  76. at = 0
  77. }
  78. if(at === 5) {
  79. var window = remote.getCurrentWindow()
  80. window.toggleDevTools()
  81. at = 0
  82. }
  83. })