index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. let Fs = require('fs');
  2. Editor.Panel.extend({
  3. style: Fs.readFileSync(Editor.url('packages://ccc-obfuscated-code/panel/index.css'), 'utf8'),
  4. template: Fs.readFileSync(Editor.url('packages://ccc-obfuscated-code/panel/index.html'), 'utf8'),
  5. ready() {
  6. let vue = new window.Vue({
  7. el: this.shadowRoot,
  8. data() {
  9. return {
  10. isSaving: false,
  11. auto: false,
  12. files: '/src/project.js',
  13. useAbsPath: false,
  14. preset: 'low',
  15. options: {
  16. compact: true,
  17. controlFlowFlattening: false,
  18. controlFlowFlatteningThreshold: 0.75,
  19. deadCodeInjection: false,
  20. deadCodeInjectionThreshold: 0.4,
  21. debugProtection: false,
  22. debugProtectionInterval: false,
  23. disableConsoleOutput: false,
  24. domainLock: '',
  25. identifierNamesGenerator: 'hexadecimal',
  26. identifiersDictionary: '',
  27. identifiersPrefix: '',
  28. inputFileName: '',
  29. log: false,
  30. renameGlobals: false,
  31. reservedNames: '',
  32. reservedStrings: '',
  33. rotateStringArray: false,
  34. seed: 0,
  35. selfDefending: false,
  36. shuffleStringArray: false,
  37. sourceMap: false,
  38. sourceMapBaseUrl: '',
  39. sourceMapFileName: '',
  40. sourceMapMode: 'separate',
  41. splitStrings: false,
  42. splitStringsChunkLength: 10,
  43. stringArray: false,
  44. stringArrayEncoding: false,
  45. stringArrayThreshold: 0.8,
  46. target: 'browser',
  47. transformObjectKeys: false,
  48. unicodeEscapeSequence: false
  49. }
  50. }
  51. },
  52. watch: {
  53. options: {
  54. handler(value) {
  55. if (value.deadCodeInjection) vue.options.stringArray = true;
  56. },
  57. deep: true
  58. }
  59. },
  60. methods: {
  61. /**
  62. * 保存配置
  63. */
  64. saveConfig() {
  65. if (this.isSaving) return;
  66. this.isSaving = true;
  67. let config = {
  68. auto: this.auto,
  69. files: this.files.split(','),
  70. useAbsPath: this.useAbsPath,
  71. preset: this.preset,
  72. options: {}
  73. };
  74. for (let key in this.options) {
  75. switch (key) {
  76. case 'domainLock': case 'identifiersDictionary': case 'reservedNames': case 'reservedStrings':
  77. config.options[key] = this.options[key] == '' ? [] : this.options[key].split(',');
  78. break;
  79. case 'stringArrayEncoding':
  80. config.options[key] = this.options.stringArrayEncoding == 'true' ||
  81. this.options.stringArrayEncoding == 'false' ?
  82. Boolean(this.options.stringArrayEncoding) :
  83. this.options.stringArrayEncoding;
  84. break;
  85. default:
  86. config.options[key] = this.options[key];
  87. break;
  88. }
  89. }
  90. Editor.Ipc.sendToMain('ccc-obfuscated-code:save-config', config, (err, msg) => {
  91. this.isSaving = false;
  92. });
  93. },
  94. /**
  95. * 读取配置
  96. */
  97. readConfig() {
  98. Editor.Ipc.sendToMain('ccc-obfuscated-code:read-config', (err, config) => {
  99. if (err) return;
  100. this.auto = config.auto;
  101. this.files = config.files.join(',');
  102. this.useAbsPath = config.useAbsPath;
  103. this.preset = config.preset;
  104. for (let key in config.options) {
  105. this.options[key] = Array.isArray(config.options[key]) ? config.options[key].join(',') : config.options[key];
  106. }
  107. });
  108. },
  109. /**
  110. * 读取预设
  111. */
  112. getPreset() {
  113. Editor.Ipc.sendToMain('ccc-obfuscated-code:get-preset', this.preset, (err, options) => {
  114. for (let key in options) {
  115. this.options[key] = options[key];
  116. }
  117. });
  118. }
  119. }
  120. });
  121. vue.readConfig();
  122. }
  123. });