Merge pull request #99 from paulcbetts/ubuntu-notifications
Ubuntu notification improvements
This commit is contained in:
commit
b62896d571
6 changed files with 60 additions and 3 deletions
|
@ -8,14 +8,52 @@
|
||||||
#include "base/bind.h"
|
#include "base/bind.h"
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
|
#include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h"
|
||||||
#include "content/public/browser/desktop_notification_delegate.h"
|
#include "content/public/browser/desktop_notification_delegate.h"
|
||||||
#include "content/public/common/platform_notification_data.h"
|
#include "content/public/common/platform_notification_data.h"
|
||||||
#include "common/application_info.h"
|
#include "common/application_info.h"
|
||||||
|
#include "dbus/dbus.h"
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
static bool unity_has_result = false;
|
||||||
|
static bool unity_result = false;
|
||||||
|
|
||||||
|
static bool UnityIsRunning() {
|
||||||
|
if (unity_has_result) {
|
||||||
|
return unity_result;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DBusError err;
|
||||||
|
struct DBusConnection* bus = NULL;
|
||||||
|
|
||||||
|
dbus_error_init(&err);
|
||||||
|
|
||||||
|
bus = dbus_bus_get(DBUS_BUS_SESSION, &err);
|
||||||
|
if (dbus_error_is_set(&err)) {
|
||||||
|
g_debug("Failed to get Session Bus reference");
|
||||||
|
unity_result = false;
|
||||||
|
dbus_error_free(&err);
|
||||||
|
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
unity_result = dbus_bus_name_has_owner(bus, "com.canonical.indicator.session", &err);
|
||||||
|
|
||||||
|
if (dbus_error_is_set(&err)) {
|
||||||
|
unity_result = false;
|
||||||
|
dbus_error_free(&err);
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (bus) dbus_connection_unref(bus);
|
||||||
|
|
||||||
|
unity_has_result = true;
|
||||||
|
return unity_result;
|
||||||
|
}
|
||||||
|
|
||||||
void log_and_clear_error(GError* error, const char* context) {
|
void log_and_clear_error(GError* error, const char* context) {
|
||||||
LOG(ERROR) << context
|
LOG(ERROR) << context
|
||||||
<< ": domain=" << error->domain
|
<< ": domain=" << error->domain
|
||||||
|
@ -52,6 +90,7 @@ NotificationPresenterLinux::~NotificationPresenterLinux() {
|
||||||
|
|
||||||
void NotificationPresenterLinux::ShowNotification(
|
void NotificationPresenterLinux::ShowNotification(
|
||||||
const content::PlatformNotificationData& data,
|
const content::PlatformNotificationData& data,
|
||||||
|
const SkBitmap& icon,
|
||||||
scoped_ptr<content::DesktopNotificationDelegate> delegate_ptr,
|
scoped_ptr<content::DesktopNotificationDelegate> delegate_ptr,
|
||||||
base::Closure* cancel_callback) {
|
base::Closure* cancel_callback) {
|
||||||
std::string title = base::UTF16ToUTF8(data.title);
|
std::string title = base::UTF16ToUTF8(data.title);
|
||||||
|
@ -62,8 +101,20 @@ void NotificationPresenterLinux::ShowNotification(
|
||||||
|
|
||||||
g_object_set_data_full(G_OBJECT(notification), "delegate", delegate, operator delete);
|
g_object_set_data_full(G_OBJECT(notification), "delegate", delegate, operator delete);
|
||||||
g_signal_connect(notification, "closed", G_CALLBACK(OnNotificationClosedThunk), this);
|
g_signal_connect(notification, "closed", G_CALLBACK(OnNotificationClosedThunk), this);
|
||||||
notify_notification_add_action(notification, "default", "View", OnNotificationViewThunk, this,
|
|
||||||
nullptr);
|
// NB: On Unity, adding a notification action will cause the notification
|
||||||
|
// to display as a modal dialog box. Testing for distros that have "Unity
|
||||||
|
// Zen Nature" is difficult, we will test for the presence of the indicate
|
||||||
|
// dbus service
|
||||||
|
if (!UnityIsRunning()) {
|
||||||
|
notify_notification_add_action(notification, "default", "View", OnNotificationViewThunk, this, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
GdkPixbuf* pixbuf = libgtk2ui::GdkPixbufFromSkBitmap(icon);
|
||||||
|
|
||||||
|
notify_notification_set_image_from_pixbuf(notification, pixbuf);
|
||||||
|
notify_notification_set_timeout(notification, NOTIFY_EXPIRES_DEFAULT);
|
||||||
|
g_object_unref(pixbuf);
|
||||||
|
|
||||||
GError* error = nullptr;
|
GError* error = nullptr;
|
||||||
notify_notification_show(notification, &error);
|
notify_notification_show(notification, &error);
|
||||||
|
|
|
@ -27,6 +27,7 @@ class NotificationPresenterLinux : public NotificationPresenter {
|
||||||
// NotificationPresenter:
|
// NotificationPresenter:
|
||||||
void ShowNotification(
|
void ShowNotification(
|
||||||
const content::PlatformNotificationData&,
|
const content::PlatformNotificationData&,
|
||||||
|
const SkBitmap& icon,
|
||||||
scoped_ptr<content::DesktopNotificationDelegate> delegate,
|
scoped_ptr<content::DesktopNotificationDelegate> delegate,
|
||||||
base::Closure* cancel_callback) override;
|
base::Closure* cancel_callback) override;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
#include "base/callback_forward.h"
|
#include "base/callback_forward.h"
|
||||||
#include "base/memory/scoped_ptr.h"
|
#include "base/memory/scoped_ptr.h"
|
||||||
|
|
||||||
|
class SkBitmap;
|
||||||
|
|
||||||
namespace content {
|
namespace content {
|
||||||
class DesktopNotificationDelegate;
|
class DesktopNotificationDelegate;
|
||||||
struct PlatformNotificationData;
|
struct PlatformNotificationData;
|
||||||
|
@ -19,6 +21,7 @@ class NotificationPresenter {
|
||||||
|
|
||||||
virtual void ShowNotification(
|
virtual void ShowNotification(
|
||||||
const content::PlatformNotificationData&,
|
const content::PlatformNotificationData&,
|
||||||
|
const SkBitmap& icon,
|
||||||
scoped_ptr<content::DesktopNotificationDelegate> delegate,
|
scoped_ptr<content::DesktopNotificationDelegate> delegate,
|
||||||
base::Closure* cancel_callback) = 0;
|
base::Closure* cancel_callback) = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,6 +23,7 @@ class NotificationPresenterMac : public NotificationPresenter {
|
||||||
// NotificationPresenter:
|
// NotificationPresenter:
|
||||||
void ShowNotification(
|
void ShowNotification(
|
||||||
const content::PlatformNotificationData&,
|
const content::PlatformNotificationData&,
|
||||||
|
const SkBitmap& icon,
|
||||||
scoped_ptr<content::DesktopNotificationDelegate> delegate,
|
scoped_ptr<content::DesktopNotificationDelegate> delegate,
|
||||||
base::Closure* cancel_callback) override;
|
base::Closure* cancel_callback) override;
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ NotificationPresenterMac::~NotificationPresenterMac() {
|
||||||
|
|
||||||
void NotificationPresenterMac::ShowNotification(
|
void NotificationPresenterMac::ShowNotification(
|
||||||
const content::PlatformNotificationData& data,
|
const content::PlatformNotificationData& data,
|
||||||
|
const SkBitmap& icon,
|
||||||
scoped_ptr<content::DesktopNotificationDelegate> delegate,
|
scoped_ptr<content::DesktopNotificationDelegate> delegate,
|
||||||
base::Closure* cancel_callback) {
|
base::Closure* cancel_callback) {
|
||||||
auto notification = [[NSUserNotification alloc] init];
|
auto notification = [[NSUserNotification alloc] init];
|
||||||
|
|
|
@ -44,7 +44,7 @@ void PlatformNotificationServiceImpl::DisplayNotification(
|
||||||
base::Closure* cancel_callback) {
|
base::Closure* cancel_callback) {
|
||||||
auto presenter = notification_presenter();
|
auto presenter = notification_presenter();
|
||||||
if (presenter)
|
if (presenter)
|
||||||
presenter->ShowNotification(notification_data, delegate.Pass(), cancel_callback);
|
presenter->ShowNotification(notification_data, icon, delegate.Pass(), cancel_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlatformNotificationServiceImpl::DisplayPersistentNotification(
|
void PlatformNotificationServiceImpl::DisplayPersistentNotification(
|
||||||
|
|
Loading…
Reference in a new issue