_entry_preview.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. var fs = require('fs');
  2. var vm = require('vm');
  3. initRuntimeEnv();
  4. var dirHome = process.env['COMX_SDK'];
  5. var dirUnit = __dirname + '/';
  6. if(process.platform == 'win32')
  7. {
  8. require('bindings')('js_ext_comx_qtshell-native-win.node');
  9. require('bindings')('js_ext_comx_resource-native-win.node');
  10. require('bindings')('js_ext_comx_mutex-native-win.node');
  11. }
  12. if(process.platform == 'linux')
  13. {
  14. require('bindings')('js_ext_comx_qt-native-linux.node');
  15. require('bindings')('js_ext_comx_resource-native-linux.node');
  16. require('bindings')('js_ext_comx_mutex-native-linux.node');
  17. }
  18. var require_ = require('require-from-string');
  19. var __ = (_)=>{
  20. (new vm.Script(_)).runInNewContext({
  21. 'require' : require,
  22. 'process' : process,
  23. 'comx' : comx,
  24. 'exports' :exports,
  25. 'comx_startup' : ()=>{
  26. comx.resource.qt.loadUnit(dirUnit, exports, function(){
  27. if(process.argv.length >= 4)
  28. {
  29. var is_hide = !process.argv[3];
  30. if(is_hide)
  31. {
  32. unit.form[process.argv[2]].ShowEmbedded();
  33. }
  34. else
  35. unit.form[process.argv[2]].ShowPreview();
  36. }
  37. else
  38. {
  39. var is_hide = !process.argv[2];
  40. if(is_hide)
  41. {
  42. unit.form._entry.ShowEmbedded();
  43. }
  44. else
  45. unit.form._entry.ShowPreview();
  46. }
  47. }, (form)=>{
  48. //readyForm
  49. });
  50. }
  51. });
  52. };
  53. var tmpl = fs.readFileSync(dirHome+'template/4e7b90182d3b4e11a7ca74d8fc8c545f');
  54. comx.resource.Initialize(require_, __, tmpl);
  55. if(!comx.resource.hasResource)
  56. {
  57. if(process.argv.length == 4)
  58. {
  59. var tmpl = fs.readFileSync(dirHome+'template/008f111453704f82b9616e9bf92655f0');
  60. comx.resource.LoadKernelRemote(parseInt(process.argv[3]), false, tmpl);
  61. }
  62. else
  63. {
  64. var tmpl = fs.readFileSync(dirHome+'template/ad72fee60eea4a89844aa934b9bc099b');
  65. comx.resource.LoadKernelRemote(getWSAddress(), false, tmpl);
  66. }
  67. }
  68. else
  69. {
  70. comx.resource.qt.loadUnit(dirUnit, exports, function(){
  71. if(process.argv.length >= 4)
  72. {
  73. var is_hide = !process.argv[3];
  74. if(is_hide)
  75. {
  76. unit.form[process.argv[2]].ShowEmbedded();
  77. }
  78. else
  79. unit.form[process.argv[2]].ShowPreview();
  80. }
  81. else
  82. {
  83. var is_hide = !process.argv[2];
  84. if(is_hide)
  85. {
  86. unit.form._entry.ShowEmbedded();
  87. }
  88. else
  89. unit.form._entry.ShowPreview();
  90. }
  91. }, (form)=>{
  92. //readyForm
  93. });
  94. }
  95. process.on('uncaughtException', (e)=>{
  96. console.error('process error is:', e.message);
  97. });
  98. /////////////////////////////////////////////////////////////////////////////
  99. // Init Runtime Env
  100. function initRuntimeEnv()
  101. {
  102. process.env.COMX_SDK = getHomeDir();
  103. var depsDir = getDepsDir();
  104. if(depsDir)
  105. {
  106. process.chdir(depsDir);
  107. }
  108. }
  109. function getParentDir(dirName)
  110. {
  111. var idx = dirName.lastIndexOf('/');
  112. if(idx == -1)
  113. {
  114. idx = dirName.lastIndexOf('\\');
  115. }
  116. return dirName.substr(0, idx);
  117. }
  118. function getHomeDir()
  119. {
  120. if(fs.existsSync(__dirname + '/07D976FB68304742A31191AA0503DE79'))
  121. {
  122. return __dirname + '/';
  123. }
  124. else
  125. {
  126. return getParentDir(getParentDir(__dirname)) + '/';
  127. }
  128. }
  129. function getDepsDir()
  130. {
  131. if(process.platform == 'win32')
  132. {
  133. return getHomeDir() + 'deps\\windows\\bin\\';
  134. }
  135. if(process.platform == 'linux')
  136. {
  137. return getHomeDir() + 'deps/linux/bin/';
  138. }
  139. return false;
  140. }
  141. function getWSAddress()
  142. {
  143. var fpath = getHomeDir() + '/cache/ws.cache';
  144. if(!fs.existsSync(fpath))
  145. {
  146. return "ws://localhost:3000";
  147. }
  148. else
  149. {
  150. return '' + fs.readFileSync(fpath);
  151. }
  152. }