Fix electron app launching issue 47/201647/1
authorSangYong Park <sy302.park@samsung.com>
Mon, 18 Mar 2019 09:15:41 +0000 (18:15 +0900)
committerSangYong Park <sy302.park@samsung.com>
Mon, 18 Mar 2019 09:15:41 +0000 (18:15 +0900)
Set proper app and electron library path

Change-Id: I34e11c4c6152e8b47ff1c2517a4bcd9c49d763bd
Signed-off-by: SangYong Park <sy302.park@samsung.com>
wrt_app/browser/init.js
wrt_app/renderer/init.js
wrt_app/renderer/wrt_renderer.js [new file with mode: 0644]
wrt_app/src/runtime.js

index 1c688d7..663464c 100755 (executable)
@@ -14,5 +14,5 @@
  *    limitations under the License.
  */
 
-const wrt = require('../browser/wrt');
+const wrt = require('./wrt');
 require(wrt.getElectronPath() + '/browser/init')
index ead2a61..177283d 100755 (executable)
@@ -14,7 +14,8 @@
  *    limitations under the License.
  */
 
-require('../../electron.asar/renderer/init')
+const wrtRenderer = require('./wrt_renderer');
+require(wrtRenderer.getElectronPath() + '/renderer/init')
 
 process.on('uncaughtException', function (error) {
   // Do nothing if the user has a custom uncaught exception handler.
diff --git a/wrt_app/renderer/wrt_renderer.js b/wrt_app/renderer/wrt_renderer.js
new file mode 100644 (file)
index 0000000..d642327
--- /dev/null
@@ -0,0 +1,3 @@
+const {wrtRenderer} = process.binding('wrt_renderer');
+
+module.exports = wrtRenderer
index ea2cc65..dc1ee02 100755 (executable)
@@ -101,10 +101,12 @@ class Runtime {
 
             if (wrt.isElectronApp()) {
                 console.log("Electron App launch");
-                let filePath = src;
-                let pkgJson = require(filePath.substr(7, filePath.length - 12));
-                let mainJsPath = filePath.substr(7, filePath.length - 19) +
-                                                (pkgJson.main || 'index.js');
+                require('module').globalPaths.push(wrt.getAppPath());
+                let filePath = src[7] === '/' ? src.substr(8) : src.substr(7); // strip "file://"
+                let pkgJson = require(filePath);
+                let pos = filePath.lastIndexOf('/');
+                let mainJsPath = (pos !== -1 ? filePath.substr(0, pos + 1) : '') +
+                                 (pkgJson.main || 'index.js');
 
                 const Module = require('module');
                 Module._load(mainJsPath, Module, true);
@@ -125,7 +127,6 @@ class Runtime {
             _this.webApplication.resume();
         });
     }
-    onAppControl() {}
     onLanguageChanged() {}
     onLowMemory() {}
     killAllProcesses() {}