Electron App launching implement 37/176137/8
authorws29.jung <ws29.jung@samsung.com>
Tue, 17 Apr 2018 02:13:23 +0000 (11:13 +0900)
committerWonsuk Jung <ws29.jung@samsung.com>
Wed, 25 Apr 2018 08:17:06 +0000 (08:17 +0000)
Ironically, Electron JS Runtime was not able to execute Electron Web App,
but only able to run Tizen Web app.
From this patch, if Electron App is packaged as wgt, JS Runtime will parse xml
then will launch Electron App from its own entry point.

Change-Id: Iec5df77495063e129d99a8e1dd21bc8f489b8ffe
Signed-off-by: ws29.jung <ws29.jung@samsung.com>
atom/app/ui_runtime.cc
atom/browser/api/atom_api_pwrt.cc
atom/browser/api/atom_api_pwrt.h
atom/browser/browser.cc
atom/browser/browser.h
wrt/src/runtime.js

index 7091bff..959e4ac 100644 (file)
@@ -55,6 +55,7 @@ bool UiRuntime::OnCreate() {
 }
 
 void UiRuntime::OnTerminate() {
+  LOG(ERROR) << "OnTerminate()";
   atom::Browser *browser_model = atom::Browser::Get();
 }
 
@@ -99,7 +100,6 @@ int UiRuntime::Exec() {
 
   // onCreate
   ops.create = [](void* data) -> bool {
-
     LOG(ERROR) << "Create Tizen App.";
     UiRuntime *runtime = (UiRuntime*)data;
     content::ContentMain(*runtime->_params);
index b63ef51..30213c5 100644 (file)
@@ -52,6 +52,10 @@ bool PWRT::isTizenWebApp() {
   }
 }
 
+bool PWRT::isElectronLaunch() {
+  return Browser::Get()->is_electron_launch();
+}
+
 void PWRT::Log(const std::string& message) {
   std::string output = "[JS LOG] " + message;
   dlog_print(DLOG_ERROR, "WRT", output.c_str());
@@ -73,6 +77,7 @@ void PWRT::BuildPrototype(
     .SetMethod("getMessage", &PWRT::GetMessage)
     .SetMethod("getPath", &PWRT::GetPath)
     .SetMethod("isTizenWebApp", &PWRT::isTizenWebApp)
+    .SetMethod("isElectronLaunch", &PWRT::isElectronLaunch)
     .SetMethod("log", &PWRT::Log);
 }
 
index 647a5ae..8b67cc2 100644 (file)
@@ -19,6 +19,7 @@ class PWRT : public mate::TrackableObject<PWRT> {
   std::string GetMessage();
   std::string GetPath();
   bool isTizenWebApp();
+  bool isElectronLaunch();
   void Log(const std::string& message);
 
  protected:
index dea0bf2..771cbee 100644 (file)
@@ -21,6 +21,9 @@ namespace atom {
 
 Browser::Browser()
     : is_quiting_(false),
+#if defined(OS_TIZEN)
+      is_electron_launch_(false),
+#endif
       is_exiting_(false),
       is_ready_(false),
       is_shutdown_(false),
@@ -100,6 +103,22 @@ void Browser::Shutdown() {
   }
 }
 
+#if defined(OS_TIZEN)
+void Browser::SetElectronAppLaunch() {
+  if (!is_electron_launch_) {
+    common::CommandLine* runtime_cmd = common::CommandLine::ForCurrentProcess();
+    std::string appid = runtime_cmd->GetAppIdFromCommandLine("/usr/bin/electron");
+    auto appdata_manager = common::ApplicationDataManager::GetInstance();
+    common::ApplicationData* app_data = appdata_manager->GetApplicationData(appid);
+    if (!strcmp(app_data->content_info()->src().c_str(), "package.json")) {
+      is_electron_launch_ = true;
+    }
+  } else {
+    is_electron_launch_ = false;
+  }
+}
+#endif
+
 std::string Browser::GetVersion() const {
   if (version_override_.empty()) {
     std::string version = GetExecutableFileVersion();
@@ -151,6 +170,9 @@ void Browser::Activate(bool has_visible_windows) {
 }
 
 void Browser::WillFinishLaunching() {
+#if defined(OS_TIZEN)
+  SetElectronAppLaunch();
+#endif
   for (BrowserObserver& observer : observers_)
     observer.OnWillFinishLaunching();
 }
index 286ba29..dfc4831 100644 (file)
@@ -222,6 +222,9 @@ class Browser : public WindowListObserver {
   bool is_shutting_down() const { return is_shutdown_; }
   bool is_quiting() const { return is_quiting_; }
   bool is_ready() const { return is_ready_; }
+#if defined(OS_TIZEN)
+  bool is_electron_launch() const { return is_electron_launch_; }
+#endif
 
  protected:
   // Returns the version of application bundle or executable file.
@@ -245,6 +248,10 @@ class Browser : public WindowListObserver {
   void OnWindowCloseCancelled(NativeWindow* window) override;
   void OnWindowAllClosed() override;
 
+#if defined(OS_TIZEN)
+  void SetElectronAppLaunch();
+#endif
+
   // Observers of the browser.
   base::ObserverList<BrowserObserver> observers_;
 
@@ -257,6 +264,10 @@ class Browser : public WindowListObserver {
   // The browser is being shutdown.
   bool is_shutdown_;
 
+#if defined(OS_TIZEN)
+  bool is_electron_launch_;
+#endif
+
   std::string version_override_;
   std::string name_override_;
 
index d6c855d..0bdaa49 100644 (file)
@@ -1,5 +1,5 @@
 'use strict';
-const {app, ipcMain} = require('electron');
+const {app, ipcMain, pwrt} = require('electron');
 const IPC_MESSAGE = require('./ipc_message');
 const WAS_EVENT = require('./was_event');
 const WebApplication = require('./web_application');
@@ -13,6 +13,7 @@ class Runtime {
         this.quitting = false;
         this.handleWasEvents();
         this.handleIpcMessages();
+        this.isLaunched = false;
 
         var _this = this;
         app.on('before-quit', function(event) {
@@ -40,8 +41,24 @@ class Runtime {
         app.on('window-all-closed', function(event) {
             return runtime_debug('window-all-closed');
         });
+        app.on('will-finish-launching', function(event) {
+            runtime_debug('will-finish-launching');
+            if (pwrt.isElectronLaunch()) {
+                console.log("Electron App launch");
+                let filePath = pwrt.getPath();
+                let pkgJson = require(filePath.substr(7, filePath.length - 12));
+                let mainJsPath = filePath.substr(7, filePath.length - 19) +
+                                                (pkgJson.main || 'index.js');
+
+                const Module = require('module');
+                Module._load(mainJsPath, Module, true);
+             }
+        });
         app.on('ready', function(event) {
             runtime_debug('ready');
+            if (pwrt.isElectronLaunch()) {
+                return;
+            }
             this.webApplication = new WebApplication(options);
         });
     }