forked from electron/electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
electron_api_push_notifications.cc
79 lines (60 loc) · 2.08 KB
/
electron_api_push_notifications.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) 2022 Asana, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/electron_api_push_notifications.h"
#include <string>
#include "shell/common/gin_converters/value_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_includes.h"
namespace electron {
namespace api {
PushNotifications* push_notifications = nullptr;
gin::WrapperInfo PushNotifications::kWrapperInfo = {gin::kEmbedderNativeGin};
PushNotifications::PushNotifications() {
DCHECK(!push_notifications);
push_notifications = this;
}
PushNotifications::~PushNotifications() {
DCHECK(push_notifications);
push_notifications = nullptr;
}
// static
PushNotifications* PushNotifications::Get() {
return push_notifications;
}
// static
gin::Handle<PushNotifications> PushNotifications::Create(v8::Isolate* isolate) {
return gin::CreateHandle(isolate, new PushNotifications());
}
// static
gin::ObjectTemplateBuilder PushNotifications::GetObjectTemplateBuilder(
v8::Isolate* isolate) {
auto builder = gin_helper::EventEmitterMixin<
PushNotifications>::GetObjectTemplateBuilder(isolate);
#if BUILDFLAG(IS_MAC)
builder
.SetMethod("registerForAPNSNotifications",
&PushNotifications::RegisterForAPNSNotifications)
.SetMethod("unregisterForAPNSNotifications",
&PushNotifications::UnregisterForAPNSNotifications);
#endif
return builder;
}
const char* PushNotifications::GetTypeName() {
return "PushNotifications";
}
} // namespace api
} // namespace electron
namespace {
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
gin::Dictionary dict(isolate, exports);
dict.Set("pushNotifications",
electron::api::PushNotifications::Create(isolate));
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_push_notifications,
Initialize)