_entry.js 3.2 KB

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