Add a new api - PWRT::GetPath() 97/171197/1
authormin7.choi <min7.choi@samsung.com>
Tue, 27 Feb 2018 10:11:03 +0000 (19:11 +0900)
committermin7.choi <min7.choi@samsung.com>
Tue, 27 Feb 2018 10:11:07 +0000 (19:11 +0900)
Get the path of app data from JS through the new api

Change-Id: I99ed00f7d62764ba17e2b0dc85d45a0e3d78d5b2
Signed-off-by: min7.choi <min7.choi@samsung.com>
atom/browser/api/atom_api_pwrt.cc
atom/browser/api/atom_api_pwrt.h
wrt/src/web_window.js

index 0938077..248361e 100644 (file)
@@ -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> 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
index 110eac0..f8bf915 100644 (file)
@@ -17,6 +17,7 @@ class PWRT : public mate::TrackableObject<PWRT> {
                              v8::Local<v8::FunctionTemplate> prototype);
 
   std::string GetMessage();
+  std::string GetPath();
 
  protected:
   explicit PWRT(v8::Isolate* isolate);
index 5262e9c..559c61b 100644 (file)
@@ -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();