@entrig/capacitor 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EntrigCapacitor.podspec +18 -0
- package/Package.swift +29 -0
- package/README.md +448 -0
- package/android/build.gradle +61 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/entrig/plugin/capacitor/EntrigPlugin.kt +176 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/bin/setup.js +291 -0
- package/dist/docs.json +240 -0
- package/dist/esm/definitions.d.ts +26 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +13 -0
- package/dist/esm/web.js +20 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +34 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +37 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/EntrigPlugin/EntrigPlugin.swift +169 -0
- package/ios/Tests/EntrigPluginTests/EntrigTests.swift +15 -0
- package/package.json +84 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PluginListenerHandle } from '@capacitor/core';
|
|
2
|
+
export interface EntrigConfig {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
handlePermission?: boolean;
|
|
5
|
+
showForegroundNotification?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface NotificationEvent {
|
|
8
|
+
title: string;
|
|
9
|
+
body: string;
|
|
10
|
+
data: Record<string, any>;
|
|
11
|
+
isForeground: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface EntrigPlugin {
|
|
14
|
+
init(config: EntrigConfig): Promise<void>;
|
|
15
|
+
register(options: {
|
|
16
|
+
userId: string;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
requestPermission(): Promise<{
|
|
19
|
+
granted: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
unregister(): Promise<void>;
|
|
22
|
+
getInitialNotification(): Promise<NotificationEvent | null>;
|
|
23
|
+
addListener(eventName: 'onForegroundNotification', listenerFunc: (event: NotificationEvent) => void): Promise<PluginListenerHandle>;
|
|
24
|
+
addListener(eventName: 'onNotificationOpened', listenerFunc: (event: NotificationEvent) => void): Promise<PluginListenerHandle>;
|
|
25
|
+
removeAllListeners(): Promise<void>;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface EntrigConfig {\n apiKey: string;\n handlePermission?: boolean;\n showForegroundNotification?: boolean;\n}\n\nexport interface NotificationEvent {\n title: string;\n body: string;\n data: Record<string, any>;\n isForeground: boolean;\n}\n\nexport interface EntrigPlugin {\n init(config: EntrigConfig): Promise<void>;\n register(options: { userId: string }): Promise<void>;\n requestPermission(): Promise<{ granted: boolean }>;\n unregister(): Promise<void>;\n getInitialNotification(): Promise<NotificationEvent | null>;\n\n addListener(\n eventName: 'onForegroundNotification',\n listenerFunc: (event: NotificationEvent) => void,\n ): Promise<PluginListenerHandle>;\n\n addListener(\n eventName: 'onNotificationOpened',\n listenerFunc: (event: NotificationEvent) => void,\n ): Promise<PluginListenerHandle>;\n\n removeAllListeners(): Promise<void>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,MAAM,GAAG,cAAc,CAAe,QAAQ,EAAE;IACpD,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;CAC1D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { EntrigPlugin } from './definitions';\n\nconst Entrig = registerPlugin<EntrigPlugin>('Entrig', {\n web: () => import('./web').then((m) => new m.EntrigWeb()),\n});\n\nexport * from './definitions';\nexport { Entrig };\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { EntrigPlugin, EntrigConfig, NotificationEvent } from './definitions';
|
|
3
|
+
export declare class EntrigWeb extends WebPlugin implements EntrigPlugin {
|
|
4
|
+
init(_config: EntrigConfig): Promise<void>;
|
|
5
|
+
register(_options: {
|
|
6
|
+
userId: string;
|
|
7
|
+
}): Promise<void>;
|
|
8
|
+
requestPermission(): Promise<{
|
|
9
|
+
granted: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
unregister(): Promise<void>;
|
|
12
|
+
getInitialNotification(): Promise<NotificationEvent | null>;
|
|
13
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class EntrigWeb extends WebPlugin {
|
|
3
|
+
async init(_config) {
|
|
4
|
+
console.warn('Entrig push notifications are not supported on web');
|
|
5
|
+
}
|
|
6
|
+
async register(_options) {
|
|
7
|
+
console.warn('Entrig push notifications are not supported on web');
|
|
8
|
+
}
|
|
9
|
+
async requestPermission() {
|
|
10
|
+
console.warn('Entrig push notifications are not supported on web');
|
|
11
|
+
return { granted: false };
|
|
12
|
+
}
|
|
13
|
+
async unregister() {
|
|
14
|
+
console.warn('Entrig push notifications are not supported on web');
|
|
15
|
+
}
|
|
16
|
+
async getInitialNotification() {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,SAAU,SAAQ,SAAS;IACtC,KAAK,CAAC,IAAI,CAAC,OAAqB;QAC9B,OAAO,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,QAA4B;QACzC,OAAO,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,iBAAiB;QACrB,OAAO,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;QACnE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,UAAU;QACd,OAAO,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,sBAAsB;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { EntrigPlugin, EntrigConfig, NotificationEvent } from './definitions';\n\nexport class EntrigWeb extends WebPlugin implements EntrigPlugin {\n async init(_config: EntrigConfig): Promise<void> {\n console.warn('Entrig push notifications are not supported on web');\n }\n\n async register(_options: { userId: string }): Promise<void> {\n console.warn('Entrig push notifications are not supported on web');\n }\n\n async requestPermission(): Promise<{ granted: boolean }> {\n console.warn('Entrig push notifications are not supported on web');\n return { granted: false };\n }\n\n async unregister(): Promise<void> {\n console.warn('Entrig push notifications are not supported on web');\n }\n\n async getInitialNotification(): Promise<NotificationEvent | null> {\n return null;\n }\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
const Entrig = core.registerPlugin('Entrig', {
|
|
6
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.EntrigWeb()),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
class EntrigWeb extends core.WebPlugin {
|
|
10
|
+
async init(_config) {
|
|
11
|
+
console.warn('Entrig push notifications are not supported on web');
|
|
12
|
+
}
|
|
13
|
+
async register(_options) {
|
|
14
|
+
console.warn('Entrig push notifications are not supported on web');
|
|
15
|
+
}
|
|
16
|
+
async requestPermission() {
|
|
17
|
+
console.warn('Entrig push notifications are not supported on web');
|
|
18
|
+
return { granted: false };
|
|
19
|
+
}
|
|
20
|
+
async unregister() {
|
|
21
|
+
console.warn('Entrig push notifications are not supported on web');
|
|
22
|
+
}
|
|
23
|
+
async getInitialNotification() {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
29
|
+
__proto__: null,
|
|
30
|
+
EntrigWeb: EntrigWeb
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
exports.Entrig = Entrig;
|
|
34
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Entrig = registerPlugin('Entrig', {\n web: () => import('./web').then((m) => new m.EntrigWeb()),\n});\nexport * from './definitions';\nexport { Entrig };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class EntrigWeb extends WebPlugin {\n async init(_config) {\n console.warn('Entrig push notifications are not supported on web');\n }\n async register(_options) {\n console.warn('Entrig push notifications are not supported on web');\n }\n async requestPermission() {\n console.warn('Entrig push notifications are not supported on web');\n return { granted: false };\n }\n async unregister() {\n console.warn('Entrig push notifications are not supported on web');\n }\n async getInitialNotification() {\n return null;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,MAAM,GAAGA,mBAAc,CAAC,QAAQ,EAAE;AACxC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;AAC7D,CAAC;;ACFM,MAAM,SAAS,SAASC,cAAS,CAAC;AACzC,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;AACxB,QAAQ,OAAO,CAAC,IAAI,CAAC,oDAAoD,CAAC;AAC1E,IAAI;AACJ,IAAI,MAAM,QAAQ,CAAC,QAAQ,EAAE;AAC7B,QAAQ,OAAO,CAAC,IAAI,CAAC,oDAAoD,CAAC;AAC1E,IAAI;AACJ,IAAI,MAAM,iBAAiB,GAAG;AAC9B,QAAQ,OAAO,CAAC,IAAI,CAAC,oDAAoD,CAAC;AAC1E,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;AACjC,IAAI;AACJ,IAAI,MAAM,UAAU,GAAG;AACvB,QAAQ,OAAO,CAAC,IAAI,CAAC,oDAAoD,CAAC;AAC1E,IAAI;AACJ,IAAI,MAAM,sBAAsB,GAAG;AACnC,QAAQ,OAAO,IAAI;AACnB,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var capacitorEntrig = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const Entrig = core.registerPlugin('Entrig', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.EntrigWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class EntrigWeb extends core.WebPlugin {
|
|
9
|
+
async init(_config) {
|
|
10
|
+
console.warn('Entrig push notifications are not supported on web');
|
|
11
|
+
}
|
|
12
|
+
async register(_options) {
|
|
13
|
+
console.warn('Entrig push notifications are not supported on web');
|
|
14
|
+
}
|
|
15
|
+
async requestPermission() {
|
|
16
|
+
console.warn('Entrig push notifications are not supported on web');
|
|
17
|
+
return { granted: false };
|
|
18
|
+
}
|
|
19
|
+
async unregister() {
|
|
20
|
+
console.warn('Entrig push notifications are not supported on web');
|
|
21
|
+
}
|
|
22
|
+
async getInitialNotification() {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
28
|
+
__proto__: null,
|
|
29
|
+
EntrigWeb: EntrigWeb
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
exports.Entrig = Entrig;
|
|
33
|
+
|
|
34
|
+
return exports;
|
|
35
|
+
|
|
36
|
+
})({}, capacitorExports);
|
|
37
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Entrig = registerPlugin('Entrig', {\n web: () => import('./web').then((m) => new m.EntrigWeb()),\n});\nexport * from './definitions';\nexport { Entrig };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class EntrigWeb extends WebPlugin {\n async init(_config) {\n console.warn('Entrig push notifications are not supported on web');\n }\n async register(_options) {\n console.warn('Entrig push notifications are not supported on web');\n }\n async requestPermission() {\n console.warn('Entrig push notifications are not supported on web');\n return { granted: false };\n }\n async unregister() {\n console.warn('Entrig push notifications are not supported on web');\n }\n async getInitialNotification() {\n return null;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,MAAM,GAAGA,mBAAc,CAAC,QAAQ,EAAE;IACxC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;IAC7D,CAAC;;ICFM,MAAM,SAAS,SAASC,cAAS,CAAC;IACzC,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;IACxB,QAAQ,OAAO,CAAC,IAAI,CAAC,oDAAoD,CAAC;IAC1E,IAAI;IACJ,IAAI,MAAM,QAAQ,CAAC,QAAQ,EAAE;IAC7B,QAAQ,OAAO,CAAC,IAAI,CAAC,oDAAoD,CAAC;IAC1E,IAAI;IACJ,IAAI,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,OAAO,CAAC,IAAI,CAAC,oDAAoD,CAAC;IAC1E,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;IACjC,IAAI;IACJ,IAAI,MAAM,UAAU,GAAG;IACvB,QAAQ,OAAO,CAAC,IAAI,CAAC,oDAAoD,CAAC;IAC1E,IAAI;IACJ,IAAI,MAAM,sBAAsB,GAAG;IACnC,QAAQ,OAAO,IAAI;IACnB,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import UserNotifications
|
|
4
|
+
import EntrigSDK
|
|
5
|
+
|
|
6
|
+
@objc(EntrigPlugin)
|
|
7
|
+
public class EntrigPlugin: CAPPlugin, CAPBridgedPlugin, OnNotificationReceivedListener, OnNotificationClickListener {
|
|
8
|
+
public let identifier = "EntrigPlugin"
|
|
9
|
+
public let jsName = "Entrig"
|
|
10
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
11
|
+
CAPPluginMethod(name: "init", returnType: CAPPluginReturnPromise),
|
|
12
|
+
CAPPluginMethod(name: "register", returnType: CAPPluginReturnPromise),
|
|
13
|
+
CAPPluginMethod(name: "requestPermission", returnType: CAPPluginReturnPromise),
|
|
14
|
+
CAPPluginMethod(name: "unregister", returnType: CAPPluginReturnPromise),
|
|
15
|
+
CAPPluginMethod(name: "getInitialNotification", returnType: CAPPluginReturnPromise)
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
// MARK: - Plugin Lifecycle
|
|
19
|
+
|
|
20
|
+
@objc override public func load() {
|
|
21
|
+
// Set up UNUserNotificationCenter delegate
|
|
22
|
+
UNUserNotificationCenter.current().delegate = self
|
|
23
|
+
|
|
24
|
+
// Set up SDK listeners
|
|
25
|
+
Entrig.setOnForegroundNotificationListener(self)
|
|
26
|
+
Entrig.setOnNotificationOpenedListener(self)
|
|
27
|
+
|
|
28
|
+
// Observe Capacitor token registration notifications from AppDelegate
|
|
29
|
+
NotificationCenter.default.addObserver(
|
|
30
|
+
self,
|
|
31
|
+
selector: #selector(handleDidRegisterForRemoteNotifications(_:)),
|
|
32
|
+
name: .capacitorDidRegisterForRemoteNotifications,
|
|
33
|
+
object: nil
|
|
34
|
+
)
|
|
35
|
+
NotificationCenter.default.addObserver(
|
|
36
|
+
self,
|
|
37
|
+
selector: #selector(handleDidFailToRegisterForRemoteNotifications(_:)),
|
|
38
|
+
name: .capacitorDidFailToRegisterForRemoteNotifications,
|
|
39
|
+
object: nil
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
// Check for launch notification (cold start)
|
|
43
|
+
Entrig.checkLaunchNotification(nil)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@objc private func handleDidRegisterForRemoteNotifications(_ notification: Notification) {
|
|
47
|
+
guard let deviceToken = notification.object as? Data else { return }
|
|
48
|
+
Entrig.didRegisterForRemoteNotifications(deviceToken: deviceToken)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@objc private func handleDidFailToRegisterForRemoteNotifications(_ notification: Notification) {
|
|
52
|
+
guard let error = notification.object as? Error else { return }
|
|
53
|
+
Entrig.didFailToRegisterForRemoteNotifications(error: error)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// MARK: - Plugin Methods
|
|
57
|
+
|
|
58
|
+
@objc func `init`(_ call: CAPPluginCall) {
|
|
59
|
+
guard let apiKey = call.getString("apiKey"), !apiKey.isEmpty else {
|
|
60
|
+
call.reject("API key is required and cannot be empty")
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let handlePermission = call.getBool("handlePermission") ?? true
|
|
65
|
+
let showForegroundNotification = call.getBool("showForegroundNotification") ?? true
|
|
66
|
+
let config = EntrigConfig(apiKey: apiKey, handlePermission: handlePermission, showForegroundNotification: showForegroundNotification)
|
|
67
|
+
|
|
68
|
+
Entrig.configure(config: config) { success, error in
|
|
69
|
+
if success {
|
|
70
|
+
call.resolve()
|
|
71
|
+
} else {
|
|
72
|
+
call.reject(error ?? "Failed to initialize SDK")
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@objc func register(_ call: CAPPluginCall) {
|
|
78
|
+
guard let userId = call.getString("userId"), !userId.isEmpty else {
|
|
79
|
+
call.reject("userId is required")
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Detect debug mode based on compilation flags
|
|
84
|
+
#if DEBUG
|
|
85
|
+
let isDebug = true
|
|
86
|
+
#else
|
|
87
|
+
let isDebug = false
|
|
88
|
+
#endif
|
|
89
|
+
|
|
90
|
+
Entrig.register(userId: userId, sdk: "capacitor", isDebug: isDebug) { success, error in
|
|
91
|
+
if success {
|
|
92
|
+
call.resolve()
|
|
93
|
+
} else {
|
|
94
|
+
call.reject(error ?? "Registration failed")
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@objc func requestPermission(_ call: CAPPluginCall) {
|
|
100
|
+
Entrig.requestPermission { granted, error in
|
|
101
|
+
if let error = error {
|
|
102
|
+
call.reject(error.localizedDescription)
|
|
103
|
+
} else {
|
|
104
|
+
call.resolve(["granted": granted])
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@objc func unregister(_ call: CAPPluginCall) {
|
|
110
|
+
Entrig.unregister { success, error in
|
|
111
|
+
if success {
|
|
112
|
+
call.resolve()
|
|
113
|
+
} else {
|
|
114
|
+
call.reject(error ?? "Unregistration failed")
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@objc func getInitialNotification(_ call: CAPPluginCall) {
|
|
120
|
+
if let event = Entrig.getInitialNotification() {
|
|
121
|
+
call.resolve(notificationToDict(event))
|
|
122
|
+
} else {
|
|
123
|
+
call.resolve([:])
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// MARK: - Notification Listeners
|
|
128
|
+
|
|
129
|
+
public func onNotificationReceived(_ event: NotificationEvent) {
|
|
130
|
+
notifyListeners("onForegroundNotification", data: notificationToDict(event))
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public func onNotificationClick(_ event: NotificationEvent) {
|
|
134
|
+
notifyListeners("onNotificationOpened", data: notificationToDict(event))
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// MARK: - Helpers
|
|
138
|
+
|
|
139
|
+
private func notificationToDict(_ event: NotificationEvent) -> [String: Any] {
|
|
140
|
+
return [
|
|
141
|
+
"title": event.title,
|
|
142
|
+
"body": event.body,
|
|
143
|
+
"data": event.data,
|
|
144
|
+
"isForeground": false
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// MARK: - UNUserNotificationCenterDelegate
|
|
150
|
+
|
|
151
|
+
extension EntrigPlugin: UNUserNotificationCenterDelegate {
|
|
152
|
+
public func userNotificationCenter(
|
|
153
|
+
_ center: UNUserNotificationCenter,
|
|
154
|
+
willPresent notification: UNNotification,
|
|
155
|
+
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
|
|
156
|
+
) {
|
|
157
|
+
Entrig.willPresentNotification(notification)
|
|
158
|
+
completionHandler(Entrig.getPresentationOptions())
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public func userNotificationCenter(
|
|
162
|
+
_ center: UNUserNotificationCenter,
|
|
163
|
+
didReceive response: UNNotificationResponse,
|
|
164
|
+
withCompletionHandler completionHandler: @escaping () -> Void
|
|
165
|
+
) {
|
|
166
|
+
Entrig.didReceiveNotification(response)
|
|
167
|
+
completionHandler()
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import EntrigPlugin
|
|
3
|
+
|
|
4
|
+
class EntrigTests: XCTestCase {
|
|
5
|
+
func testEcho() {
|
|
6
|
+
// This is an example of a functional test case for a plugin.
|
|
7
|
+
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
8
|
+
|
|
9
|
+
let implementation = Entrig()
|
|
10
|
+
let value = "Hello, World!"
|
|
11
|
+
let result = implementation.echo(value)
|
|
12
|
+
|
|
13
|
+
XCTAssertEqual(value, result)
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@entrig/capacitor",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Push Notifications for Supabase",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"bin": {
|
|
10
|
+
"entrig-capacitor": "./bin/setup.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"android/src/main/",
|
|
14
|
+
"android/build.gradle",
|
|
15
|
+
"bin/",
|
|
16
|
+
"dist/",
|
|
17
|
+
"ios/Sources",
|
|
18
|
+
"ios/Tests",
|
|
19
|
+
"Package.swift",
|
|
20
|
+
"EntrigCapacitor.podspec"
|
|
21
|
+
],
|
|
22
|
+
"author": "entrig",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/entrig/capacitor.git"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/entrig/capacitor/issues"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"capacitor",
|
|
33
|
+
"plugin",
|
|
34
|
+
"native"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
38
|
+
"verify:ios": "xcodebuild -scheme EntrigCapacitor -destination generic/platform=iOS",
|
|
39
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
40
|
+
"verify:web": "npm run build",
|
|
41
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
42
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
43
|
+
"eslint": "eslint . --ext ts",
|
|
44
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
45
|
+
"swiftlint": "node-swiftlint",
|
|
46
|
+
"docgen": "docgen --api EntrigPlugin --output-readme README.md --output-json dist/docs.json",
|
|
47
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
48
|
+
"clean": "rimraf ./dist",
|
|
49
|
+
"watch": "tsc --watch",
|
|
50
|
+
"prepublishOnly": "npm run build"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@capacitor/android": "^8.0.0",
|
|
54
|
+
"@capacitor/core": "^8.0.0",
|
|
55
|
+
"@capacitor/docgen": "^0.3.1",
|
|
56
|
+
"@capacitor/ios": "^8.0.0",
|
|
57
|
+
"@ionic/eslint-config": "^0.4.0",
|
|
58
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
59
|
+
"@ionic/swiftlint-config": "^2.0.0",
|
|
60
|
+
"eslint": "^8.57.1",
|
|
61
|
+
"prettier": "^3.6.2",
|
|
62
|
+
"prettier-plugin-java": "^2.7.7",
|
|
63
|
+
"rimraf": "^6.1.0",
|
|
64
|
+
"rollup": "^4.53.2",
|
|
65
|
+
"swiftlint": "^2.0.0",
|
|
66
|
+
"typescript": "^5.9.3"
|
|
67
|
+
},
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"@capacitor/core": ">=8.0.0"
|
|
70
|
+
},
|
|
71
|
+
"prettier": "@ionic/prettier-config",
|
|
72
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
73
|
+
"eslintConfig": {
|
|
74
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
75
|
+
},
|
|
76
|
+
"capacitor": {
|
|
77
|
+
"ios": {
|
|
78
|
+
"src": "ios"
|
|
79
|
+
},
|
|
80
|
+
"android": {
|
|
81
|
+
"src": "android"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|