Make Notification
factory function a member of NotificationPresenter
so that we can create different types of notifications based on runtime conditions.
This commit is contained in:
parent
0981807261
commit
e6a30388da
12 changed files with 22 additions and 26 deletions
|
@ -55,12 +55,6 @@ void log_and_clear_error(GError* error, const char* context) {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// static
|
|
||||||
Notification* Notification::Create(NotificationDelegate* delegate,
|
|
||||||
NotificationPresenter* presenter) {
|
|
||||||
return new LibnotifyNotification(delegate, presenter);
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
// static
|
||||||
bool LibnotifyNotification::Initialize() {
|
bool LibnotifyNotification::Initialize() {
|
||||||
if (!libnotify_loader_.Load("libnotify.so.4") && // most common one
|
if (!libnotify_loader_.Load("libnotify.so.4") && // most common one
|
||||||
|
|
|
@ -22,4 +22,8 @@ NotificationPresenterLinux::NotificationPresenterLinux() {
|
||||||
NotificationPresenterLinux::~NotificationPresenterLinux() {
|
NotificationPresenterLinux::~NotificationPresenterLinux() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Notification* NotificationPresenterLinux::CreateNotificationObject(NotificationDelegate* delegate) {
|
||||||
|
return new LibnotifyNotification(delegate, this);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -16,6 +16,8 @@ class NotificationPresenterLinux : public NotificationPresenter {
|
||||||
~NotificationPresenterLinux();
|
~NotificationPresenterLinux();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Notification* CreateNotificationObject(NotificationDelegate* delegate) override;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(NotificationPresenterLinux);
|
DISALLOW_COPY_AND_ASSIGN(NotificationPresenterLinux);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,6 @@
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
// static
|
|
||||||
Notification* Notification::Create(NotificationDelegate* delegate,
|
|
||||||
NotificationPresenter* presenter) {
|
|
||||||
return new CocoaNotification(delegate, presenter);
|
|
||||||
}
|
|
||||||
|
|
||||||
CocoaNotification::CocoaNotification(NotificationDelegate* delegate,
|
CocoaNotification::CocoaNotification(NotificationDelegate* delegate,
|
||||||
NotificationPresenter* presenter)
|
NotificationPresenter* presenter)
|
||||||
: Notification(delegate, presenter) {
|
: Notification(delegate, presenter) {
|
||||||
|
|
|
@ -22,6 +22,8 @@ class NotificationPresenterMac : public NotificationPresenter {
|
||||||
~NotificationPresenterMac();
|
~NotificationPresenterMac();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Notification* CreateNotificationObject(NotificationDelegate* delegate) override;
|
||||||
|
|
||||||
base::scoped_nsobject<NotificationCenterDelegate>
|
base::scoped_nsobject<NotificationCenterDelegate>
|
||||||
notification_center_delegate_;
|
notification_center_delegate_;
|
||||||
|
|
||||||
|
|
|
@ -35,4 +35,8 @@ NotificationPresenterMac::~NotificationPresenterMac() {
|
||||||
NSUserNotificationCenter.defaultUserNotificationCenter.delegate = nil;
|
NSUserNotificationCenter.defaultUserNotificationCenter.delegate = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Notification* NotificationPresenterMac::CreateNotificationObject(NotificationDelegate* delegate) {
|
||||||
|
return new CocoaNotification(delegate, this);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -47,16 +47,10 @@ class Notification {
|
||||||
protected:
|
protected:
|
||||||
Notification(NotificationDelegate* delegate,
|
Notification(NotificationDelegate* delegate,
|
||||||
NotificationPresenter* presenter);
|
NotificationPresenter* presenter);
|
||||||
|
public:
|
||||||
virtual ~Notification();
|
virtual ~Notification();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class NotificationPresenter;
|
|
||||||
|
|
||||||
// Can only be called by NotificationPresenter, the caller is responsible of
|
|
||||||
// freeing the returned instance.
|
|
||||||
static Notification* Create(NotificationDelegate* delegate,
|
|
||||||
NotificationPresenter* presenter);
|
|
||||||
|
|
||||||
NotificationDelegate* delegate_;
|
NotificationDelegate* delegate_;
|
||||||
NotificationPresenter* presenter_;
|
NotificationPresenter* presenter_;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,8 @@ NotificationPresenter::~NotificationPresenter() {
|
||||||
|
|
||||||
base::WeakPtr<Notification> NotificationPresenter::CreateNotification(
|
base::WeakPtr<Notification> NotificationPresenter::CreateNotification(
|
||||||
NotificationDelegate* delegate) {
|
NotificationDelegate* delegate) {
|
||||||
Notification* notification = Notification::Create(delegate, this);
|
Notification* notification = CreateNotificationObject(delegate);
|
||||||
|
if (!notification) return {};
|
||||||
notifications_.insert(notification);
|
notifications_.insert(notification);
|
||||||
return notification->GetWeakPtr();
|
return notification->GetWeakPtr();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ class NotificationPresenter {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NotificationPresenter();
|
NotificationPresenter();
|
||||||
|
virtual Notification* CreateNotificationObject(NotificationDelegate* delegate) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class Notification;
|
friend class Notification;
|
||||||
|
|
|
@ -66,4 +66,8 @@ base::string16 NotificationPresenterWin::SaveIconToFilesystem(
|
||||||
return base::UTF8ToUTF16(origin.spec());
|
return base::UTF8ToUTF16(origin.spec());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Notification* NotificationPresenterWin::CreateNotificationObject(NotificationDelegate* delegate) {
|
||||||
|
return new WindowsToastNotification(delegate, this);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -42,6 +42,8 @@ class NotificationPresenterWin : public NotificationPresenter {
|
||||||
base::string16 SaveIconToFilesystem(const SkBitmap& icon, const GURL& origin);
|
base::string16 SaveIconToFilesystem(const SkBitmap& icon, const GURL& origin);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Notification* CreateNotificationObject(NotificationDelegate* delegate) override;
|
||||||
|
|
||||||
base::ScopedTempDir temp_dir_;
|
base::ScopedTempDir temp_dir_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin);
|
DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin);
|
||||||
|
|
|
@ -42,12 +42,6 @@ bool GetAppUserModelId(ScopedHString* app_id) {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// static
|
|
||||||
Notification* Notification::Create(NotificationDelegate* delegate,
|
|
||||||
NotificationPresenter* presenter) {
|
|
||||||
return new WindowsToastNotification(delegate, presenter);
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
// static
|
||||||
ComPtr<ABI::Windows::UI::Notifications::IToastNotificationManagerStatics>
|
ComPtr<ABI::Windows::UI::Notifications::IToastNotificationManagerStatics>
|
||||||
WindowsToastNotification::toast_manager_;
|
WindowsToastNotification::toast_manager_;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue