Initial implementation of watch app 90/184790/2
authorSoorya R <soorya.r@samsung.com>
Fri, 20 Jul 2018 14:04:34 +0000 (19:34 +0530)
committerSoorya R <soorya.r@samsung.com>
Mon, 23 Jul 2018 07:36:09 +0000 (13:06 +0530)
Change-Id: Id5ee0d012756014f94c646504255b15476acb063
Signed-off-by: Soorya R <soorya.r@samsung.com>
atom/app/runtime.cc
atom/app/watch_runtime.cc [new file with mode: 0644]
atom/app/watch_runtime.h [new file with mode: 0644]
atom/browser/native_window_efl.cc
atom/browser/native_window_efl.h
efl/build/system.gyp
packaging/electron-efl.spec
wrt.gyp

index ad61e2d55eb4ae0e0475933e4f107b30af5ff8f7..fcfda5ee47d77fc696573832790e0677eb9ff2ed 100644 (file)
 
 #include "atom/app/runtime.h"
 #include "atom/app/ui_runtime.h"
+#include "atom/app/watch_runtime.h"
+#include "atom/browser/native_window_efl.h"
 #include "base/logging.h"
+#include "efl/window_factory.h"
+#include "tizen/common/application_data.h"
 
 namespace runtime {
 
@@ -31,15 +35,13 @@ std::unique_ptr<Runtime> Runtime::MakeRuntime(content::ContentMainParams *params
   else if (app_data->app_type() == common::ApplicationData::IME) {
     return std::unique_ptr<Runtime>(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<Runtime>(new WatchRuntime(app_data));
-  }
-#endif  // WATCH_FACE_FEATURE_SUPPORT
-  else { */
+#endif  // IME_FEATURE_SUPPORT */
+  auto app_data = common::ApplicationDataManager::GetCurrentAppData();
+  efl::WindowFactory::SetDelegate(&atom::NativeWindowEfl::GetHostWindowDelegate);
+  if (app_data->app_type() == common::ApplicationData::WATCH)
+    return std::unique_ptr<Runtime>(new WatchRuntime(params));
+  else
     return std::unique_ptr<Runtime>(new UiRuntime(params));
-  //}
 }
 
 }  // namespace runtime
diff --git a/atom/app/watch_runtime.cc b/atom/app/watch_runtime.cc
new file mode 100644 (file)
index 0000000..1309b53
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * 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 <app.h>
+#include <string>
+#include <vector>
+#include <watch_app_efl.h>
+
+#include "atom/app/atom_main_delegate.h"
+#include "atom/app/watch_runtime.h"
+#include "atom/browser/atom_browser_client.h"
+#include "atom/browser/atom_browser_main_parts.h"
+#include "atom/browser/browser.h"
+#include "atom/common/atom_command_line.h"
+#include "base/logging.h"
+#include "content/public/app/content_main.h"
+#include "gin/v8_initializer.h"
+#include "tizen/common/app_control.h"
+#include "tizen/common/app_db.h"
+#include "tizen/common/application_data.h"
+#include "tizen/common/command_line.h"
+#include "tizen/common/constants.h"
+
+namespace runtime {
+
+WatchRuntime::WatchRuntime(content::ContentMainParams *params)
+    : _params(params) {
+  // This line's position is essential as this creates the Browser
+  // object which is needed later on by watch_runtime in its watch_loop callbacks
+  atom::AtomBrowserMainParts::SetNodeEnvironment();
+}
+
+WatchRuntime::~WatchRuntime() {
+}
+
+void WatchRuntime::SetParam(content::ContentMainParams *params) {
+  if (_params)
+    LOG(ERROR) << "Use SetParam only when params is null";
+  else
+    _params = params;
+}
+
+bool WatchRuntime::OnCreate() {
+  auto appdata = common::ApplicationDataManager::GetCurrentAppData();
+  if (appdata->splash_screen_info()) {
+    atom::Browser* browser_model = atom::Browser::Get();
+    browser_model->SetSplashScreen();
+  }
+
+  return true;
+}
+
+void WatchRuntime::OnTerminate() {
+  LOG(ERROR) << "OnTerminate()";
+  atom::Browser *browser_model = atom::Browser::Get();
+}
+
+void WatchRuntime::OnPause() {
+  LOG(ERROR) << "OnPause()";
+  atom::Browser *browser_model = atom::Browser::Get();
+  browser_model->Hide();
+}
+
+void WatchRuntime::OnResume() {
+  LOG(ERROR) << "OnResume()";
+  atom::Browser *browser_model = atom::Browser::Get();
+  browser_model->Show();
+}
+
+void WatchRuntime::OnAppControl(app_control_h app_control) {
+  LOG(ERROR) << "OnAppControl()";
+  std::unique_ptr<common::AppControl>
+      appcontrol(new common::AppControl(app_control));
+  common::AppDB* appdb = common::AppDB::GetInstance();
+  appdb->Set(kAppDBRuntimeSection, kAppDBRuntimeBundle,
+             appcontrol->encoded_bundle());
+  atom::Browser *browser_model = atom::Browser::Get();
+  if (browser_model->launched()) {
+   browser_model->AppControl(std::move(appcontrol));
+  } else {
+   browser_model->Initialize();
+   browser_model->Launch(std::move(appcontrol));
+  }
+}
+
+void WatchRuntime::OnLanguageChanged(const std::string& language) {
+  LOG(ERROR) << "OnLanguageChanged()";
+}
+
+void WatchRuntime::OnLowMemory() {
+  LOG(ERROR) << "OnLowMemory()";
+}
+
+int WatchRuntime::Exec() {
+  watch_app_lifecycle_callback_s ops = {NULL, NULL, NULL, NULL, NULL};
+
+  // onCreate
+  ops.create = [](int width, int height, void *data) -> bool {
+    LOG(ERROR) << "Create Tizen App.";
+    WatchRuntime *runtime = (WatchRuntime*)data;
+    runtime->OnCreate();
+    content::ContentMain(*runtime->_params);
+    return true;
+  };
+
+  // onTerminate
+  ops.terminate = [](void* data) -> void {
+    LOG(ERROR) << "Terminate Tizen App.";
+    WatchRuntime *runtime = (WatchRuntime*)data;
+    runtime->OnTerminate();
+  };
+
+  // onPause
+  ops.pause = [](void* data) -> void {
+    LOG(ERROR) << "Pause Tizen App.";
+    WatchRuntime *runtime = (WatchRuntime*)data;
+    runtime->OnPause();
+  };
+
+  // onResume
+  ops.resume = [](void* data) -> void {
+    LOG(ERROR) << "Resume Tizen App.";
+    WatchRuntime *runtime = (WatchRuntime*)data;
+    runtime->OnResume();
+  };
+
+  // onAppControl
+  ops.app_control = [](app_control_h app_control, void* data) -> void {
+    LOG(ERROR) << "app_control Tizen App.";
+    WatchRuntime *runtime = (WatchRuntime*)data;
+    runtime->OnAppControl(app_control);
+  };
+
+  return watch_app_main(_params->argc, const_cast<char**>(_params->argv), &ops, this);
+}
+} //namespace
diff --git a/atom/app/watch_runtime.h b/atom/app/watch_runtime.h
new file mode 100644 (file)
index 0000000..43636bc
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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 WATCH_RUNTIME_H_
+#define WATCH_RUNTIME_H_
+
+#include <app.h>
+#include <string>
+#include <watch_app.h>
+#include "atom/app/runtime.h"
+#include "content/public/app/content_main.h"
+
+namespace runtime {
+
+class WatchRuntime : public Runtime {
+ public:
+  WatchRuntime(content::ContentMainParams *params);
+  virtual ~WatchRuntime();
+
+  virtual int Exec();
+  virtual void SetParam(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();
+
+ private:
+  content::ContentMainParams *_params;
+};
+
+}  // namespace runtime
+
+#endif  // XWALK_RUNTIME_BROWSER_WATCH_RUNTIME_H_
index bcbe50975382167d73722a20e598bd14bd5f32dc..b71e5638a509320c1837df0108f0e408c68f2559 100644 (file)
@@ -5,11 +5,14 @@
 #include "atom/browser/native_window_efl.h"
 
 #include <Elementary.h>
+#include <map>
+#include <watch_app_efl.h>
 
 #include "atom/common/options_switches.h"
 #include "base/command_line.h"
 #include "content/public/browser/web_contents.h"
 #include "efl/window_factory.h"
+#include "tizen/common/application_data.h"
 #include "ui/gfx/geometry/rect.h"
 #include "ui/gfx/geometry/size.h"
 #include "ui/gfx/image/image.h"
@@ -31,6 +34,7 @@ namespace atom {
 
 namespace {
 
+std::map<const content::WebContents*, Evas_Object*> window_map_;
 const int kDefaultWindowWidthDip = 800;
 const int kDefaultWindowHeightDip = 600;
 
@@ -58,6 +62,28 @@ const char* kMenuKeyEventScript =
 #endif
 }
 
+Evas_Object* NativeWindowEfl::GetHostWindowDelegate(const content::WebContents* web_contents) {
+  LOG(ERROR) << "NativeWindowEfl::GetHostWindowDelegate";
+  if (window_map_.find(web_contents) != window_map_.end())
+    return window_map_[web_contents];
+
+  Evas_Object* win = NULL;
+  auto app_data = common::ApplicationDataManager::GetCurrentAppData();
+  if (app_data->app_type() == common::ApplicationData::WATCH) {
+    elm_config_accel_preference_set("opengl");
+    watch_app_get_elm_win(&win);
+    elm_win_alpha_set(win, EINA_TRUE);
+    evas_object_render_op_set(win, EVAS_RENDER_COPY);
+  }
+  else {
+    win = elm_win_util_standard_add("", "");
+    elm_win_autodel_set(win, EINA_TRUE);
+  }
+
+  window_map_[web_contents] = win;
+  return win;
+}
+
 NativeWindowEfl::NativeWindowEfl(
     brightray::InspectableWebContents* inspectable_web_contents,
     const mate::Dictionary& options,
index b7f40249b6ca006ad5c24857235f6f79a348da14..5d93937bb1dc3bdfd3d4a4641e9e6b321613d1e1 100644 (file)
@@ -6,6 +6,7 @@
 #define ATOM_BROWSER_NATIVE_WINDOW_EFL_H_
 
 #include "atom/browser/native_window.h"
+#include "content/public/browser/web_contents_delegate.h"
 
 #include <Evas.h>
 
@@ -26,6 +27,8 @@ class NativeWindowEfl : public NativeWindow {
                            const mate::Dictionary& options,
                            NativeWindow* parent);
 
+  static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
+
   void Close() override;
   void CloseImmediately() override;
   void Focus(bool focus) override;
index c15c218cbad98da4f47930208be473472ce0d77e..2d41270ba74b20b1e4958085a889df346d04428b 100644 (file)
         }],
       ],
     }, # capi-media-player
+    {
+      'target_name': 'capi-appfw-watch-application',
+      'type': 'none',
+      'conditions': [
+        ['is_tizen==1', {
+          'direct_dependent_settings': {
+            'cflags': [
+              '<!@(<(pkg-config) --cflags capi-appfw-watch-application)',
+            ],
+          },
+          'link_settings': {
+            'ldflags': [
+              '<!@(<(pkg-config) --libs-only-L --libs-only-other capi-appfw-watch-application)',
+            ],
+            'libraries': [
+              '<!@(<(pkg-config) --libs-only-l capi-appfw-watch-application)',
+            ],
+          },
+        }],
+      ],
+    }, # capi-appfw-watch-application
+    {
+      'target_name': 'appcore-watch',
+      'type': 'none',
+      'conditions': [
+        ['is_tizen==1', {
+          'direct_dependent_settings': {
+            'cflags': [
+              '<!@(<(pkg-config) --cflags appcore-watch)',
+            ],
+          },
+          'link_settings': {
+            'ldflags': [
+              '<!@(<(pkg-config) --libs-only-L --libs-only-other appcore-watch)',
+            ],
+            'libraries': [
+              '<!@(<(pkg-config) --libs-only-l appcore-watch)',
+            ],
+          },
+        }],
+      ],
+    }, # appcore-watch
   ],
 }
