capacitor-push-signal 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.
Files changed (38) hide show
  1. package/CapacitorPushSignal.podspec +19 -0
  2. package/Package.swift +36 -0
  3. package/README.md +271 -0
  4. package/android/build.gradle +66 -0
  5. package/android/src/main/AndroidManifest.xml +19 -0
  6. package/android/src/main/java/com/antonseagull/cap/push/signal/PushModels.kt +15 -0
  7. package/android/src/main/java/com/antonseagull/cap/push/signal/PushSignalCenter.kt +397 -0
  8. package/android/src/main/java/com/antonseagull/cap/push/signal/PushSignalInitProvider.kt +34 -0
  9. package/android/src/main/java/com/antonseagull/cap/push/signal/PushSignalMessagingService.kt +20 -0
  10. package/android/src/main/java/com/antonseagull/cap/push/signal/PushSignalPlugin.kt +85 -0
  11. package/android/src/main/res/.gitkeep +0 -0
  12. package/dist/docs.json +275 -0
  13. package/dist/esm/definitions.d.ts +19 -0
  14. package/dist/esm/definitions.js +2 -0
  15. package/dist/esm/definitions.js.map +1 -0
  16. package/dist/esm/index.d.ts +2 -0
  17. package/dist/esm/index.js +2 -0
  18. package/dist/esm/index.js.map +1 -0
  19. package/dist/esm/pushSignal.d.ts +8 -0
  20. package/dist/esm/pushSignal.js +76 -0
  21. package/dist/esm/pushSignal.js.map +1 -0
  22. package/dist/esm/types.d.ts +20 -0
  23. package/dist/esm/types.js +2 -0
  24. package/dist/esm/types.js.map +1 -0
  25. package/dist/esm/web.d.ts +8 -0
  26. package/dist/esm/web.js +13 -0
  27. package/dist/esm/web.js.map +1 -0
  28. package/dist/plugin.cjs.js +100 -0
  29. package/dist/plugin.cjs.js.map +1 -0
  30. package/dist/plugin.js +103 -0
  31. package/dist/plugin.js.map +1 -0
  32. package/ios/Sources/PushSignalCore/PushSignalCenter.m +583 -0
  33. package/ios/Sources/PushSignalCore/PushSignalLaunchStore.m +38 -0
  34. package/ios/Sources/PushSignalCore/include/PushSignalCenter.h +26 -0
  35. package/ios/Sources/PushSignalCore/include/PushSignalLaunchStore.h +21 -0
  36. package/ios/Sources/PushSignalPlugin/PushSignalPlugin.swift +66 -0
  37. package/ios/Tests/PushSignalPluginTests/PushSignalTests.swift +9 -0
  38. package/package.json +80 -0
