From 8f49617801551b4425f6ec092f7f426321cb6939 Mon Sep 17 00:00:00 2001 From: "surya.kumar7" Date: Wed, 14 Feb 2018 20:11:33 +0530 Subject: [PATCH 01/16] Add pwrt electron interface object Any necesssary implementations or functions needed by JS-WRT can be facilitated through this private pwrt object so that the deviation from electron model is minimized and isolated Change-Id: I5653406dd04c360259ba35656f1e598ce05d1858 --- atom/browser/api/atom_api_pwrt.cc | 61 +++++++++++++++++++++++++++++++++++++++ atom/browser/api/atom_api_pwrt.h | 33 +++++++++++++++++++++ atom/common/node_bindings.cc | 1 + filenames.gypi | 3 ++ lib/browser/api/module-list.js | 3 +- lib/browser/api/pwrt.js | 3 ++ 6 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 atom/browser/api/atom_api_pwrt.cc create mode 100644 atom/browser/api/atom_api_pwrt.h create mode 100644 lib/browser/api/pwrt.js diff --git a/atom/browser/api/atom_api_pwrt.cc b/atom/browser/api/atom_api_pwrt.cc new file mode 100644 index 0000000..334127d --- /dev/null +++ b/atom/browser/api/atom_api_pwrt.cc @@ -0,0 +1,61 @@ +#include "atom/browser/api/atom_api_pwrt.h" + +#include "atom/browser/browser.h" +#include "native_mate/dictionary.h" +#include "base/logging.h" + +#include "atom/common/node_includes.h" + +namespace atom { + +namespace api { + +PWRT::PWRT(v8::Isolate* isolate) { + LOG(DEBUG) << "PWRT::PWRT"; + Init(isolate); +} + +PWRT::~PWRT() { + LOG(DEBUG) << "PWRT::~PWRT"; +} + +std::string PWRT::GetMessage() { + LOG(DEBUG) << "PWRT::GetMessage"; + return "message from C++"; +} + +// static +mate::Handle PWRT::Create(v8::Isolate* isolate) { + LOG(DEBUG) << "PWRT::Create"; + return mate::CreateHandle(isolate, new PWRT(isolate)); +} + +// static +void PWRT::BuildPrototype( + v8::Isolate* isolate, v8::Local prototype) { + LOG(DEBUG) << "PWRT::BuildPrototype"; + prototype->SetClassName(mate::StringToV8(isolate, "PWRT")); + // TODO: Needs adding necessary interface methods + mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + .SetMethod("getMessage", &PWRT::GetMessage); +} + +} // namespace api + +} // namespace atom + + +namespace { + +void Initialize(v8::Local exports, v8::Local unused, + v8::Local context, void* priv) { + LOG(DEBUG) << "PWRT::Initialize"; + v8::Isolate* isolate = context->GetIsolate(); + mate::Dictionary dict(isolate, exports); + // TODO: Expose this attribute only for Tizen web apps + dict.Set("pwrt", atom::api::PWRT::Create(isolate)); +} + +} // namespace + +NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_pwrt, Initialize) diff --git a/atom/browser/api/atom_api_pwrt.h b/atom/browser/api/atom_api_pwrt.h new file mode 100644 index 0000000..110eac0 --- /dev/null +++ b/atom/browser/api/atom_api_pwrt.h @@ -0,0 +1,33 @@ +#ifndef ATOM_BROWSER_API_ATOM_API_PWRT_H_ +#define ATOM_BROWSER_API_ATOM_API_PWRT_H_ + +#include "atom/browser/api/trackable_object.h" +#include "base/compiler_specific.h" +#include "native_mate/handle.h" + +namespace atom { + +namespace api { + +class PWRT : public mate::TrackableObject { + public: + static mate::Handle Create(v8::Isolate* isolate); + + static void BuildPrototype(v8::Isolate* isolate, + v8::Local prototype); + + std::string GetMessage(); + + protected: + explicit PWRT(v8::Isolate* isolate); + ~PWRT() override; + + private: + DISALLOW_COPY_AND_ASSIGN(PWRT); +}; + +} // namespace api + +} // namespace atom + +#endif // ATOM_BROWSER_API_ATOM_API_PWRT_H_ diff --git a/atom/common/node_bindings.cc b/atom/common/node_bindings.cc index 4c8e82f..2a9c057 100644 --- a/atom/common/node_bindings.cc +++ b/atom/common/node_bindings.cc @@ -47,6 +47,7 @@ REFERENCE_MODULE(atom_browser_net); REFERENCE_MODULE(atom_browser_power_monitor); REFERENCE_MODULE(atom_browser_power_save_blocker); REFERENCE_MODULE(atom_browser_protocol); +REFERENCE_MODULE(atom_browser_pwrt); REFERENCE_MODULE(atom_browser_render_process_preferences); REFERENCE_MODULE(atom_browser_session); REFERENCE_MODULE(atom_browser_system_preferences); diff --git a/filenames.gypi b/filenames.gypi index fc6d857..16fd220 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -29,6 +29,7 @@ 'lib/browser/api/power-monitor.js', 'lib/browser/api/power-save-blocker.js', 'lib/browser/api/protocol.js', + 'lib/browser/api/pwrt.js', 'lib/browser/api/screen.js', 'lib/browser/api/session.js', 'lib/browser/api/system-preferences.js', @@ -135,6 +136,8 @@ 'atom/browser/api/atom_api_power_save_blocker.h', 'atom/browser/api/atom_api_protocol.cc', 'atom/browser/api/atom_api_protocol.h', + 'atom/browser/api/atom_api_pwrt.cc', + 'atom/browser/api/atom_api_pwrt.h', 'atom/browser/api/atom_api_render_process_preferences.cc', 'atom/browser/api/atom_api_render_process_preferences.h', 'atom/browser/api/atom_api_screen.cc', diff --git a/lib/browser/api/module-list.js b/lib/browser/api/module-list.js index 64b2829..fcc07b3 100644 --- a/lib/browser/api/module-list.js +++ b/lib/browser/api/module-list.js @@ -21,5 +21,6 @@ module.exports = [ {name: 'Tray', file: 'tray'}, {name: 'webContents', file: 'web-contents'}, // The internal modules, invisible unless you know their names. - {name: 'NavigationController', file: 'navigation-controller', private: true} + {name: 'NavigationController', file: 'navigation-controller', private: true}, + {name: 'pwrt', file: 'pwrt', private: true} ] diff --git a/lib/browser/api/pwrt.js b/lib/browser/api/pwrt.js new file mode 100644 index 0000000..0019884 --- /dev/null +++ b/lib/browser/api/pwrt.js @@ -0,0 +1,3 @@ +const {pwrt} = process.atomBinding('pwrt'); + +module.exports = pwrt -- 2.7.4 From 33efdff9c835296e135507a21f9eb7125d0ca349 Mon Sep 17 00:00:00 2001 From: jinwoo jeong Date: Wed, 31 Jan 2018 17:59:22 +0900 Subject: [PATCH 02/16] Getting application data using wrt common library. To use wrt common library, it should be complied to shared library. Because it has many dependency with system libraries. In wrt common, there are CommandLine and ApplicationData modules. Using those modules, the arguements can be parsed. And electron can get more information from app db or app control. Change-Id: Idb7f906b240de01f04ad4ed145266e23615ef4d3 Signed-off-by: jinwoo jeong --- atom/app/atom_main.cc | 18 +++++++++++++++--- electron.gyp | 13 +++++++++---- packaging/electron-efl.spec | 5 +++++ tizen/common/common.gyp | 2 +- tizen/loader/loader.gyp | 35 ++++++++--------------------------- tizen/loader/wrt_loader.cc | 8 ++++---- 6 files changed, 42 insertions(+), 39 deletions(-) diff --git a/atom/app/atom_main.cc b/atom/app/atom_main.cc index 0d6ea8b..49625a6 100644 --- a/atom/app/atom_main.cc +++ b/atom/app/atom_main.cc @@ -37,6 +37,9 @@ #include "base/i18n/icu_util.h" #if defined(OS_TIZEN) +#include "base/logging.h" +#include "tizen/common/application_data.h" +#include "tizen/common/command_line.h" #include "tizen/loader/prelauncher.h" #include "base/logging.h" #endif @@ -144,9 +147,18 @@ int main(int argc, char* argv[]) { } #if defined(USE_EFL) - if (argv[0] == "/usr/bin/electron") // not browser process - base::CommandLine::Init(argc, argv); - else if (efl::Initialize(argc, const_cast(argv))) + common::CommandLine::Init(argc, argv); + common::CommandLine* runtime_cmd = common::CommandLine::ForCurrentProcess(); + std::string appid = runtime_cmd->GetAppIdFromCommandLine("/usr/bin/electron"); + + // load manifest + auto appdata_manager = common::ApplicationDataManager::GetInstance(); + common::ApplicationData* appdata = appdata_manager->GetApplicationData(appid); + if (!appdata->LoadManifestData()) { + return false; + } + + if (efl::Initialize(argc, const_cast(argv))) return 1; // Add params for EFL port diff --git a/electron.gyp b/electron.gyp index dda2dff..d876687 100644 --- a/electron.gyp +++ b/electron.gyp @@ -221,18 +221,23 @@ ], }], # OS=="linux" ['is_tizen==1', { + 'includes': [ + 'tizen/build/common.gypi', + ], 'dependencies': [ - 'tizen/common/common.gyp:*', - 'tizen/loader/loader.gyp:*', + 'tizen/common/common.gyp:wrt_common', + 'tizen/loader/loader.gyp:wrt-loader', '<(DEPTH)/efl/build/system.gyp:ecore', '<(DEPTH)/efl/build/system.gyp:launchpad', ], + 'sources': [ + 'tizen/loader/prelauncher.h', + 'tizen/loader/prelauncher.cc', + ], 'ldflags': [ '-pie', '-export-dynamic', ], - 'cflags': [ '-fPIC' ], - 'cflags_cc': [ '-fPIC' ], }], # is_tizen==1 ], }, # target <(project_name) diff --git a/packaging/electron-efl.spec b/packaging/electron-efl.spec index f909978..42f9c65 100755 --- a/packaging/electron-efl.spec +++ b/packaging/electron-efl.spec @@ -105,6 +105,10 @@ install -m 0644 %{_out}/packaging/%{_pkgid}.xml %{buildroot}%{_xmldir} mkdir -p %{buildroot}%{_datadir}/aul/ cp %{SOURCE1002} %{buildroot}%{_datadir}/aul/ +# wrt_common +mkdir -p %{buildroot}%{_libdir} +install -p -m 644 %{_out}/lib/libwrt_common.so %{buildroot}%{_libdir} + mkdir -p %{buildroot}/usr/apps/org.tizen.electron-efl/bin/ install -d %{buildroot}/%{_icondir} install -d %{buildroot}/%{_libdir} @@ -162,3 +166,4 @@ rm -fr %{buildroot} %attr(755,root,root) %{_bindir}/wrt-loader %attr(755,root,root) %{_bindir}/xwalk_runtime %attr(644,root,root) %{_datadir}/aul/wrt.loader +%attr(644,root,root) %{_libdir}/libwrt_common.so diff --git a/tizen/common/common.gyp b/tizen/common/common.gyp index 25d27a8..7d56a2e 100644 --- a/tizen/common/common.gyp +++ b/tizen/common/common.gyp @@ -5,7 +5,7 @@ 'targets': [ { 'target_name': 'wrt_common', - 'type': 'static_library', + 'type': 'shared_library', 'sources': [ 'command_line.h', 'command_line.cc', diff --git a/tizen/loader/loader.gyp b/tizen/loader/loader.gyp index 14d1fdc..d71af00 100755 --- a/tizen/loader/loader.gyp +++ b/tizen/loader/loader.gyp @@ -1,4 +1,7 @@ { + 'includes': [ + '../build/common.gypi', + ], 'targets': [ { 'target_name': 'wrt-loader', @@ -9,36 +12,14 @@ 'libraries' : [ '-ldl', ], - 'include_dirs': [ - '<(libchromiumcontent_src_dir)', - ], 'ldflags': [ - '-Wl,--whole-archive', - '<@(libchromiumcontent_libraries)', - '-Wl,--no-whole-archive', + '-pie', ], - 'link_settings': { - 'libraries': [ - '<@(libchromiumcontent_libraries)', - ] + 'variables': { + 'packages': [ + 'dlog', + ], }, }, # end of target 'wrt-loader' - { - 'target_name': 'prelauncher', - 'type': 'static_library', - 'dependencies': [ - '<(DEPTH)/efl/build/system.gyp:ecore', - '<(DEPTH)/efl/build/system.gyp:launchpad', - ], - 'include_dirs': [ - '<(libchromiumcontent_src_dir)', - ], - 'cflags': [ '-fPIC' ], - 'cflags_cc': [ '-fPIC' ], - 'sources': [ - 'prelauncher.cc', - 'prelauncher.h', - ], - }, # end of target 'preloader' ], } diff --git a/tizen/loader/wrt_loader.cc b/tizen/loader/wrt_loader.cc index 57b9d3b..bb91449 100644 --- a/tizen/loader/wrt_loader.cc +++ b/tizen/loader/wrt_loader.cc @@ -14,15 +14,15 @@ * limitations under the License. */ #include -#include "base/logging.h" +#include // loader file must have "User" execute label, because launchpad daemon runs // with "System::Privileged" label. int main(int argc, char* argv[]) { - LOG(INFO) << "Begin wrt-loader"; + dlog_print(DLOG_INFO, "CHROMIUM", "Begin wrt-loader"); void* handle = dlopen("/usr/bin/electron", RTLD_NOW); if (!handle) { - LOG(ERROR) << "Failed to load electorn"; + dlog_print(DLOG_ERROR, "CHROMIUM", "Failed to load electorn"); return false; } @@ -30,7 +30,7 @@ int main(int argc, char* argv[]) { MAIN_FUNC real_main = reinterpret_cast(dlsym(handle, "main")); if (!real_main) { - LOG(ERROR) << "Failed to load real_main"; + dlog_print(DLOG_ERROR, "CHROMIUM", "Failed to load real_main"); return false; } -- 2.7.4 From 543a605dc6593e28185d6a954ca3bfebd0372b19 Mon Sep 17 00:00:00 2001 From: "min7.choi" Date: Mon, 26 Feb 2018 19:42:12 +0900 Subject: [PATCH 03/16] Fix build errors Error message with recompile with -fPIC Change-Id: Idaeb7adbc5a2eaaf4b160c6c9a81802f9bbb7d12 Signed-off-by: min7.choi --- electron.gyp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/electron.gyp b/electron.gyp index d876687..a7f036f 100644 --- a/electron.gyp +++ b/electron.gyp @@ -238,6 +238,8 @@ '-pie', '-export-dynamic', ], + 'cflags': [ '-fPIC' ], + 'cflags_cc': [ '-fPIC' ], }], # is_tizen==1 ], }, # target <(project_name) -- 2.7.4 From 9d78cd305ea3ae69850a9b4d37ee4258d4fa6dd1 Mon Sep 17 00:00:00 2001 From: "min7.choi" Date: Tue, 27 Feb 2018 13:10:11 +0900 Subject: [PATCH 04/16] Revert "Add pwrt electron interface object" "LOG(DEBUG)" produces a build error. This reverts commit 8f49617801551b4425f6ec092f7f426321cb6939. Change-Id: I11f50cd3e012ae1719b700409974307379b0fe74 Signed-off-by: min7.choi --- atom/browser/api/atom_api_pwrt.cc | 61 --------------------------------------- atom/browser/api/atom_api_pwrt.h | 33 --------------------- atom/common/node_bindings.cc | 1 - filenames.gypi | 3 -- lib/browser/api/module-list.js | 3 +- lib/browser/api/pwrt.js | 3 -- 6 files changed, 1 insertion(+), 103 deletions(-) delete mode 100644 atom/browser/api/atom_api_pwrt.cc delete mode 100644 atom/browser/api/atom_api_pwrt.h delete mode 100644 lib/browser/api/pwrt.js diff --git a/atom/browser/api/atom_api_pwrt.cc b/atom/browser/api/atom_api_pwrt.cc deleted file mode 100644 index 334127d..0000000 --- a/atom/browser/api/atom_api_pwrt.cc +++ /dev/null @@ -1,61 +0,0 @@ -#include "atom/browser/api/atom_api_pwrt.h" - -#include "atom/browser/browser.h" -#include "native_mate/dictionary.h" -#include "base/logging.h" - -#include "atom/common/node_includes.h" - -namespace atom { - -namespace api { - -PWRT::PWRT(v8::Isolate* isolate) { - LOG(DEBUG) << "PWRT::PWRT"; - Init(isolate); -} - -PWRT::~PWRT() { - LOG(DEBUG) << "PWRT::~PWRT"; -} - -std::string PWRT::GetMessage() { - LOG(DEBUG) << "PWRT::GetMessage"; - return "message from C++"; -} - -// static -mate::Handle PWRT::Create(v8::Isolate* isolate) { - LOG(DEBUG) << "PWRT::Create"; - return mate::CreateHandle(isolate, new PWRT(isolate)); -} - -// static -void PWRT::BuildPrototype( - v8::Isolate* isolate, v8::Local prototype) { - LOG(DEBUG) << "PWRT::BuildPrototype"; - prototype->SetClassName(mate::StringToV8(isolate, "PWRT")); - // TODO: Needs adding necessary interface methods - mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) - .SetMethod("getMessage", &PWRT::GetMessage); -} - -} // namespace api - -} // namespace atom - - -namespace { - -void Initialize(v8::Local exports, v8::Local unused, - v8::Local context, void* priv) { - LOG(DEBUG) << "PWRT::Initialize"; - v8::Isolate* isolate = context->GetIsolate(); - mate::Dictionary dict(isolate, exports); - // TODO: Expose this attribute only for Tizen web apps - dict.Set("pwrt", atom::api::PWRT::Create(isolate)); -} - -} // namespace - -NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_pwrt, Initialize) diff --git a/atom/browser/api/atom_api_pwrt.h b/atom/browser/api/atom_api_pwrt.h deleted file mode 100644 index 110eac0..0000000 --- a/atom/browser/api/atom_api_pwrt.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef ATOM_BROWSER_API_ATOM_API_PWRT_H_ -#define ATOM_BROWSER_API_ATOM_API_PWRT_H_ - -#include "atom/browser/api/trackable_object.h" -#include "base/compiler_specific.h" -#include "native_mate/handle.h" - -namespace atom { - -namespace api { - -class PWRT : public mate::TrackableObject { - public: - static mate::Handle Create(v8::Isolate* isolate); - - static void BuildPrototype(v8::Isolate* isolate, - v8::Local prototype); - - std::string GetMessage(); - - protected: - explicit PWRT(v8::Isolate* isolate); - ~PWRT() override; - - private: - DISALLOW_COPY_AND_ASSIGN(PWRT); -}; - -} // namespace api - -} // namespace atom - -#endif // ATOM_BROWSER_API_ATOM_API_PWRT_H_ diff --git a/atom/common/node_bindings.cc b/atom/common/node_bindings.cc index 2a9c057..4c8e82f 100644 --- a/atom/common/node_bindings.cc +++ b/atom/common/node_bindings.cc @@ -47,7 +47,6 @@ REFERENCE_MODULE(atom_browser_net); REFERENCE_MODULE(atom_browser_power_monitor); REFERENCE_MODULE(atom_browser_power_save_blocker); REFERENCE_MODULE(atom_browser_protocol); -REFERENCE_MODULE(atom_browser_pwrt); REFERENCE_MODULE(atom_browser_render_process_preferences); REFERENCE_MODULE(atom_browser_session); REFERENCE_MODULE(atom_browser_system_preferences); diff --git a/filenames.gypi b/filenames.gypi index 16fd220..fc6d857 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -29,7 +29,6 @@ 'lib/browser/api/power-monitor.js', 'lib/browser/api/power-save-blocker.js', 'lib/browser/api/protocol.js', - 'lib/browser/api/pwrt.js', 'lib/browser/api/screen.js', 'lib/browser/api/session.js', 'lib/browser/api/system-preferences.js', @@ -136,8 +135,6 @@ 'atom/browser/api/atom_api_power_save_blocker.h', 'atom/browser/api/atom_api_protocol.cc', 'atom/browser/api/atom_api_protocol.h', - 'atom/browser/api/atom_api_pwrt.cc', - 'atom/browser/api/atom_api_pwrt.h', 'atom/browser/api/atom_api_render_process_preferences.cc', 'atom/browser/api/atom_api_render_process_preferences.h', 'atom/browser/api/atom_api_screen.cc', diff --git a/lib/browser/api/module-list.js b/lib/browser/api/module-list.js index fcc07b3..64b2829 100644 --- a/lib/browser/api/module-list.js +++ b/lib/browser/api/module-list.js @@ -21,6 +21,5 @@ module.exports = [ {name: 'Tray', file: 'tray'}, {name: 'webContents', file: 'web-contents'}, // The internal modules, invisible unless you know their names. - {name: 'NavigationController', file: 'navigation-controller', private: true}, - {name: 'pwrt', file: 'pwrt', private: true} + {name: 'NavigationController', file: 'navigation-controller', private: true} ] diff --git a/lib/browser/api/pwrt.js b/lib/browser/api/pwrt.js deleted file mode 100644 index 0019884..0000000 --- a/lib/browser/api/pwrt.js +++ /dev/null @@ -1,3 +0,0 @@ -const {pwrt} = process.atomBinding('pwrt'); - -module.exports = pwrt -- 2.7.4 From d25194e4736ea15dce66ef83e63ed2a2d7896397 Mon Sep 17 00:00:00 2001 From: "surya.kumar7" Date: Tue, 27 Feb 2018 11:09:19 +0530 Subject: [PATCH 05/16] Add pwrt electron interface object Any necesssary implementations or functions needed by JS-WRT can be facilitated through this private pwrt object so that the deviation from electron model is minimized and isolated Change-Id: Iebb569dcacb5e6745199c4b0e579dcc256ea3b11 Signed-off-by: surya.kumar7 --- atom/browser/api/atom_api_pwrt.cc | 61 +++++++++++++++++++++++++++++++++++++++ atom/browser/api/atom_api_pwrt.h | 33 +++++++++++++++++++++ atom/common/node_bindings.cc | 1 + filenames.gypi | 3 ++ lib/browser/api/module-list.js | 3 +- lib/browser/api/pwrt.js | 3 ++ 6 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 atom/browser/api/atom_api_pwrt.cc create mode 100644 atom/browser/api/atom_api_pwrt.h create mode 100644 lib/browser/api/pwrt.js diff --git a/atom/browser/api/atom_api_pwrt.cc b/atom/browser/api/atom_api_pwrt.cc new file mode 100644 index 0000000..0938077 --- /dev/null +++ b/atom/browser/api/atom_api_pwrt.cc @@ -0,0 +1,61 @@ +#include "atom/browser/api/atom_api_pwrt.h" + +#include "atom/browser/browser.h" +#include "native_mate/dictionary.h" +#include "base/logging.h" + +#include "atom/common/node_includes.h" + +namespace atom { + +namespace api { + +PWRT::PWRT(v8::Isolate* isolate) { + LOG(INFO) << "PWRT::PWRT"; + Init(isolate); +} + +PWRT::~PWRT() { + LOG(INFO) << "PWRT::~PWRT"; +} + +std::string PWRT::GetMessage() { + LOG(INFO) << "PWRT::GetMessage"; + return "message from C++"; +} + +// static +mate::Handle PWRT::Create(v8::Isolate* isolate) { + LOG(INFO) << "PWRT::Create"; + return mate::CreateHandle(isolate, new PWRT(isolate)); +} + +// static +void PWRT::BuildPrototype( + v8::Isolate* isolate, v8::Local prototype) { + LOG(INFO) << "PWRT::BuildPrototype"; + prototype->SetClassName(mate::StringToV8(isolate, "PWRT")); + // TODO: Needs adding necessary interface methods + mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + .SetMethod("getMessage", &PWRT::GetMessage); +} + +} // namespace api + +} // namespace atom + + +namespace { + +void Initialize(v8::Local exports, v8::Local unused, + v8::Local context, void* priv) { + LOG(INFO) << "PWRT::Initialize"; + v8::Isolate* isolate = context->GetIsolate(); + mate::Dictionary dict(isolate, exports); + // TODO: Expose this attribute only for Tizen web apps + dict.Set("pwrt", atom::api::PWRT::Create(isolate)); +} + +} // namespace + +NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_pwrt, Initialize) diff --git a/atom/browser/api/atom_api_pwrt.h b/atom/browser/api/atom_api_pwrt.h new file mode 100644 index 0000000..110eac0 --- /dev/null +++ b/atom/browser/api/atom_api_pwrt.h @@ -0,0 +1,33 @@ +#ifndef ATOM_BROWSER_API_ATOM_API_PWRT_H_ +#define ATOM_BROWSER_API_ATOM_API_PWRT_H_ + +#include "atom/browser/api/trackable_object.h" +#include "base/compiler_specific.h" +#include "native_mate/handle.h" + +namespace atom { + +namespace api { + +class PWRT : public mate::TrackableObject { + public: + static mate::Handle Create(v8::Isolate* isolate); + + static void BuildPrototype(v8::Isolate* isolate, + v8::Local prototype); + + std::string GetMessage(); + + protected: + explicit PWRT(v8::Isolate* isolate); + ~PWRT() override; + + private: + DISALLOW_COPY_AND_ASSIGN(PWRT); +}; + +} // namespace api + +} // namespace atom + +#endif // ATOM_BROWSER_API_ATOM_API_PWRT_H_ diff --git a/atom/common/node_bindings.cc b/atom/common/node_bindings.cc index 4c8e82f..2a9c057 100644 --- a/atom/common/node_bindings.cc +++ b/atom/common/node_bindings.cc @@ -47,6 +47,7 @@ REFERENCE_MODULE(atom_browser_net); REFERENCE_MODULE(atom_browser_power_monitor); REFERENCE_MODULE(atom_browser_power_save_blocker); REFERENCE_MODULE(atom_browser_protocol); +REFERENCE_MODULE(atom_browser_pwrt); REFERENCE_MODULE(atom_browser_render_process_preferences); REFERENCE_MODULE(atom_browser_session); REFERENCE_MODULE(atom_browser_system_preferences); diff --git a/filenames.gypi b/filenames.gypi index fc6d857..16fd220 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -29,6 +29,7 @@ 'lib/browser/api/power-monitor.js', 'lib/browser/api/power-save-blocker.js', 'lib/browser/api/protocol.js', + 'lib/browser/api/pwrt.js', 'lib/browser/api/screen.js', 'lib/browser/api/session.js', 'lib/browser/api/system-preferences.js', @@ -135,6 +136,8 @@ 'atom/browser/api/atom_api_power_save_blocker.h', 'atom/browser/api/atom_api_protocol.cc', 'atom/browser/api/atom_api_protocol.h', + 'atom/browser/api/atom_api_pwrt.cc', + 'atom/browser/api/atom_api_pwrt.h', 'atom/browser/api/atom_api_render_process_preferences.cc', 'atom/browser/api/atom_api_render_process_preferences.h', 'atom/browser/api/atom_api_screen.cc', diff --git a/lib/browser/api/module-list.js b/lib/browser/api/module-list.js index 64b2829..fcc07b3 100644 --- a/lib/browser/api/module-list.js +++ b/lib/browser/api/module-list.js @@ -21,5 +21,6 @@ module.exports = [ {name: 'Tray', file: 'tray'}, {name: 'webContents', file: 'web-contents'}, // The internal modules, invisible unless you know their names. - {name: 'NavigationController', file: 'navigation-controller', private: true} + {name: 'NavigationController', file: 'navigation-controller', private: true}, + {name: 'pwrt', file: 'pwrt', private: true} ] diff --git a/lib/browser/api/pwrt.js b/lib/browser/api/pwrt.js new file mode 100644 index 0000000..0019884 --- /dev/null +++ b/lib/browser/api/pwrt.js @@ -0,0 +1,3 @@ +const {pwrt} = process.atomBinding('pwrt'); + +module.exports = pwrt -- 2.7.4 From 47c1995de576c2cc344bcfdbae06e859db059933 Mon Sep 17 00:00:00 2001 From: "min7.choi" Date: Tue, 27 Feb 2018 19:11:03 +0900 Subject: [PATCH 06/16] Add a new api - PWRT::GetPath() Get the path of app data from JS through the new api Change-Id: I99ed00f7d62764ba17e2b0dc85d45a0e3d78d5b2 Signed-off-by: min7.choi --- atom/browser/api/atom_api_pwrt.cc | 15 ++++++++++++++- atom/browser/api/atom_api_pwrt.h | 1 + wrt/src/web_window.js | 4 +++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/atom/browser/api/atom_api_pwrt.cc b/atom/browser/api/atom_api_pwrt.cc index 0938077..248361e 100644 --- a/atom/browser/api/atom_api_pwrt.cc +++ b/atom/browser/api/atom_api_pwrt.cc @@ -5,6 +5,8 @@ #include "base/logging.h" #include "atom/common/node_includes.h" +#include "tizen/common/application_data.h" +#include "tizen/common/command_line.h" namespace atom { @@ -24,6 +26,16 @@ std::string PWRT::GetMessage() { return "message from C++"; } +std::string PWRT::GetPath() { + LOG(INFO) << "PWRT::GetPath"; + 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); + std::string app_path = "file://" + app_data->application_path() + "index.html"; + return app_path; +} + // static mate::Handle PWRT::Create(v8::Isolate* isolate) { LOG(INFO) << "PWRT::Create"; @@ -37,7 +49,8 @@ void PWRT::BuildPrototype( prototype->SetClassName(mate::StringToV8(isolate, "PWRT")); // TODO: Needs adding necessary interface methods mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) - .SetMethod("getMessage", &PWRT::GetMessage); + .SetMethod("getMessage", &PWRT::GetMessage) + .SetMethod("getPath", &PWRT::GetPath); } } // namespace api diff --git a/atom/browser/api/atom_api_pwrt.h b/atom/browser/api/atom_api_pwrt.h index 110eac0..f8bf915 100644 --- a/atom/browser/api/atom_api_pwrt.h +++ b/atom/browser/api/atom_api_pwrt.h @@ -17,6 +17,7 @@ class PWRT : public mate::TrackableObject { v8::Local prototype); std::string GetMessage(); + std::string GetPath(); protected: explicit PWRT(v8::Isolate* isolate); diff --git a/wrt/src/web_window.js b/wrt/src/web_window.js index 5262e9c..559c61b 100644 --- a/wrt/src/web_window.js +++ b/wrt/src/web_window.js @@ -231,7 +231,9 @@ class WebWindow { if(!path){ path = DEFAULT_URL; } - this.mainWindow.loadUrl(path); +        var {pwrt} = require('electron'); +        path = pwrt.getPath(); +        this.mainWindow.loadUrl(path); } show() { this.mainWindow.show(); -- 2.7.4 From c76ede6a4d27ae6dcda26d5f1990072755f5d793 Mon Sep 17 00:00:00 2001 From: prathmeshm Date: Fri, 23 Feb 2018 16:39:44 +0530 Subject: [PATCH 07/16] Initial implementation of app loop Change-Id: Id704b08ce2df00648de0e7b1718f5c994894df40 Signed-off-by: prathmeshm --- atom/app/atom_main.cc | 22 ++++++ atom/app/runtime.cc | 29 +++++++ atom/app/runtime.h | 23 ++++++ atom/app/ui_runtime.cc | 124 ++++++++++++++++++++++++++++++ atom/app/ui_runtime.h | 50 ++++++++++++ atom/browser/api/atom_api_web_contents.cc | 5 ++ atom/browser/api/atom_api_window.cc | 10 +++ atom/browser/api/atom_api_window.h | 5 ++ atom/browser/browser.cc | 10 +++ atom/browser/browser.h | 2 + atom/browser/browser_observer.h | 2 + efl/build/system.gyp | 21 +++++ electron.gyp | 2 + filenames.gypi | 2 + wrt/src/runtime.js | 4 +- wrt/src/web_window.js | 8 ++ wrt/src/web_window_tag.js | 8 ++ 17 files changed, 325 insertions(+), 2 deletions(-) create mode 100644 atom/app/runtime.cc create mode 100644 atom/app/runtime.h create mode 100644 atom/app/ui_runtime.cc create mode 100644 atom/app/ui_runtime.h diff --git a/atom/app/atom_main.cc b/atom/app/atom_main.cc index 49625a6..c71f3dd 100644 --- a/atom/app/atom_main.cc +++ b/atom/app/atom_main.cc @@ -44,6 +44,8 @@ #include "base/logging.h" #endif +#include "atom/app/runtime.h" + namespace { const char* kRunAsNode = "ELECTRON_RUN_AS_NODE"; @@ -136,6 +138,18 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) { #elif defined(OS_LINUX) // defined(OS_WIN) #if defined(OS_TIZEN) +// For debug purpose only +bool hasTizenPackageID(int argc, const char* const* argv) { + if (argc > 3) { + if (0 == strncmp(argv[0], "/opt/usr/globalapps/", strlen("/opt/usr/globalapps/"))) { + return true; + } + } + return false; +} +#endif + +#if defined(OS_TIZEN) int real_main(int argc, char* argv[]) { #else int main(int argc, char* argv[]) { @@ -175,7 +189,15 @@ int main(int argc, char* argv[]) { params.argc = argc; params.argv = const_cast(argv); atom::AtomCommandLine::Init(argc, argv); +#if defined(OS_TIZEN) + if (hasTizenPackageID(argc,argv)) { + std::unique_ptr runtime = runtime::Runtime::MakeRuntime(); + runtime->Exec(params); + return 1; + } +#endif return content::ContentMain(params); + } #if defined(OS_TIZEN) diff --git a/atom/app/runtime.cc b/atom/app/runtime.cc new file mode 100644 index 0000000..95a9b16 --- /dev/null +++ b/atom/app/runtime.cc @@ -0,0 +1,29 @@ +#include "atom/app/runtime.h" +#include "atom/app/ui_runtime.h" +#include "base/logging.h" + +namespace runtime { + +Runtime::~Runtime() { +} + +std::unique_ptr Runtime::MakeRuntime() { +/* if (app_data->app_type() == common::ApplicationData::UI) { + return std::unique_ptr(new UiRuntime()); + } +#ifdef IME_FEATURE_SUPPORT + else if (app_data->app_type() == common::ApplicationData::IME) { + return std::unique_ptr(new ImeRuntime(app_data)); + } +#endif // IME_FEATURE_SUPPORT +#ifdef WATCH_FACE_FEATURE_SUPPORT + else if (app_data->app_type() == common::ApplicationData::WATCH) { + return std::unique_ptr(new WatchRuntime(app_data)); + } +#endif // WATCH_FACE_FEATURE_SUPPORT + else { */ + return std::unique_ptr(new UiRuntime()); + //} +} + +} // namespace runtime \ No newline at end of file diff --git a/atom/app/runtime.h b/atom/app/runtime.h new file mode 100644 index 0000000..a893875 --- /dev/null +++ b/atom/app/runtime.h @@ -0,0 +1,23 @@ + +#ifndef RUNTIME_H_ +#define RUNTIME_H_ + +#include +#include + +#include "content/public/app/content_main.h" + +namespace runtime { + +class Runtime { + public: + virtual ~Runtime() = 0; + + virtual int Exec(content::ContentMainParams params) = 0; + + static std::unique_ptr MakeRuntime(); +}; + +} // namespace runtime + +#endif // RUNTIME_H_ \ No newline at end of file diff --git a/atom/app/ui_runtime.cc b/atom/app/ui_runtime.cc new file mode 100644 index 0000000..b732652 --- /dev/null +++ b/atom/app/ui_runtime.cc @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "atom/app/ui_runtime.h" +#include "atom/app/atom_main_delegate.h" +#include "content/public/app/content_main.h" +#include "atom/common/atom_command_line.h" +#include "atom/browser/atom_browser_client.h" +#include "base/logging.h" +#include "atom/browser/browser.h" + +#include +#include +#include + +namespace runtime { + +UiRuntime::UiRuntime() { +} + +UiRuntime::~UiRuntime() { +} + + +bool UiRuntime::OnCreate() { + +} + +void UiRuntime::OnTerminate() { +} + +void UiRuntime::Terminate() { + +} + +void UiRuntime::OnPause() { + LOG(ERROR) << "OnPause()"; +} + +void UiRuntime::OnResume() { + LOG(ERROR) << "OnResume()"; +} + +void UiRuntime::OnAppControl(app_control_h app_control) { + LOG(ERROR) << "OnAppControl()"; +} + +void UiRuntime::OnLanguageChanged(const std::string& language) { + LOG(ERROR) << "OnLanguageChanged()"; +} + +void UiRuntime::OnLowMemory() { + LOG(ERROR) << "OnLowMemory()"; +} + +int UiRuntime::Exec(content::ContentMainParams params) { + ui_app_lifecycle_callback_s ops = {NULL, NULL, NULL, NULL, NULL}; + + // onCreate + ops.create = [](void* data) -> bool { + + LOG(ERROR) << "Create Tizen App."; + content::ContentMainParams *params = (content::ContentMainParams*)data; + content::ContentMain(*params); + return true; + }; + + // onTerminate + ops.terminate = [](void* data) -> void { + LOG(ERROR) << "Terminate Tizen App."; + atom::Browser *browser_model = atom::Browser::Get(); + browser_model->Shutdown(); + }; + + // onPause + ops.pause = [](void* data) -> void { + LOG(ERROR) << "Pause Tizen App."; + atom::Browser *browser_model = atom::Browser::Get(); + browser_model->Hide(); + }; + + // onResume + ops.resume = [](void* data) -> void { + LOG(ERROR) << "Resume Tizen App."; + atom::Browser *browser_model = atom::Browser::Get(); + browser_model->Show(); + }; + + // onAppControl + ops.app_control = [](app_control_h app_control, void* data) -> void { + LOG(ERROR) << "app_control Tizen App."; + }; + + std::vector cmdAgrs = atom::AtomCommandLine::argv(); + int argc = cmdAgrs.size(); + //std::string argv; + char **argvs = (char**)malloc(sizeof(char)*100); + for (int i=0;i +#include +#include "atom/app/runtime.h" +#include "content/public/app/content_main.h" + +namespace runtime { + +class UiRuntime : public Runtime { + public: + UiRuntime(); + virtual ~UiRuntime(); + + virtual int Exec(content::ContentMainParams params); + + protected: + virtual bool OnCreate(); + virtual void OnTerminate(); + virtual void OnPause(); + virtual void OnResume(); + virtual void OnAppControl(app_control_h app_control); + virtual void OnLanguageChanged(const std::string& language); + virtual void OnLowMemory(); + virtual void Terminate(); + + private: + void ResetWebApplication(); +}; + +} // namespace runtime + +#endif // XWALK_RUNTIME_BROWSER_UI_RUNTIME_H_ diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 8c473c5..66c4564 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -434,7 +434,12 @@ bool WebContents::DidAddMessageToConsole(content::WebContents* source, int32_t line_no, const base::string16& source_id) { if (type_ == BROWSER_WINDOW || type_ == OFF_SCREEN) { +#if defined(USE_EFL) + LOG(ERROR) << "ConsoleMessage : " << message << "\", source: " << source_id << " (" << line_no << ")"; + return true; +#else return false; +#endif } else { Emit("console-message", level, message, line_no, source_id); return true; diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 72b8e33..f19fbda 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -310,6 +310,16 @@ void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) { } #endif +#if defined(USE_EFL) +void Window::OnSuspend() { + Emit("app-on-suspend"); +} + +void Window::OnResume() { + Emit("app-on-resume"); +} +#endif + // static mate::WrappableBase* Window::New(mate::Arguments* args) { if (!Browser::Get()->is_ready()) { diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 75f0328..daa56c7 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -96,6 +96,11 @@ class Window : public mate::TrackableObject, void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) override; #endif + #if defined(USE_EFL) + void OnSuspend(); + void OnResume(); + #endif + private: void Init(v8::Isolate* isolate, v8::Local wrapper, diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index b2900a3..6f2a3c7 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -213,4 +213,14 @@ void Browser::OnWindowAllClosed() { } } +void Browser::Hide() { + for (BrowserObserver& observer : observers_) + observer.OnSuspend(); +} + +void Browser::Show() { + for (BrowserObserver& observer : observers_) + observer.OnResume(); +} + } // namespace atom diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 78cac65..fc674dd 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -104,6 +104,8 @@ class Browser : public WindowListObserver { void SetLoginItemSettings(LoginItemSettings settings); LoginItemSettings GetLoginItemSettings(const LoginItemSettings& options); + void Hide(); + void Show(); #if defined(OS_MACOSX) // Hide the application. void Hide(); diff --git a/atom/browser/browser_observer.h b/atom/browser/browser_observer.h index 88a50a9..b5760ec 100644 --- a/atom/browser/browser_observer.h +++ b/atom/browser/browser_observer.h @@ -55,6 +55,8 @@ class BrowserObserver { // The browser's accessibility suppport has changed. virtual void OnAccessibilitySupportChanged() {} + virtual void OnSuspend() {} + virtual void OnResume() {} #if defined(OS_MACOSX) // The browser wants to resume a user activity via handoff. (macOS only) virtual void OnContinueUserActivity( diff --git a/efl/build/system.gyp b/efl/build/system.gyp index 8934237..3e0f94f 100644 --- a/efl/build/system.gyp +++ b/efl/build/system.gyp @@ -197,5 +197,26 @@ }], # tizen_product_tv==1 ], }, # vd-win-util + { + 'target_name': 'capi-appfw-application', + 'type': 'none', + 'conditions': [ + ['is_tizen==1', { + 'direct_dependent_settings': { + 'cflags': [ + ' { + events.on(WAS_EVENT.RUNTIME.RESUME, (sender, id) => { runtime_debug('handleWasMessages: focus ' + id); return _this.onResume(id); }); - events.on(WAS_EVENT.RUNTIME.UNFOCUS, (sender, id) => { + events.on(WAS_EVENT.RUNTIME.SUSPEND, (sender, id) => { return _this.onPause(id); }); } diff --git a/wrt/src/web_window.js b/wrt/src/web_window.js index 559c61b..5720c82 100644 --- a/wrt/src/web_window.js +++ b/wrt/src/web_window.js @@ -131,6 +131,14 @@ class WebWindow { this.mainWindow.on('language-changed', function(event, locale) { webwindow_debug('WebWindow : language-changed event = ' + (JSON.stringify(locale))); }); + this.mainWindow.on('app-on-suspend', function() { + webwindow_debug('WebWindow : app-on-suspend'); + events.emit(WAS_EVENT.RUNTIME.SUSPEND, 'web_window', self.mainWindow.id); + }); + this.mainWindow.on('app-on-resume', function() { + webwindow_debug('WebWindow : app-on-resume'); + events.emit(WAS_EVENT.RUNTIME.RESUME, 'web_window', self.mainWindow.id); + }); this.mainWindow.webContents.on('crashed', function() { webwindow_debug('WebWindow : webContents crashed'); global.webApplication.exit(100); diff --git a/wrt/src/web_window_tag.js b/wrt/src/web_window_tag.js index ae60995..ac02405 100644 --- a/wrt/src/web_window_tag.js +++ b/wrt/src/web_window_tag.js @@ -154,6 +154,14 @@ class WebWindowTag { this.mainWindow.on('language-changed', function(event, locale) { webwindow_debug('WebWindow : language-changed event = ' + (JSON.stringify(locale))); }); + this.mainWindow.on('app-on-suspend', function() { + webwindow_debug('WebWindow : app-on-suspend'); + events.emit(WAS_EVENT.RUNTIME.SUSPEND, 'web_window', self.mainWindow.id); + }); + this.mainWindow.on('app-on-resume', function() { + webwindow_debug('WebWindow : app-on-resume'); + events.emit(WAS_EVENT.RUNTIME.RESUME, 'web_window', self.mainWindow.id); + }); this.mainWindow.webContents.on('crashed', function() { webwindow_debug('WebWindow : webContents crashed'); global.webApplication.exit(100); -- 2.7.4 From 5b51a6c7345ee4141cc08233d2463ce8ec508cd8 Mon Sep 17 00:00:00 2001 From: "surya.kumar7" Date: Thu, 1 Mar 2018 21:11:39 +0530 Subject: [PATCH 08/16] Electron doesn't have a config file to parse config.xml is not present for electron-efl which is unintentionally regarded as a terminal failure and app exits Change-Id: I781a854956c2931bf8492b8f4614438262afe802 Signed-off-by: surya.kumar7 --- atom/app/atom_main.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/atom/app/atom_main.cc b/atom/app/atom_main.cc index c71f3dd..522e499 100644 --- a/atom/app/atom_main.cc +++ b/atom/app/atom_main.cc @@ -166,10 +166,12 @@ int main(int argc, char* argv[]) { std::string appid = runtime_cmd->GetAppIdFromCommandLine("/usr/bin/electron"); // load manifest - auto appdata_manager = common::ApplicationDataManager::GetInstance(); - common::ApplicationData* appdata = appdata_manager->GetApplicationData(appid); - if (!appdata->LoadManifestData()) { - return false; + if (appid != "electron") { // TODO: Any better way to distinguish? + auto appdata_manager = common::ApplicationDataManager::GetInstance(); + common::ApplicationData* appdata = appdata_manager->GetApplicationData(appid); + if (!appdata->LoadManifestData()) { + return false; + } } if (efl::Initialize(argc, const_cast(argv))) -- 2.7.4 From c424d3165ea8aef24a83bff72af2f9c856dd492f Mon Sep 17 00:00:00 2001 From: "surya.kumar7" Date: Thu, 1 Mar 2018 22:47:57 +0530 Subject: [PATCH 09/16] Extract start url from config only for Tizen Web Apps Extended the pwrt object to identify if the current app is Tizen web app and retrieve its source file Change-Id: I48f799942a8ce48ce90f65ac257d8092242987a8 Signed-off-by: surya.kumar7 --- atom/browser/api/atom_api_pwrt.cc | 16 ++++++++++++++-- atom/browser/api/atom_api_pwrt.h | 1 + tizen/common/application_data.h | 1 + wrt/src/main.js | 4 ++++ wrt/src/web_window.js | 2 -- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/atom/browser/api/atom_api_pwrt.cc b/atom/browser/api/atom_api_pwrt.cc index 248361e..766b8cb 100644 --- a/atom/browser/api/atom_api_pwrt.cc +++ b/atom/browser/api/atom_api_pwrt.cc @@ -32,10 +32,21 @@ std::string PWRT::GetPath() { std::string appid = runtime_cmd->GetAppIdFromCommandLine("/usr/bin/electron"); auto appdata_manager = common::ApplicationDataManager::GetInstance(); common::ApplicationData* app_data = appdata_manager->GetApplicationData(appid); - std::string app_path = "file://" + app_data->application_path() + "index.html"; + std::string app_path = "file://" + app_data->application_path() + app_data->content_src(); return app_path; } +bool PWRT::isTizenWebApp() { + LOG(INFO) << "PWRT::isTizenWebApp"; + common::CommandLine* runtime_cmd = common::CommandLine::ForCurrentProcess(); + std::string appid = runtime_cmd->GetAppIdFromCommandLine("/usr/bin/electron"); + if (appid != "electron") { // TODO: Any better distinguishing feature? + return true; + } else { + return false; + } +} + // static mate::Handle PWRT::Create(v8::Isolate* isolate) { LOG(INFO) << "PWRT::Create"; @@ -50,7 +61,8 @@ void PWRT::BuildPrototype( // TODO: Needs adding necessary interface methods mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetMethod("getMessage", &PWRT::GetMessage) - .SetMethod("getPath", &PWRT::GetPath); + .SetMethod("getPath", &PWRT::GetPath) + .SetMethod("isTizenWebApp", &PWRT::isTizenWebApp); } } // namespace api diff --git a/atom/browser/api/atom_api_pwrt.h b/atom/browser/api/atom_api_pwrt.h index f8bf915..ac466d7 100644 --- a/atom/browser/api/atom_api_pwrt.h +++ b/atom/browser/api/atom_api_pwrt.h @@ -18,6 +18,7 @@ class PWRT : public mate::TrackableObject { std::string GetMessage(); std::string GetPath(); + bool isTizenWebApp(); protected: explicit PWRT(v8::Isolate* isolate); diff --git a/tizen/common/application_data.h b/tizen/common/application_data.h index 8f43cae..eed0347 100644 --- a/tizen/common/application_data.h +++ b/tizen/common/application_data.h @@ -70,6 +70,7 @@ class ApplicationData { const std::string application_path() const { return application_path_; } const std::string pkg_id() const; const std::string app_id() const { return app_id_; } + const std::string content_src() { return (content_info_.get())->src(); } ApplicationData::AppType app_type() { return app_type_; } private: diff --git a/wrt/src/main.js b/wrt/src/main.js index 9b96567..dfdeeb7 100644 --- a/wrt/src/main.js +++ b/wrt/src/main.js @@ -113,6 +113,10 @@ makeArguments = function () { path_debug('Check runType'); break; } + let {pwrt} = require('electron'); + if (pwrt.isTizenWebApp()) { + packageRealPath = pwrt.getPath(); + } args['packageRealPath'] = packageRealPath; if (args.windowSize) { diff --git a/wrt/src/web_window.js b/wrt/src/web_window.js index 5720c82..1111959 100644 --- a/wrt/src/web_window.js +++ b/wrt/src/web_window.js @@ -239,8 +239,6 @@ class WebWindow { if(!path){ path = DEFAULT_URL; } -        var {pwrt} = require('electron'); -        path = pwrt.getPath();         this.mainWindow.loadUrl(path); } show() { -- 2.7.4 From 689eebd92cc5127586cd901ddd69bd4df722fd55 Mon Sep 17 00:00:00 2001 From: "ws29.jung" Date: Mon, 5 Mar 2018 17:52:39 +0900 Subject: [PATCH 10/16] Revert "Initial implementation of app loop" This commit causes WebApp crash. This reverts commit c76ede6a4d27ae6dcda26d5f1990072755f5d793. Change-Id: I2e11d793959c740cbba092910c0aac83443db87a Signed-off-by: ws29.jung --- atom/app/atom_main.cc | 22 ------ atom/app/runtime.cc | 29 ------- atom/app/runtime.h | 23 ------ atom/app/ui_runtime.cc | 124 ------------------------------ atom/app/ui_runtime.h | 50 ------------ atom/browser/api/atom_api_web_contents.cc | 5 -- atom/browser/api/atom_api_window.cc | 10 --- atom/browser/api/atom_api_window.h | 5 -- atom/browser/browser.cc | 10 --- atom/browser/browser.h | 2 - atom/browser/browser_observer.h | 2 - efl/build/system.gyp | 21 ----- electron.gyp | 2 - filenames.gypi | 2 - wrt/src/runtime.js | 4 +- wrt/src/web_window.js | 8 -- wrt/src/web_window_tag.js | 8 -- 17 files changed, 2 insertions(+), 325 deletions(-) delete mode 100644 atom/app/runtime.cc delete mode 100644 atom/app/runtime.h delete mode 100644 atom/app/ui_runtime.cc delete mode 100644 atom/app/ui_runtime.h diff --git a/atom/app/atom_main.cc b/atom/app/atom_main.cc index 522e499..cd51296 100644 --- a/atom/app/atom_main.cc +++ b/atom/app/atom_main.cc @@ -44,8 +44,6 @@ #include "base/logging.h" #endif -#include "atom/app/runtime.h" - namespace { const char* kRunAsNode = "ELECTRON_RUN_AS_NODE"; @@ -138,18 +136,6 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) { #elif defined(OS_LINUX) // defined(OS_WIN) #if defined(OS_TIZEN) -// For debug purpose only -bool hasTizenPackageID(int argc, const char* const* argv) { - if (argc > 3) { - if (0 == strncmp(argv[0], "/opt/usr/globalapps/", strlen("/opt/usr/globalapps/"))) { - return true; - } - } - return false; -} -#endif - -#if defined(OS_TIZEN) int real_main(int argc, char* argv[]) { #else int main(int argc, char* argv[]) { @@ -191,15 +177,7 @@ int main(int argc, char* argv[]) { params.argc = argc; params.argv = const_cast(argv); atom::AtomCommandLine::Init(argc, argv); -#if defined(OS_TIZEN) - if (hasTizenPackageID(argc,argv)) { - std::unique_ptr runtime = runtime::Runtime::MakeRuntime(); - runtime->Exec(params); - return 1; - } -#endif return content::ContentMain(params); - } #if defined(OS_TIZEN) diff --git a/atom/app/runtime.cc b/atom/app/runtime.cc deleted file mode 100644 index 95a9b16..0000000 --- a/atom/app/runtime.cc +++ /dev/null @@ -1,29 +0,0 @@ -#include "atom/app/runtime.h" -#include "atom/app/ui_runtime.h" -#include "base/logging.h" - -namespace runtime { - -Runtime::~Runtime() { -} - -std::unique_ptr Runtime::MakeRuntime() { -/* if (app_data->app_type() == common::ApplicationData::UI) { - return std::unique_ptr(new UiRuntime()); - } -#ifdef IME_FEATURE_SUPPORT - else if (app_data->app_type() == common::ApplicationData::IME) { - return std::unique_ptr(new ImeRuntime(app_data)); - } -#endif // IME_FEATURE_SUPPORT -#ifdef WATCH_FACE_FEATURE_SUPPORT - else if (app_data->app_type() == common::ApplicationData::WATCH) { - return std::unique_ptr(new WatchRuntime(app_data)); - } -#endif // WATCH_FACE_FEATURE_SUPPORT - else { */ - return std::unique_ptr(new UiRuntime()); - //} -} - -} // namespace runtime \ No newline at end of file diff --git a/atom/app/runtime.h b/atom/app/runtime.h deleted file mode 100644 index a893875..0000000 --- a/atom/app/runtime.h +++ /dev/null @@ -1,23 +0,0 @@ - -#ifndef RUNTIME_H_ -#define RUNTIME_H_ - -#include -#include - -#include "content/public/app/content_main.h" - -namespace runtime { - -class Runtime { - public: - virtual ~Runtime() = 0; - - virtual int Exec(content::ContentMainParams params) = 0; - - static std::unique_ptr MakeRuntime(); -}; - -} // namespace runtime - -#endif // RUNTIME_H_ \ No newline at end of file diff --git a/atom/app/ui_runtime.cc b/atom/app/ui_runtime.cc deleted file mode 100644 index b732652..0000000 --- a/atom/app/ui_runtime.cc +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "atom/app/ui_runtime.h" -#include "atom/app/atom_main_delegate.h" -#include "content/public/app/content_main.h" -#include "atom/common/atom_command_line.h" -#include "atom/browser/atom_browser_client.h" -#include "base/logging.h" -#include "atom/browser/browser.h" - -#include -#include -#include - -namespace runtime { - -UiRuntime::UiRuntime() { -} - -UiRuntime::~UiRuntime() { -} - - -bool UiRuntime::OnCreate() { - -} - -void UiRuntime::OnTerminate() { -} - -void UiRuntime::Terminate() { - -} - -void UiRuntime::OnPause() { - LOG(ERROR) << "OnPause()"; -} - -void UiRuntime::OnResume() { - LOG(ERROR) << "OnResume()"; -} - -void UiRuntime::OnAppControl(app_control_h app_control) { - LOG(ERROR) << "OnAppControl()"; -} - -void UiRuntime::OnLanguageChanged(const std::string& language) { - LOG(ERROR) << "OnLanguageChanged()"; -} - -void UiRuntime::OnLowMemory() { - LOG(ERROR) << "OnLowMemory()"; -} - -int UiRuntime::Exec(content::ContentMainParams params) { - ui_app_lifecycle_callback_s ops = {NULL, NULL, NULL, NULL, NULL}; - - // onCreate - ops.create = [](void* data) -> bool { - - LOG(ERROR) << "Create Tizen App."; - content::ContentMainParams *params = (content::ContentMainParams*)data; - content::ContentMain(*params); - return true; - }; - - // onTerminate - ops.terminate = [](void* data) -> void { - LOG(ERROR) << "Terminate Tizen App."; - atom::Browser *browser_model = atom::Browser::Get(); - browser_model->Shutdown(); - }; - - // onPause - ops.pause = [](void* data) -> void { - LOG(ERROR) << "Pause Tizen App."; - atom::Browser *browser_model = atom::Browser::Get(); - browser_model->Hide(); - }; - - // onResume - ops.resume = [](void* data) -> void { - LOG(ERROR) << "Resume Tizen App."; - atom::Browser *browser_model = atom::Browser::Get(); - browser_model->Show(); - }; - - // onAppControl - ops.app_control = [](app_control_h app_control, void* data) -> void { - LOG(ERROR) << "app_control Tizen App."; - }; - - std::vector cmdAgrs = atom::AtomCommandLine::argv(); - int argc = cmdAgrs.size(); - //std::string argv; - char **argvs = (char**)malloc(sizeof(char)*100); - for (int i=0;i -#include -#include "atom/app/runtime.h" -#include "content/public/app/content_main.h" - -namespace runtime { - -class UiRuntime : public Runtime { - public: - UiRuntime(); - virtual ~UiRuntime(); - - virtual int Exec(content::ContentMainParams params); - - protected: - virtual bool OnCreate(); - virtual void OnTerminate(); - virtual void OnPause(); - virtual void OnResume(); - virtual void OnAppControl(app_control_h app_control); - virtual void OnLanguageChanged(const std::string& language); - virtual void OnLowMemory(); - virtual void Terminate(); - - private: - void ResetWebApplication(); -}; - -} // namespace runtime - -#endif // XWALK_RUNTIME_BROWSER_UI_RUNTIME_H_ diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 66c4564..8c473c5 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -434,12 +434,7 @@ bool WebContents::DidAddMessageToConsole(content::WebContents* source, int32_t line_no, const base::string16& source_id) { if (type_ == BROWSER_WINDOW || type_ == OFF_SCREEN) { -#if defined(USE_EFL) - LOG(ERROR) << "ConsoleMessage : " << message << "\", source: " << source_id << " (" << line_no << ")"; - return true; -#else return false; -#endif } else { Emit("console-message", level, message, line_no, source_id); return true; diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index f19fbda..72b8e33 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -310,16 +310,6 @@ void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) { } #endif -#if defined(USE_EFL) -void Window::OnSuspend() { - Emit("app-on-suspend"); -} - -void Window::OnResume() { - Emit("app-on-resume"); -} -#endif - // static mate::WrappableBase* Window::New(mate::Arguments* args) { if (!Browser::Get()->is_ready()) { diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index daa56c7..75f0328 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -96,11 +96,6 @@ class Window : public mate::TrackableObject, void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) override; #endif - #if defined(USE_EFL) - void OnSuspend(); - void OnResume(); - #endif - private: void Init(v8::Isolate* isolate, v8::Local wrapper, diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index 6f2a3c7..b2900a3 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -213,14 +213,4 @@ void Browser::OnWindowAllClosed() { } } -void Browser::Hide() { - for (BrowserObserver& observer : observers_) - observer.OnSuspend(); -} - -void Browser::Show() { - for (BrowserObserver& observer : observers_) - observer.OnResume(); -} - } // namespace atom diff --git a/atom/browser/browser.h b/atom/browser/browser.h index fc674dd..78cac65 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -104,8 +104,6 @@ class Browser : public WindowListObserver { void SetLoginItemSettings(LoginItemSettings settings); LoginItemSettings GetLoginItemSettings(const LoginItemSettings& options); - void Hide(); - void Show(); #if defined(OS_MACOSX) // Hide the application. void Hide(); diff --git a/atom/browser/browser_observer.h b/atom/browser/browser_observer.h index b5760ec..88a50a9 100644 --- a/atom/browser/browser_observer.h +++ b/atom/browser/browser_observer.h @@ -55,8 +55,6 @@ class BrowserObserver { // The browser's accessibility suppport has changed. virtual void OnAccessibilitySupportChanged() {} - virtual void OnSuspend() {} - virtual void OnResume() {} #if defined(OS_MACOSX) // The browser wants to resume a user activity via handoff. (macOS only) virtual void OnContinueUserActivity( diff --git a/efl/build/system.gyp b/efl/build/system.gyp index 3e0f94f..8934237 100644 --- a/efl/build/system.gyp +++ b/efl/build/system.gyp @@ -197,26 +197,5 @@ }], # tizen_product_tv==1 ], }, # vd-win-util - { - 'target_name': 'capi-appfw-application', - 'type': 'none', - 'conditions': [ - ['is_tizen==1', { - 'direct_dependent_settings': { - 'cflags': [ - ' { + events.on(WAS_EVENT.RUNTIME.FOCUS, (sender, id) => { runtime_debug('handleWasMessages: focus ' + id); return _this.onResume(id); }); - events.on(WAS_EVENT.RUNTIME.SUSPEND, (sender, id) => { + events.on(WAS_EVENT.RUNTIME.UNFOCUS, (sender, id) => { return _this.onPause(id); }); } diff --git a/wrt/src/web_window.js b/wrt/src/web_window.js index 1111959..6423300 100644 --- a/wrt/src/web_window.js +++ b/wrt/src/web_window.js @@ -131,14 +131,6 @@ class WebWindow { this.mainWindow.on('language-changed', function(event, locale) { webwindow_debug('WebWindow : language-changed event = ' + (JSON.stringify(locale))); }); - this.mainWindow.on('app-on-suspend', function() { - webwindow_debug('WebWindow : app-on-suspend'); - events.emit(WAS_EVENT.RUNTIME.SUSPEND, 'web_window', self.mainWindow.id); - }); - this.mainWindow.on('app-on-resume', function() { - webwindow_debug('WebWindow : app-on-resume'); - events.emit(WAS_EVENT.RUNTIME.RESUME, 'web_window', self.mainWindow.id); - }); this.mainWindow.webContents.on('crashed', function() { webwindow_debug('WebWindow : webContents crashed'); global.webApplication.exit(100); diff --git a/wrt/src/web_window_tag.js b/wrt/src/web_window_tag.js index ac02405..ae60995 100644 --- a/wrt/src/web_window_tag.js +++ b/wrt/src/web_window_tag.js @@ -154,14 +154,6 @@ class WebWindowTag { this.mainWindow.on('language-changed', function(event, locale) { webwindow_debug('WebWindow : language-changed event = ' + (JSON.stringify(locale))); }); - this.mainWindow.on('app-on-suspend', function() { - webwindow_debug('WebWindow : app-on-suspend'); - events.emit(WAS_EVENT.RUNTIME.SUSPEND, 'web_window', self.mainWindow.id); - }); - this.mainWindow.on('app-on-resume', function() { - webwindow_debug('WebWindow : app-on-resume'); - events.emit(WAS_EVENT.RUNTIME.RESUME, 'web_window', self.mainWindow.id); - }); this.mainWindow.webContents.on('crashed', function() { webwindow_debug('WebWindow : webContents crashed'); global.webApplication.exit(100); -- 2.7.4 From 98e6783c6d8a4ce575a806a7142e8a1dab446992 Mon Sep 17 00:00:00 2001 From: "surya.kumar7" Date: Mon, 5 Mar 2018 16:17:37 +0530 Subject: [PATCH 11/16] Refactor the logic to retrieve the source url from config.xml Change-Id: Ie5292bedc917ab53fabef8db7a2a0d2cee9f3fad --- atom/browser/api/atom_api_pwrt.cc | 3 ++- tizen/common/application_data.h | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/atom/browser/api/atom_api_pwrt.cc b/atom/browser/api/atom_api_pwrt.cc index 766b8cb..e249288 100644 --- a/atom/browser/api/atom_api_pwrt.cc +++ b/atom/browser/api/atom_api_pwrt.cc @@ -32,7 +32,8 @@ std::string PWRT::GetPath() { std::string appid = runtime_cmd->GetAppIdFromCommandLine("/usr/bin/electron"); auto appdata_manager = common::ApplicationDataManager::GetInstance(); common::ApplicationData* app_data = appdata_manager->GetApplicationData(appid); - std::string app_path = "file://" + app_data->application_path() + app_data->content_src(); + // TODO: Use resource-manager's GetStartResource() for localized urls + std::string app_path = "file://" + app_data->application_path() + app_data->content_info()->src(); return app_path; } diff --git a/tizen/common/application_data.h b/tizen/common/application_data.h index eed0347..8f43cae 100644 --- a/tizen/common/application_data.h +++ b/tizen/common/application_data.h @@ -70,7 +70,6 @@ class ApplicationData { const std::string application_path() const { return application_path_; } const std::string pkg_id() const; const std::string app_id() const { return app_id_; } - const std::string content_src() { return (content_info_.get())->src(); } ApplicationData::AppType app_type() { return app_type_; } private: -- 2.7.4 From 0142abc136202966e3bdcbc6de593fa5fea82a9f Mon Sep 17 00:00:00 2001 From: prathmeshm Date: Fri, 23 Feb 2018 16:39:44 +0530 Subject: [PATCH 12/16] Implement Tizen application loop. Change-Id: I4c9487ca7bf3125d7614bb1de0d84c60acb2dd36 Signed-off-by: prathmeshm --- atom/app/atom_main.cc | 22 ++++++- atom/app/runtime.cc | 45 ++++++++++++++ atom/app/runtime.h | 39 ++++++++++++ atom/app/ui_runtime.cc | 115 ++++++++++++++++++++++++++++++++++++ atom/app/ui_runtime.h | 49 +++++++++++++++ atom/browser/api/atom_api_window.cc | 10 ++++ atom/browser/api/atom_api_window.h | 5 ++ atom/browser/browser.cc | 10 ++++ atom/browser/browser.h | 2 + atom/browser/browser_observer.h | 2 + efl/build/system.gyp | 21 +++++++ electron.gyp | 3 + filenames.gypi | 4 ++ wrt/src/runtime.js | 4 +- wrt/src/web_window.js | 8 +++ wrt/src/web_window_tag.js | 8 +++ 16 files changed, 344 insertions(+), 3 deletions(-) create mode 100644 atom/app/runtime.cc create mode 100644 atom/app/runtime.h create mode 100644 atom/app/ui_runtime.cc create mode 100644 atom/app/ui_runtime.h diff --git a/atom/app/atom_main.cc b/atom/app/atom_main.cc index cd51296..c67500f 100644 --- a/atom/app/atom_main.cc +++ b/atom/app/atom_main.cc @@ -37,11 +37,13 @@ #include "base/i18n/icu_util.h" #if defined(OS_TIZEN) +#include + +#include "atom/app/runtime.h" #include "base/logging.h" #include "tizen/common/application_data.h" #include "tizen/common/command_line.h" #include "tizen/loader/prelauncher.h" -#include "base/logging.h" #endif namespace { @@ -136,6 +138,17 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) { #elif defined(OS_LINUX) // defined(OS_WIN) #if defined(OS_TIZEN) +// For debug purpose only. +// TODO: To be removed later +bool hasTizenPackageID(int argc, const char* const* argv) { + if (argc > 3) { + if (0 == strncmp(argv[0], "/opt/usr/globalapps/", strlen("/opt/usr/globalapps/"))) { + return true; + } + } + return false; +} + int real_main(int argc, char* argv[]) { #else int main(int argc, char* argv[]) { @@ -177,6 +190,13 @@ int main(int argc, char* argv[]) { params.argc = argc; params.argv = const_cast(argv); atom::AtomCommandLine::Init(argc, argv); +#if defined(OS_TIZEN) + if (hasTizenPackageID(argc,argv)) { // TODO: Check to be removed later + elm_init(argc, argv); + std::unique_ptr runtime = runtime::Runtime::MakeRuntime(¶ms); + return runtime->Exec(); + } +#endif return content::ContentMain(params); } diff --git a/atom/app/runtime.cc b/atom/app/runtime.cc new file mode 100644 index 0000000..a14e842 --- /dev/null +++ b/atom/app/runtime.cc @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "atom/app/runtime.h" +#include "atom/app/ui_runtime.h" +#include "base/logging.h" + +namespace runtime { + +Runtime::~Runtime() { +} + +std::unique_ptr Runtime::MakeRuntime(content::ContentMainParams *params) { +/* if (app_data->app_type() == common::ApplicationData::UI) { + return std::unique_ptr(new UiRuntime()); + } +#ifdef IME_FEATURE_SUPPORT + else if (app_data->app_type() == common::ApplicationData::IME) { + return std::unique_ptr(new ImeRuntime(app_data)); + } +#endif // IME_FEATURE_SUPPORT +#ifdef WATCH_FACE_FEATURE_SUPPORT + else if (app_data->app_type() == common::ApplicationData::WATCH) { + return std::unique_ptr(new WatchRuntime(app_data)); + } +#endif // WATCH_FACE_FEATURE_SUPPORT + else { */ + return std::unique_ptr(new UiRuntime(params)); + //} +} + +} // namespace runtime \ No newline at end of file diff --git a/atom/app/runtime.h b/atom/app/runtime.h new file mode 100644 index 0000000..baf9001 --- /dev/null +++ b/atom/app/runtime.h @@ -0,0 +1,39 @@ + +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef RUNTIME_H_ +#define RUNTIME_H_ + +#include +#include + +#include "content/public/app/content_main.h" + +namespace runtime { + +class Runtime { + public: + virtual ~Runtime() = 0; + + virtual int Exec() = 0; + + static std::unique_ptr MakeRuntime(content::ContentMainParams *params); +}; + +} // namespace runtime + +#endif // RUNTIME_H_ \ No newline at end of file diff --git a/atom/app/ui_runtime.cc b/atom/app/ui_runtime.cc new file mode 100644 index 0000000..97ef0a9 --- /dev/null +++ b/atom/app/ui_runtime.cc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "atom/app/atom_main_delegate.h" +#include "atom/app/ui_runtime.h" +#include "atom/browser/browser.h" +#include "atom/browser/atom_browser_client.h" +#include "atom/common/atom_command_line.h" +#include "base/logging.h" +#include "content/public/app/content_main.h" + +namespace runtime { + +UiRuntime::UiRuntime(content::ContentMainParams *params) { + _params = params; +} + +UiRuntime::~UiRuntime() { +} + + +bool UiRuntime::OnCreate() { + return true; +} + +void UiRuntime::OnTerminate() { + atom::Browser *browser_model = atom::Browser::Get(); + browser_model->Shutdown(); +} + +void UiRuntime::OnPause() { + LOG(ERROR) << "OnPause()"; + atom::Browser *browser_model = atom::Browser::Get(); + browser_model->Hide(); +} + +void UiRuntime::OnResume() { + LOG(ERROR) << "OnResume()"; + atom::Browser *browser_model = atom::Browser::Get(); + browser_model->Show(); +} + +void UiRuntime::OnAppControl(app_control_h app_control) { + LOG(ERROR) << "OnAppControl()"; +} + +void UiRuntime::OnLanguageChanged(const std::string& language) { + LOG(ERROR) << "OnLanguageChanged()"; +} + +void UiRuntime::OnLowMemory() { + LOG(ERROR) << "OnLowMemory()"; +} + +int UiRuntime::Exec() { + ui_app_lifecycle_callback_s ops = {NULL, NULL, NULL, NULL, NULL}; + + // onCreate + ops.create = [](void* data) -> bool { + + LOG(ERROR) << "Create Tizen App."; + UiRuntime *runtime = (UiRuntime*)data; + content::ContentMain(*runtime->_params); + return true; + }; + + // onTerminate + ops.terminate = [](void* data) -> void { + LOG(ERROR) << "Terminate Tizen App."; + UiRuntime *runtime = (UiRuntime*)data; + runtime->OnTerminate(); + }; + + // onPause + ops.pause = [](void* data) -> void { + LOG(ERROR) << "Pause Tizen App."; + UiRuntime *runtime = (UiRuntime*)data; + runtime->OnPause(); + }; + + // onResume + ops.resume = [](void* data) -> void { + LOG(ERROR) << "Resume Tizen App."; + UiRuntime *runtime = (UiRuntime*)data; + runtime->OnResume(); + }; + + // onAppControl + ops.app_control = [](app_control_h app_control, void* data) -> void { + LOG(ERROR) << "app_control Tizen App."; + UiRuntime *runtime = (UiRuntime*)data; + runtime->OnAppControl(app_control); + }; + + return ui_app_main(_params->argc, const_cast(_params->argv), &ops, this); +} + +} //namespace \ No newline at end of file diff --git a/atom/app/ui_runtime.h b/atom/app/ui_runtime.h new file mode 100644 index 0000000..1c8ec22 --- /dev/null +++ b/atom/app/ui_runtime.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UI_RUNTIME_H_ +#define UI_RUNTIME_H_ + +#include +#include +#include "atom/app/runtime.h" +#include "content/public/app/content_main.h" + +namespace runtime { + +class UiRuntime : public Runtime { + public: + UiRuntime(content::ContentMainParams *params); + virtual ~UiRuntime(); + + virtual int Exec(); + + protected: + virtual bool OnCreate(); + virtual void OnTerminate(); + virtual void OnPause(); + virtual void OnResume(); + virtual void OnAppControl(app_control_h app_control); + virtual void OnLanguageChanged(const std::string& language); + virtual void OnLowMemory(); + + private: + content::ContentMainParams *_params; +}; + +} // namespace runtime + +#endif // XWALK_RUNTIME_BROWSER_UI_RUNTIME_H_ diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 72b8e33..f19fbda 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -310,6 +310,16 @@ void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) { } #endif +#if defined(USE_EFL) +void Window::OnSuspend() { + Emit("app-on-suspend"); +} + +void Window::OnResume() { + Emit("app-on-resume"); +} +#endif + // static mate::WrappableBase* Window::New(mate::Arguments* args) { if (!Browser::Get()->is_ready()) { diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 75f0328..91b5633 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -96,6 +96,11 @@ class Window : public mate::TrackableObject, void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) override; #endif +#if defined(USE_EFL) + void OnSuspend(); + void OnResume(); +#endif + private: void Init(v8::Isolate* isolate, v8::Local wrapper, diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index b2900a3..42cc787 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -213,4 +213,14 @@ void Browser::OnWindowAllClosed() { } } +void Browser::Hide() { + for (BrowserObserver& observer : observers_) + observer.OnSuspend(); +} + +void Browser::Show() { + for (BrowserObserver& observer : observers_) + observer.OnResume(); +} + } // namespace atom diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 78cac65..fc674dd 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -104,6 +104,8 @@ class Browser : public WindowListObserver { void SetLoginItemSettings(LoginItemSettings settings); LoginItemSettings GetLoginItemSettings(const LoginItemSettings& options); + void Hide(); + void Show(); #if defined(OS_MACOSX) // Hide the application. void Hide(); diff --git a/atom/browser/browser_observer.h b/atom/browser/browser_observer.h index 88a50a9..b5760ec 100644 --- a/atom/browser/browser_observer.h +++ b/atom/browser/browser_observer.h @@ -55,6 +55,8 @@ class BrowserObserver { // The browser's accessibility suppport has changed. virtual void OnAccessibilitySupportChanged() {} + virtual void OnSuspend() {} + virtual void OnResume() {} #if defined(OS_MACOSX) // The browser wants to resume a user activity via handoff. (macOS only) virtual void OnContinueUserActivity( diff --git a/efl/build/system.gyp b/efl/build/system.gyp index 8934237..3e0f94f 100644 --- a/efl/build/system.gyp +++ b/efl/build/system.gyp @@ -197,5 +197,26 @@ }], # tizen_product_tv==1 ], }, # vd-win-util + { + 'target_name': 'capi-appfw-application', + 'type': 'none', + 'conditions': [ + ['is_tizen==1', { + 'direct_dependent_settings': { + 'cflags': [ + ' { + events.on(WAS_EVENT.WEBAPPLICATION.RESUME, (sender, id) => { runtime_debug('handleWasMessages: focus ' + id); return _this.onResume(id); }); - events.on(WAS_EVENT.RUNTIME.UNFOCUS, (sender, id) => { + events.on(WAS_EVENT.WEBAPPLICATION.SUSPEND, (sender, id) => { return _this.onPause(id); }); } diff --git a/wrt/src/web_window.js b/wrt/src/web_window.js index 6423300..1baa83a 100644 --- a/wrt/src/web_window.js +++ b/wrt/src/web_window.js @@ -131,6 +131,14 @@ class WebWindow { this.mainWindow.on('language-changed', function(event, locale) { webwindow_debug('WebWindow : language-changed event = ' + (JSON.stringify(locale))); }); + this.mainWindow.on('app-on-suspend', function() { + webwindow_debug('WebWindow : app-on-suspend'); + events.emit(WAS_EVENT.WEBAPPLICATION.SUSPEND, 'web_window', self.mainWindow.id); + }); + this.mainWindow.on('app-on-resume', function() { + webwindow_debug('WebWindow : app-on-resume'); + events.emit(WAS_EVENT.WEBAPPLICATION.RESUME, 'web_window', self.mainWindow.id); + }); this.mainWindow.webContents.on('crashed', function() { webwindow_debug('WebWindow : webContents crashed'); global.webApplication.exit(100); diff --git a/wrt/src/web_window_tag.js b/wrt/src/web_window_tag.js index ae60995..ec77a47 100644 --- a/wrt/src/web_window_tag.js +++ b/wrt/src/web_window_tag.js @@ -154,6 +154,14 @@ class WebWindowTag { this.mainWindow.on('language-changed', function(event, locale) { webwindow_debug('WebWindow : language-changed event = ' + (JSON.stringify(locale))); }); + this.mainWindow.on('app-on-suspend', function() { + webwindow_debug('WebWindow : app-on-suspend'); + events.emit(WAS_EVENT.WEBAPPLICATION.SUSPEND, 'web_window', self.mainWindow.id); + }); + this.mainWindow.on('app-on-resume', function() { + webwindow_debug('WebWindow : app-on-resume'); + events.emit(WAS_EVENT.WEBAPPLICATION.RESUME, 'web_window', self.mainWindow.id); + }); this.mainWindow.webContents.on('crashed', function() { webwindow_debug('WebWindow : webContents crashed'); global.webApplication.exit(100); -- 2.7.4 From 5b05d606f8ebfa38cb35175a8d585e6e38632c39 Mon Sep 17 00:00:00 2001 From: SangYong Park Date: Mon, 12 Mar 2018 14:39:57 +0900 Subject: [PATCH 13/16] Print console messages to dlog Change-Id: I0826b601c629969ca710d298f64e0716b4ad5f88 Signed-off-by: SangYong Park --- atom/browser/api/atom_api_pwrt.cc | 9 ++++++++- atom/browser/api/atom_api_pwrt.h | 1 + lib/browser/init.js | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_pwrt.cc b/atom/browser/api/atom_api_pwrt.cc index e249288..e8a75a6 100644 --- a/atom/browser/api/atom_api_pwrt.cc +++ b/atom/browser/api/atom_api_pwrt.cc @@ -7,6 +7,7 @@ #include "atom/common/node_includes.h" #include "tizen/common/application_data.h" #include "tizen/common/command_line.h" +#include namespace atom { @@ -48,6 +49,11 @@ bool PWRT::isTizenWebApp() { } } +void PWRT::Log(const std::string& message) { + std::string output = "[JS LOG] " + message; + dlog_print(DLOG_INFO, "WRT", output.c_str()); +} + // static mate::Handle PWRT::Create(v8::Isolate* isolate) { LOG(INFO) << "PWRT::Create"; @@ -63,7 +69,8 @@ void PWRT::BuildPrototype( mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetMethod("getMessage", &PWRT::GetMessage) .SetMethod("getPath", &PWRT::GetPath) - .SetMethod("isTizenWebApp", &PWRT::isTizenWebApp); + .SetMethod("isTizenWebApp", &PWRT::isTizenWebApp) + .SetMethod("log", &PWRT::Log); } } // namespace api diff --git a/atom/browser/api/atom_api_pwrt.h b/atom/browser/api/atom_api_pwrt.h index ac466d7..647a5ae 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(); + void Log(const std::string& message); protected: explicit PWRT(v8::Isolate* isolate); diff --git a/lib/browser/init.js b/lib/browser/init.js index b9fe447..308dde7 100644 --- a/lib/browser/init.js +++ b/lib/browser/init.js @@ -42,6 +42,11 @@ if (process.platform === 'win32') { process.stdout.write = process.stderr.write = streamWrite } +let {pwrt} = require('electron'); +console.log = console.error = console.warn = function(...args) { + pwrt.log(util.format(...args)); +}; + // Don't quit on fatal error. process.on('uncaughtException', function (error) { // Do nothing if the user has a custom uncaught exception handler. -- 2.7.4 From 1f0e10afb595b5ae1e61ebeeeab1efeb7571ae69 Mon Sep 17 00:00:00 2001 From: SangYong Park Date: Tue, 13 Mar 2018 16:53:34 +0900 Subject: [PATCH 14/16] Install rpm file after gbs building If target device/emulator is connected, then, install rpm file after gbs building. Change-Id: I32f9d2de9acf71a4865b1a7022a199925aa97979 Signed-off-by: SangYong Park --- tizen/script/build | 6 ++--- tizen/script/gbs.conf | 2 +- tizen/script/install_rpm | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 4 deletions(-) create mode 100755 tizen/script/install_rpm diff --git a/tizen/script/build b/tizen/script/build index 23aceb0..7e8b86e 100755 --- a/tizen/script/build +++ b/tizen/script/build @@ -51,7 +51,8 @@ def main(): else: print 'Error: Fail to find valid profile (Please refer print_list option)' return 1 - build_gbs(profile, args.force_bootstrap, args.verbose) + if build_gbs(profile, args.force_bootstrap, args.verbose): + subprocess.call([sys.executable, os.path.join(SCRIPT_PATH, 'install_rpm')]) else: print 'Error: Cannot found any hint for build profile.' parser.print_help() @@ -121,8 +122,7 @@ def build_gbs(profile, force_bootstrap, verbose): print 'Build : profile=' + profile + ' architecture=' + arch command = ['gbs', '--conf', os.path.join(SCRIPT_PATH, 'gbs.conf'), 'build', '-P', profile, '--include-all', '-A', arch, '--incremental'] - subprocess.call(command) - return True + return True if subprocess.call(command) == 0 else False def find_architecture(profile): if profile.startswith('tztv'): diff --git a/tizen/script/gbs.conf b/tizen/script/gbs.conf index f25aa88..2a16e4b 100755 --- a/tizen/script/gbs.conf +++ b/tizen/script/gbs.conf @@ -63,7 +63,7 @@ url = http://10.113.138.88/tizenrepo/electron_repo/armv7l/ [profile.tz_v4.0_standard_armv7l] obs = obs.tizen_v4.0 repos = repo.electron_armv7l, repo.public_4.0_base_arm, repo.tz_v4.0_standard -buildroot = ~/GBS-ROOT-4.0-STANDARD-ARMV7L2 +buildroot = ~/GBS-ROOT-4.0-STANDARD-ARMV7L ############################################### # diff --git a/tizen/script/install_rpm b/tizen/script/install_rpm new file mode 100755 index 0000000..919b227 --- /dev/null +++ b/tizen/script/install_rpm @@ -0,0 +1,66 @@ +#!/usr/bin/env python + +import argparse +import glob +import os +import subprocess +import sys + +def main(): + parser = argparse.ArgumentParser(description=('Install Programmable Web Runtime RPM')) + parser.add_argument('-r', '--root', help='Specify GBS root path', default='~/GBS-ROOT*') + parser.add_argument('-f', '--file', help='Specify RPM file to install') + args = parser.parse_args() + + rpm_file = args.file if args.file else find_rpm(args.root) + if not rpm_file: + print 'Error: Fail to find RPM file in %s.' % args.root + return 1 + elif not os.path.isfile(rpm_file): + print 'Error: RPM file (%s) is not exist.' % rpm_file + return 1 + + print 'Install RPM file (%s)' % rpm_file + if not install_rpm(rpm_file): + print 'Error: Fail to install RPM file.' + return 1 + print 'Installation is done.' + return 0 + +def find_rpm(root_path): + root_path = os.path.abspath(os.path.expanduser(root_path)) + rpm_path = os.path.join(root_path, 'local', 'repos', '*', '*', 'RPMS') + command = ['find'] + glob.glob(rpm_path) + ['-name', '*.rpm'] + for ex in ['*debug*', '*devel*']: + command += ['-and', '!', '-name', ex] + try: + files = subprocess.check_output(command).strip().split('\n') + files.sort(key=os.path.getmtime, reverse=True) + return files[0] + except subprocess.CalledProcessError: + return None + +def install_rpm(rpm_file): + name = os.path.basename(rpm_file) + units = name.split('.') + package = units[0] + if '-' in package: + package, _ = package.rsplit('-', 1) + arch = units[-2] + target_option = '-d' if arch == 'armv7l' or arch == 'aarch64' else '-e' + try: + subprocess.check_call(['sdb', target_option, 'root', 'on']) + subprocess.check_call(['sdb', target_option, 'push', rpm_file, '/opt/usr']) + subprocess.check_call(['sdb', target_option, 'shell', 'mount', '-o', 'remount,rw', os.sep]) + subprocess.call(['sdb', target_option, 'shell', 'rpm', '-e', package]) + subprocess.check_call(['sdb', target_option, 'shell', 'rpm', '-Uh', '--force', '--nodeps', + os.path.join(os.sep, 'opt', 'usr', name)]) + subprocess.call(['sdb', target_option, 'shell', 'tpk-backend', '--preload', '-y', + 'org.tizen.' + package]) # TODO : check needs + subprocess.call(['sdb', target_option, 'shell', 'reboot', '-f']) + except subprocess.CalledProcessError: + return False + return True + +if __name__ == '__main__': + sys.exit(main()) -- 2.7.4 From 1e66211336d2c6b42b525a3ddbffdddafac77ac5 Mon Sep 17 00:00:00 2001 From: jaekuk lee Date: Tue, 13 Mar 2018 10:43:22 +0000 Subject: [PATCH 15/16] Revert "Print console messages to dlog" This reverts commit 5b05d606f8ebfa38cb35175a8d585e6e38632c39. Change-Id: Iaba35a5b7b43771acf378a743995f6e25a25ca12 --- atom/browser/api/atom_api_pwrt.cc | 9 +-------- atom/browser/api/atom_api_pwrt.h | 1 - lib/browser/init.js | 5 ----- 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/atom/browser/api/atom_api_pwrt.cc b/atom/browser/api/atom_api_pwrt.cc index e8a75a6..e249288 100644 --- a/atom/browser/api/atom_api_pwrt.cc +++ b/atom/browser/api/atom_api_pwrt.cc @@ -7,7 +7,6 @@ #include "atom/common/node_includes.h" #include "tizen/common/application_data.h" #include "tizen/common/command_line.h" -#include namespace atom { @@ -49,11 +48,6 @@ bool PWRT::isTizenWebApp() { } } -void PWRT::Log(const std::string& message) { - std::string output = "[JS LOG] " + message; - dlog_print(DLOG_INFO, "WRT", output.c_str()); -} - // static mate::Handle PWRT::Create(v8::Isolate* isolate) { LOG(INFO) << "PWRT::Create"; @@ -69,8 +63,7 @@ void PWRT::BuildPrototype( mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetMethod("getMessage", &PWRT::GetMessage) .SetMethod("getPath", &PWRT::GetPath) - .SetMethod("isTizenWebApp", &PWRT::isTizenWebApp) - .SetMethod("log", &PWRT::Log); + .SetMethod("isTizenWebApp", &PWRT::isTizenWebApp); } } // namespace api diff --git a/atom/browser/api/atom_api_pwrt.h b/atom/browser/api/atom_api_pwrt.h index 647a5ae..ac466d7 100644 --- a/atom/browser/api/atom_api_pwrt.h +++ b/atom/browser/api/atom_api_pwrt.h @@ -19,7 +19,6 @@ class PWRT : public mate::TrackableObject { std::string GetMessage(); std::string GetPath(); bool isTizenWebApp(); - void Log(const std::string& message); protected: explicit PWRT(v8::Isolate* isolate); diff --git a/lib/browser/init.js b/lib/browser/init.js index 308dde7..b9fe447 100644 --- a/lib/browser/init.js +++ b/lib/browser/init.js @@ -42,11 +42,6 @@ if (process.platform === 'win32') { process.stdout.write = process.stderr.write = streamWrite } -let {pwrt} = require('electron'); -console.log = console.error = console.warn = function(...args) { - pwrt.log(util.format(...args)); -}; - // Don't quit on fatal error. process.on('uncaughtException', function (error) { // Do nothing if the user has a custom uncaught exception handler. -- 2.7.4 From f43e4ca0423d4b540953f5df6286014c2f73d2ba Mon Sep 17 00:00:00 2001 From: jaekuk lee Date: Wed, 14 Mar 2018 07:41:07 +0000 Subject: [PATCH 16/16] Revert "Revert "Print console messages to dlog"" This reverts commit 1e66211336d2c6b42b525a3ddbffdddafac77ac5. Change-Id: I5255a6b28e70da7d84bf8716d4c468b7daac6b18 --- atom/browser/api/atom_api_pwrt.cc | 9 ++++++++- atom/browser/api/atom_api_pwrt.h | 1 + lib/browser/init.js | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_pwrt.cc b/atom/browser/api/atom_api_pwrt.cc index e249288..e8a75a6 100644 --- a/atom/browser/api/atom_api_pwrt.cc +++ b/atom/browser/api/atom_api_pwrt.cc @@ -7,6 +7,7 @@ #include "atom/common/node_includes.h" #include "tizen/common/application_data.h" #include "tizen/common/command_line.h" +#include namespace atom { @@ -48,6 +49,11 @@ bool PWRT::isTizenWebApp() { } } +void PWRT::Log(const std::string& message) { + std::string output = "[JS LOG] " + message; + dlog_print(DLOG_INFO, "WRT", output.c_str()); +} + // static mate::Handle PWRT::Create(v8::Isolate* isolate) { LOG(INFO) << "PWRT::Create"; @@ -63,7 +69,8 @@ void PWRT::BuildPrototype( mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetMethod("getMessage", &PWRT::GetMessage) .SetMethod("getPath", &PWRT::GetPath) - .SetMethod("isTizenWebApp", &PWRT::isTizenWebApp); + .SetMethod("isTizenWebApp", &PWRT::isTizenWebApp) + .SetMethod("log", &PWRT::Log); } } // namespace api diff --git a/atom/browser/api/atom_api_pwrt.h b/atom/browser/api/atom_api_pwrt.h index ac466d7..647a5ae 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(); + void Log(const std::string& message); protected: explicit PWRT(v8::Isolate* isolate); diff --git a/lib/browser/init.js b/lib/browser/init.js index b9fe447..308dde7 100644 --- a/lib/browser/init.js +++ b/lib/browser/init.js @@ -42,6 +42,11 @@ if (process.platform === 'win32') { process.stdout.write = process.stderr.write = streamWrite } +let {pwrt} = require('electron'); +console.log = console.error = console.warn = function(...args) { + pwrt.log(util.format(...args)); +}; + // Don't quit on fatal error. process.on('uncaughtException', function (error) { // Do nothing if the user has a custom uncaught exception handler. -- 2.7.4