electron/shell/browser/api/electron_api_notification.h

124 lines
3.9 KiB
C
Raw Normal View History

// Copyright (c) 2014 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ELECTRON_API_NOTIFICATION_H_
#define SHELL_BROWSER_API_ELECTRON_API_NOTIFICATION_H_
#include <memory>
#include <string>
#include <vector>
2017-04-23 22:14:35 +00:00
#include "base/strings/utf_string_conversions.h"
2020-03-31 18:42:32 +00:00
#include "gin/wrappable.h"
#include "shell/browser/event_emitter_mixin.h"
#include "shell/browser/notifications/notification.h"
#include "shell/browser/notifications/notification_delegate.h"
#include "shell/browser/notifications/notification_presenter.h"
2020-03-31 18:42:32 +00:00
#include "shell/common/gin_helper/cleaned_up_at_exit.h"
#include "shell/common/gin_helper/constructible.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "ui/gfx/image/image.h"
namespace gin {
class Arguments;
2020-03-31 18:42:32 +00:00
template <typename T>
class Handle;
} // namespace gin
namespace electron {
namespace api {
2020-03-31 18:42:32 +00:00
class Notification : public gin::Wrappable<Notification>,
public gin_helper::EventEmitterMixin<Notification>,
public gin_helper::Constructible<Notification>,
public gin_helper::CleanedUpAtExit,
public NotificationDelegate {
public:
2017-05-30 10:27:24 +00:00
static bool IsSupported();
2020-03-31 18:42:32 +00:00
// gin_helper::Constructible
static gin::Handle<Notification> New(gin_helper::ErrorThrower thrower,
gin::Arguments* args);
static v8::Local<v8::ObjectTemplate> FillObjectTemplate(
v8::Isolate*,
v8::Local<v8::ObjectTemplate>);
2017-05-30 09:06:51 +00:00
// NotificationDelegate:
void NotificationAction(int index) override;
2017-05-30 09:06:51 +00:00
void NotificationClick() override;
2017-05-31 07:17:29 +00:00
void NotificationReplied(const std::string& reply) override;
2017-05-30 09:06:51 +00:00
void NotificationDisplayed() override;
void NotificationDestroyed() override;
void NotificationClosed() override;
void NotificationFailed(const std::string& error) override;
2020-03-31 18:42:32 +00:00
// gin::Wrappable
static gin::WrapperInfo kWrapperInfo;
protected:
explicit Notification(gin::Arguments* args);
~Notification() override;
void Show();
void Close();
// Prop Getters
base::string16 GetTitle() const;
base::string16 GetSubtitle() const;
base::string16 GetBody() const;
bool GetSilent() const;
bool GetHasReply() const;
base::string16 GetTimeoutType() const;
2018-01-22 18:48:12 +00:00
base::string16 GetReplyPlaceholder() const;
base::string16 GetUrgency() const;
2017-08-21 20:53:50 +00:00
base::string16 GetSound() const;
std::vector<electron::NotificationAction> GetActions() const;
2018-01-16 19:26:41 +00:00
base::string16 GetCloseButtonText() const;
base::string16 GetToastXml() const;
// Prop Setters
2017-05-30 09:06:51 +00:00
void SetTitle(const base::string16& new_title);
void SetSubtitle(const base::string16& new_subtitle);
2017-05-30 09:06:51 +00:00
void SetBody(const base::string16& new_body);
void SetSilent(bool new_silent);
void SetHasReply(bool new_has_reply);
void SetUrgency(const base::string16& new_urgency);
void SetTimeoutType(const base::string16& new_timeout_type);
2018-01-22 18:48:12 +00:00
void SetReplyPlaceholder(const base::string16& new_reply_placeholder);
2017-08-21 20:53:50 +00:00
void SetSound(const base::string16& sound);
void SetActions(const std::vector<electron::NotificationAction>& actions);
2018-01-16 19:26:41 +00:00
void SetCloseButtonText(const base::string16& text);
void SetToastXml(const base::string16& text);
private:
2017-05-30 09:06:51 +00:00
base::string16 title_;
base::string16 subtitle_;
2017-05-30 09:06:51 +00:00
base::string16 body_;
gfx::Image icon_;
2017-05-30 09:06:51 +00:00
base::string16 icon_path_;
bool has_icon_ = false;
bool silent_ = false;
bool has_reply_ = false;
base::string16 timeout_type_;
2018-01-22 18:48:12 +00:00
base::string16 reply_placeholder_;
2017-08-18 00:28:14 +00:00
base::string16 sound_;
base::string16 urgency_;
std::vector<electron::NotificationAction> actions_;
2018-01-16 19:26:41 +00:00
base::string16 close_button_text_;
base::string16 toast_xml_;
2017-05-31 07:17:29 +00:00
electron::NotificationPresenter* presenter_;
base::WeakPtr<electron::Notification> notification_;
DISALLOW_COPY_AND_ASSIGN(Notification);
};
} // namespace api
} // namespace electron
#endif // SHELL_BROWSER_API_ELECTRON_API_NOTIFICATION_H_