@@ -0,0 +1,38 @@
1
+ #import "PushSignalLaunchStore.h"
2
+ #import "PushSignalCenter.h"
3
+ #import <UIKit/UIKit.h>
4
+
5
+ static NSDictionary *sLaunchOptions;
6
+
7
+ NSDictionary *PushSignalCopyLaunchOptions(void) {
8
+ return sLaunchOptions;
9
+ }
10
+
11
+ @implementation PushSignalLaunchStore
12
+
13
+ + (void)load {
14
+ // String form: `UIApplicationWillFinishLaunchingNotification` is not declared in
15
+ // every UIKit header set, but the system still posts this name.
16
+ [[NSNotificationCenter defaultCenter]
17
+ addObserverForName:@"UIApplicationWillFinishLaunchingNotification"
18
+ object:nil
19
+ queue:nil
20
+ usingBlock:^(NSNotification *notification) {
21
+ [PushSignalCenter installEarly];
22
+ }];
23
+
24
+ [[NSNotificationCenter defaultCenter]
25
+ addObserverForName:UIApplicationDidFinishLaunchingNotification
26
+ object:nil
27
+ queue:nil
28
+ usingBlock:^(NSNotification *notification) {
29
+ sLaunchOptions = [notification.userInfo copy];
30
+ [PushSignalCenter bootstrapWithLaunchOptions:sLaunchOptions];
31
+ }];
32
+ }
33
+
34
+ + (NSDictionary *)launchOptions {
35
+ return sLaunchOptions;
36
+ }
37
+
38
+ @end
@@ -0,0 +1,26 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <UserNotifications/UserNotifications.h>
3
+
4
+ NS_ASSUME_NONNULL_BEGIN
5
+
6
+ @interface PushSignalCenter : NSObject <UNUserNotificationCenterDelegate>
7
+
8
+ + (instancetype)shared;
9
+ + (void)installEarly;
10
+ + (void)bootstrapWithLaunchOptions:(nullable NSDictionary *)launchOptions;
11
+
12
+ - (void)install;
13
+ - (void)rememberForwardingDelegate:(nullable id<UNUserNotificationCenterDelegate>)delegate;
14
+
15
+ - (void)fetchCredentialsWithResolver:(void (^)(NSDictionary *credentials))resolve
16
+ rejecter:(void (^)(NSError *error))reject;
17
+
18
+ - (void)setOnMessage:(void (^)(NSDictionary *message))callback;
19
+ - (void)setOnNotificationPress:(void (^)(NSDictionary *message))callback;
20
+
21
+ - (void)handleDeviceToken:(NSData *)deviceToken;
22
+ - (void)handleRegistrationError:(NSError *)error;
23
+
24
+ @end
25
+
26
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,21 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ NS_ASSUME_NONNULL_BEGIN
4
+
5
+ #ifdef __cplusplus
6
+ extern "C" {
7
+ #endif
8
+
9
+ NSDictionary * _Nullable PushSignalCopyLaunchOptions(void);
10
+
11
+ #ifdef __cplusplus
12
+ }
13
+ #endif
14
+
15
+ @interface PushSignalLaunchStore : NSObject
16
+
17
+ + (nullable NSDictionary *)launchOptions;
18
+
19
+ @end
20
+
21
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,66 @@
1
+ import Foundation
2
+ import Capacitor
3
+ #if canImport(PushSignalCore)
4
+ import PushSignalCore
5
+ #endif
6
+
7
+ @objc(PushSignalPlugin)
8
+ public class PushSignalPlugin: CAPPlugin, CAPBridgedPlugin {
9
+ public let identifier = "PushSignalPlugin"
10
+ public let jsName = "PushSignal"
11
+ public let pluginMethods: [CAPPluginMethod] = [
12
+ CAPPluginMethod(name: "initialize", returnType: CAPPluginReturnPromise),
13
+ CAPPluginMethod(name: "getCredentials", returnType: CAPPluginReturnPromise),
14
+ CAPPluginMethod(name: "startListening", returnType: CAPPluginReturnPromise)
15
+ ]
16
+
17
+ private var listening = false
18
+
19
+ public override func load() {
20
+ PushSignalCenter.installEarly()
21
+ }
22
+
23
+ @objc func initialize(_ call: CAPPluginCall) {
24
+ call.resolve()
25
+ }
26
+
27
+ @objc func getCredentials(_ call: CAPPluginCall) {
28
+ PushSignalCenter.shared().fetchCredentials(
29
+ resolver: { credentials in
30
+ call.resolve(Self.stringKeyed(credentials))
31
+ },
32
+ rejecter: { error in
33
+ call.reject(error.localizedDescription, nil, error)
34
+ }
35
+ )
36
+ }
37
+
38
+ @objc func startListening(_ call: CAPPluginCall) {
39
+ if !listening {
40
+ listening = true
41
+ PushSignalCenter.shared().setOnMessage { [weak self] message in
42
+ self?.notifyListeners("onMessage", data: Self.stringKeyed(message))
43
+ }
44
+ PushSignalCenter.shared().setOnNotificationPress { [weak self] message in
45
+ self?.notifyListeners("onNotificationPress", data: Self.stringKeyed(message))
46
+ }
47
+ }
48
+ call.resolve()
49
+ }
50
+
51
+ private static func stringKeyed(_ value: Any?) -> [String: Any] {
52
+ guard let dict = value as? [AnyHashable: Any] else {
53
+ return [:]
54
+ }
55
+ var result: [String: Any] = [:]
56
+ for (key, item) in dict {
57
+ let stringKey = "\(key)"
58
+ if let nested = item as? [AnyHashable: Any] {
59
+ result[stringKey] = stringKeyed(nested)
60
+ } else {
61
+ result[stringKey] = item
62
+ }
63
+ }
64
+ return result
65
+ }
66
+ }
@@ -0,0 +1,9 @@
1
+ import XCTest
2
+ @testable import PushSignalPlugin
3
+ import PushSignalCore
4
+
5
+ class PushSignalTests: XCTestCase {
6
+ func testSharedCenterExists() {
7
+ XCTAssertNotNil(PushSignalCenter.shared())
8
+ }
9
+ }
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "capacitor-push-signal",
3
+ "version": "0.0.1",
4
+ "description": "Capacitor push credentials and notification listeners (APNs / FCM)",
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
+ "files": [
10
+ "android/src/main/",
11
+ "android/build.gradle",
12
+ "dist/",
13
+ "ios/Sources",
14
+ "ios/Tests",
15
+ "Package.swift",
16
+ "CapacitorPushSignal.podspec"
17
+ ],
18
+ "author": "Anton Seagull",
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/Anton Seagull/capacitor-push-signal.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/Anton Seagull/capacitor-push-signal/issues"
26
+ },
27
+ "keywords": [
28
+ "capacitor",
29
+ "plugin",
30
+ "native"
31
+ ],
32
+ "scripts": {
33
+ "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
34
+ "verify:ios": "xcodebuild -scheme CapacitorPushSignal -destination generic/platform=iOS",
35
+ "verify:android": "cd android && ./gradlew clean build test && cd ..",
36
+ "verify:web": "npm run build",
37
+ "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
38
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
39
+ "eslint": "eslint . --ext ts",
40
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
41
+ "swiftlint": "node-swiftlint",
42
+ "docgen": "docgen --api PushSignalPlugin --output-readme README.md --output-json dist/docs.json",
43
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
44
+ "clean": "rimraf ./dist",
45
+ "watch": "tsc --watch",
46
+ "prepublishOnly": "npm run build"
47
+ },
48
+ "devDependencies": {
49
+ "@capacitor/android": "^8.0.0",
50
+ "@capacitor/core": "^8.0.0",
51
+ "@capacitor/docgen": "^0.3.1",
52
+ "@capacitor/ios": "^8.0.0",
53
+ "@ionic/eslint-config": "^0.4.0",
54
+ "@ionic/prettier-config": "^4.0.0",
55
+ "@ionic/swiftlint-config": "^2.0.0",
56
+ "eslint": "^8.57.1",
57
+ "prettier": "^3.6.2",
58
+ "prettier-plugin-java": "^2.7.7",
59
+ "rimraf": "^6.1.0",
60
+ "rollup": "^4.53.2",
61
+ "swiftlint": "^2.0.0",
62
+ "typescript": "^5.9.3"
63
+ },
64
+ "peerDependencies": {
65
+ "@capacitor/core": ">=8.0.0"
66
+ },
67
+ "prettier": "@ionic/prettier-config",
68
+ "swiftlint": "@ionic/swiftlint-config",
69
+ "eslintConfig": {
70
+ "extends": "@ionic/eslint-config/recommended"
71
+ },
72
+ "capacitor": {
73
+ "ios": {
74
+ "src": "ios"
75
+ },
76
+ "android": {
77
+ "src": "android"
78
+ }
79
+ }
80
+ }