<template>
  <div></div>
</template>

<script>
export default {
  name: "DevTools",
  created() {
    if (typeof nodeRequire != "undefined") {
      // 按Ctrl+Shift+U，放开U，在一秒内再按Ctrl+Shift+P，可以调出开发者工具
      let firstStepKey = false;
      let secondStepKey = false;
      let psscode = [];
      this.listener = document.addEventListener("keydown", function(e) {
        // console.log(e.code);
        if (firstStepKey && secondStepKey) {
          // console.log(psscode);
          psscode.push(e.code[e.code.length - 1]);
          // console.log(psscode);
          if (
            psscode.join("").toLowerCase() ===
            window.QECSConfig.STUDENT_CLIENT_CONSOLE_CONFIG
          ) {
            window
              .nodeRequire("electron")
              .remote.getCurrentWindow()
              .toggleDevTools();
          }
        }
        if (e.ctrlKey && e.shiftKey && e.code === "KeyU") {
          firstStepKey = true;
          setTimeout(() => {
            firstStepKey = false;
            secondStepKey = false;
            psscode = [];
          }, 5000);
        }
        if (firstStepKey && e.ctrlKey && e.shiftKey && e.code === "KeyP") {
          secondStepKey = true;
        }
      });
    }
  },
  beforeDestroy() {
    if (this.listener) document.removeEventListener(this.listener);
  },
};
</script>
