#include <memory>
#include "common/logger.h"
+#include "EWebKit_internal.h"
namespace runtime {
NotificationManager::NotificationManager() {
}
+static void notification_onclick_event_cb(
+ notification_h noti, int event_type, void* userdata) {
+ NotificationManager* thiz =
+ static_cast<NotificationManager*>(userdata);
+ int notification_priv_id = NOTIFICATION_PRIV_ID_NONE;
+ int ret = notification_get_id(noti, nullptr, ¬ification_priv_id);
+ if (ret != NOTIFICATION_ERROR_NONE)
+ LOGGER(ERROR) << "Can't get notification ID" << ret;
+ ewk_notification_clicked(thiz->FindNotificationID(notification_priv_id));
+}
+
+uint64_t NotificationManager::FindNotificationID(
+ int notification_priv_id) {
+ for (auto it = keymapper_.begin(); it != keymapper_.end(); it++)
+ if (it->second == notification_priv_id)
+ return it->first;
+ LOGGER(ERROR) << "Can't find notification ID" << notification_priv_id;
+ return 0;
+}
+
bool NotificationManager::Show(uint64_t tag,
const std::string& title,
const std::string& body,
}
// insert notification
- int platform_key = NOTIFICATION_PRIV_ID_NONE;
- ret = notification_insert(noti_h, &platform_key);
+ ret = notification_post_with_event_cb(
+ noti_h, notification_onclick_event_cb, this);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ LOGGER(ERROR) << "Can't insert notification " << ret;
+ return false;
+ }
+
+ int notification_priv_id = NOTIFICATION_PRIV_ID_NONE;
+
+ ret = notification_get_id(noti_h, nullptr, ¬ification_priv_id);
if (ret != NOTIFICATION_ERROR_NONE) {
- LOGGER(ERROR) << "Can't insert notification";
+ LOGGER(ERROR) << "Can't get notification ID" << ret;
return false;
}
- keymapper_[tag] = platform_key;
+ keymapper_[tag] = notification_priv_id;
return true;
}