From a6289324b1f05291eb6f0de0dccfd6f3664ac3e4 Mon Sep 17 00:00:00 2001 From: "ws29.jung" Date: Tue, 17 Apr 2018 11:13:23 +0900 Subject: [PATCH] Electron App launching implement 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 --- atom/app/ui_runtime.cc | 2 +- atom/browser/api/atom_api_pwrt.cc | 5 +++++ atom/browser/api/atom_api_pwrt.h | 1 + atom/browser/browser.cc | 22 ++++++++++++++++++++++ atom/browser/browser.h | 11 +++++++++++ wrt/src/runtime.js | 19 ++++++++++++++++++- 6 files changed, 58 insertions(+), 2 deletions(-) diff --git a/atom/app/ui_runtime.cc b/atom/app/ui_runtime.cc index 7091bff..959e4ac 100644 --- a/atom/app/ui_runtime.cc +++ b/atom/app/ui_runtime.cc @@ -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); diff --git a/atom/browser/api/atom_api_pwrt.cc b/atom/browser/api/atom_api_pwrt.cc index b63ef51..30213c5 100644 --- a/atom/browser/api/atom_api_pwrt.cc +++ b/atom/browser/api/atom_api_pwrt.cc @@ -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); } diff --git a/atom/browser/api/atom_api_pwrt.h b/atom/browser/api/atom_api_pwrt.h index 647a5ae..8b67cc2 100644 --- a/atom/browser/api/atom_api_pwrt.h +++ b/atom/browser/api/atom_api_pwrt.h @@ -19,6 +19,7 @@ class PWRT : public mate::TrackableObject { std::string GetMessage(); std::string GetPath(); bool isTizenWebApp(); + bool isElectronLaunch(); void Log(const std::string& message); protected: diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index dea0bf2..771cbee 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -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(); } diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 286ba29..dfc4831 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -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 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_; diff --git a/wrt/src/runtime.js b/wrt/src/runtime.js index d6c855d..0bdaa49 100644 --- a/wrt/src/runtime.js +++ b/wrt/src/runtime.js @@ -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); }); } -- 2.7.4