Support Windows 7 notifications from brightray

This commit is contained in:
Samuel Attard 2017-04-24 09:47:18 +10:00
parent a4bd26fab0
commit 6bbc4c3113
No known key found for this signature in database
GPG key ID: 273DC1869D8F13EF
5 changed files with 85 additions and 9 deletions

View file

@ -4,10 +4,16 @@
#include "atom/browser/api/atom_api_notification.h"
#include "atom/browser/ui/notification_delegate_adapter.h"
#include "atom/browser/ui/win/toast_handler.h"
#include "atom/browser/ui/win/toast_lib.h"
#include "base/strings/utf_string_conversions.h"
#include "browser/notification.h"
#include "browser/notification_presenter.h"
#include "browser/win/notification_presenter_win7.h"
#include "common/string_conversion.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "url/gurl.h"
namespace atom {
@ -15,8 +21,10 @@ namespace api {
bool can_toast_ = true;
bool initialized_ = false;
brightray::NotificationPresenter* presenter;
void Notification::Show() {
if (can_toast_) {
atom::AtomToastHandler* handler = new atom::AtomToastHandler(this);
WinToastLib::WinToastTemplate toast = WinToastLib::WinToastTemplate(WinToastLib::WinToastTemplate::TextTwoLines);
// toast.setImagePath(L"C:\example.png");
@ -27,6 +35,19 @@ void Notification::Show() {
WinToastLib::WinToast::instance()->showToast(toast, handler);
OnShown();
} else {
AtomNotificationDelegateAdapter* adapter = new AtomNotificationDelegateAdapter(this);
auto notif = presenter->CreateNotification(adapter);
GURL* u = new GURL;
notif->Show(
title_,
body_,
"",
u->Resolve(""),
*(new SkBitmap),
true
);
}
}
void Notification::OnInitialProps() {
@ -37,6 +58,10 @@ void Notification::OnInitialProps() {
);
can_toast_ = WinToastLib::WinToast::instance()->initialize();
}
can_toast_ = false;
if (!can_toast_) {
presenter = new brightray::NotificationPresenterWin7;
}
}
void Notification::NotifyPropsUpdated() {

View file

@ -0,0 +1,21 @@
#include "atom/browser/ui/notification_delegate_adapter.h"
#include "atom/browser/api/atom_api_notification.h"
#include "browser/notification_delegate.h"
namespace atom {
AtomNotificationDelegateAdapter::AtomNotificationDelegateAdapter(atom::api::Notification* target) {
observer_ = target;
}
void AtomNotificationDelegateAdapter::NotificationDisplayed() {
observer_->OnShown();
}
void AtomNotificationDelegateAdapter::NotificationClosed() {}
void AtomNotificationDelegateAdapter::NotificationClick() {
observer_->OnClicked();
}
void AtomNotificationDelegateAdapter::NotificationDestroyed() {}
void AtomNotificationDelegateAdapter::NotificationFailed() {}
}

View file

@ -0,0 +1,28 @@
// Copyright (c) 2014 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "browser/notification_delegate.h"
#include "atom/browser/api/atom_api_notification.h"
#ifndef ATOM_BROWSER_UI_NOTIFICATION_DELEGATE_ADAPTER_H_
#define ATOM_BROWSER_UI_NOTIFICATION_DELEGATE_ADAPTER_H_
namespace atom {
class AtomNotificationDelegateAdapter : public brightray::NotificationDelegate {
public:
atom::api::Notification* observer_;
AtomNotificationDelegateAdapter(atom::api::Notification* target);
void NotificationDisplayed();
void NotificationClosed();
void NotificationClick();
void NotificationDestroyed();
void NotificationFailed();
};
}
#endif // ATOM_BROWSER_UI_NOTIFICATION_DELEGATE_ADAPTER_H_

View file

@ -34,7 +34,7 @@ exports.load = (appUrl) => {
silent: true,
icon: '/Users/samuel/Downloads/ninja.png',
hasReply: true,
replyPlacehodler: 'Type Here!!'
replyPlaceholder: 'Type Here!!'
});
n.on('show', () => console.log('showed'));
n.on('click', () => console.info('clicked!!'));

View file

@ -315,6 +315,8 @@
'atom/browser/ui/message_box_gtk.cc',
'atom/browser/ui/message_box_mac.mm',
'atom/browser/ui/message_box_win.cc',
'atom/browser/ui/notification_delegate_adapter.h',
'atom/browser/ui/notification_delegate_adapter.cc',
'atom/browser/ui/notification_observer.h',
'atom/browser/ui/tray_icon.cc',
'atom/browser/ui/tray_icon.h',