index 88fc0097e375c63575ccb3cd957494698d323a07..a646f07ad7f34620dc791135aaf2471e19797ce5 100755 (executable)
@@ -17,12 +17,14 @@ BuildRequires: python-accel-armv7l-cross-arm
 %ifarch aarch64
 BuildRequires: python-accel-aarch64-cross-aarch64
 %endif
+BuildRequires: pkgconfig(appcore-watch)
 BuildRequires: pkgconfig(appsvc)
 BuildRequires: pkgconfig(aul)
 BuildRequires: pkgconfig(bundle)
 BuildRequires: pkgconfig(capi-appfw-application)
 BuildRequires: pkgconfig(capi-appfw-app-manager)
 BuildRequires: pkgconfig(capi-appfw-package-manager)
+BuildRequires: pkgconfig(capi-appfw-watch-application)
 BuildRequires: pkgconfig(capi-system-system-settings)
 BuildRequires: pkgconfig(capi-system-info)
 BuildRequires: pkgconfig(chromium-efl)
diff --git a/wrt.gyp b/wrt.gyp
index 5941ad9e3befa51895d8b6f3959031c3f64814ab..36af55341281307ae1f914e5fa08b03f057ba8b2 100644 (file)
--- a/wrt.gyp
+++ b/wrt.gyp
@@ -97,6 +97,8 @@
         'atom/app/runtime.h',
         'atom/app/ui_runtime.cc',
         'atom/app/ui_runtime.h',
+        'atom/app/watch_runtime.cc',
+        'atom/app/watch_runtime.h',
         'atom/browser/api/atom_api_menu_efl.cc',
         'atom/browser/api/atom_api_menu_efl.h',
         'atom/browser/api/atom_api_web_contents_efl.cc',
           'cflags': [ '-fPIC' ],
           'cflags_cc': [ '-fPIC' ],
           'dependencies': [
+            '<(DEPTH)/efl/build/system.gyp:appcore-watch',
             '<(DEPTH)/efl/build/system.gyp:capi-appfw-application',
+            '<(DEPTH)/efl/build/system.gyp:capi-appfw-watch-application',
             '<(DEPTH)/efl/build/system.gyp:efl-extension',
             '<(DEPTH)/efl/build/system.gyp:elementary',
             '<(DEPTH)/efl/build/system.gyp:evas',