uicore.js 3.1 KB

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