uicore.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.addEventListener('readystatechange', 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. } else if(document.readyState === 'complete'){
  34. // Bind progress bar length to length of bot wrapper
  35. const targetWidth = document.getElementById("launch_content").getBoundingClientRect().width
  36. const targetWidth2 = document.getElementById("server_selection").getBoundingClientRect().width
  37. const targetWidth3 = document.getElementById("launch_button").getBoundingClientRect().width
  38. document.getElementById("launch_details").style.maxWidth = targetWidth
  39. document.getElementById("launch_progress").style.width = targetWidth2
  40. document.getElementById("launch_details_right").style.maxWidth = targetWidth2
  41. document.getElementById("launch_progress_label").style.width = targetWidth3
  42. }
  43. }, false)
  44. /**
  45. * Open web links in the user's default browser.
  46. */
  47. $(document).on('click', 'a[href^="http"]', function(event) {
  48. event.preventDefault();
  49. //console.log(os.homedir())
  50. shell.openExternal(this.href)
  51. })
  52. /**
  53. * Opens DevTools window if you type "wcdev" in sequence.
  54. * This will crash the program if you are using multiple
  55. * DevTools, for example the chrome debugger in VS Code.
  56. */
  57. const match = [87, 67, 68, 69, 86]
  58. let at = 0;
  59. document.addEventListener('keydown', function (e) {
  60. switch(e.keyCode){
  61. case match[0]:
  62. if(at === 0) ++at
  63. break
  64. case match[1]:
  65. if(at === 1) ++at
  66. break
  67. case match[2]:
  68. if(at === 2) ++at
  69. break
  70. case match[3]:
  71. if(at === 3) ++at
  72. break
  73. case match[4]:
  74. if(at === 4) ++at
  75. break
  76. default:
  77. at = 0
  78. }
  79. if(at === 5) {
  80. var window = remote.getCurrentWindow()
  81. window.toggleDevTools()
  82. at = 0
  83. }
  84. })