@ua/capacitor-airship 3.1.0 → 4.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.
@@ -1,4 +1,5 @@
1
1
  import Foundation
2
+ @preconcurrency
2
3
  import Capacitor
3
4
 
4
5
  #if canImport(AirshipKit)
@@ -14,7 +15,7 @@ import AirshipFrameworkProxy
14
15
  * here: https://capacitorjs.com/docs/plugins/ios
15
16
  */
16
17
  @objc(AirshipPlugin)
17
- public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin {
18
+ public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin, @unchecked Sendable {
18
19
 
19
20
  public let identifier = "AirshipPlugin"
20
21
  public let jsName = "Airship"
@@ -36,15 +37,17 @@ public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin {
36
37
  .liveActivitiesUpdated: "ios_live_activities_updated"
37
38
  ]
38
39
 
39
- @MainActor
40
40
  public override func load() {
41
- AirshipCapacitorAutopilot.shared.onPluginInitialized(
42
- pluginConfig: self.getConfig()
43
- )
41
+ let config = self.getConfig()
42
+ MainActor.assumeIsolated {
43
+ AirshipCapacitorAutopilot.shared.onPluginInitialized(
44
+ pluginConfig: config
45
+ )
44
46
 
45
- Task {
46
- for await _ in await AirshipProxyEventEmitter.shared.pendingEventAdded {
47
- await self.notifyPendingEvents()
47
+ Task {
48
+ for await _ in AirshipProxyEventEmitter.shared.pendingEventAdded {
49
+ await self.notifyPendingEvents()
50
+ }
48
51
  }
49
52
  }
50
53
  }
@@ -52,22 +55,26 @@ public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin {
52
55
  @MainActor
53
56
  private func notifyPendingEvents() async {
54
57
  for eventType in AirshipProxyEventType.allCases {
55
- await AirshipProxyEventEmitter.shared.processPendingEvents(type: eventType) { event in
58
+ AirshipProxyEventEmitter.shared.processPendingEvents(type: eventType) { event in
56
59
  return sendEvent(event)
57
60
  }
58
61
  }
59
62
  }
60
63
 
61
64
  @MainActor
62
- private func sendEvent(_ event: AirshipProxyEvent) -> Bool {
65
+ private func sendEvent(_ event: any AirshipProxyEvent) -> Bool {
63
66
  guard let eventName = Self.eventNames[event.type] else {
64
67
  return false
65
68
  }
66
69
  guard self.hasListeners(eventName) else {
67
70
  return false
68
71
  }
72
+ do {
73
+ self.notifyListeners(eventName, data: try event.body.unwrapped())
74
+ } catch {
75
+ AirshipLogger.error("Failed to send event: \(event) error: \(error)")
76
+ }
69
77
 
70
- self.notifyListeners(eventName, data: event.body)
71
78
  return true
72
79
  }
73
80
 
@@ -80,7 +87,7 @@ public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin {
80
87
 
81
88
  CAPLog.print("⚡️ To Airship -> ", pluginId, method, call.callbackId as Any)
82
89
 
83
- Task {
90
+ Task { @MainActor in
84
91
  do {
85
92
  if let result = try await self.handle(method: method, call: call) {
86
93
  call.resolve(["value": try AirshipJSON.wrap(result).unWrap() as Any])
@@ -102,7 +109,7 @@ public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin {
102
109
  }
103
110
 
104
111
  @MainActor
105
- private func handle(method: String, call: CAPPluginCall) async throws -> Any? {
112
+ private func handle(method: String, call: CAPPluginCall) async throws -> (any Sendable)? {
106
113
 
107
114
  switch method {
108
115
 
@@ -117,20 +124,20 @@ public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin {
117
124
 
118
125
  // Channel
119
126
  case "channel#getChannelId":
120
- return try AirshipProxy.shared.channel.getChannelId()
127
+ return try AirshipProxy.shared.channel.channelID
121
128
 
122
129
  case "channel#editTags":
123
130
  try AirshipProxy.shared.channel.editTags(
124
- json: try call.requireAnyArg()
131
+ operations: try call.requireCodableArg()
125
132
  )
126
133
  return nil
127
134
 
128
135
  case "channel#getTags":
129
- return try AirshipProxy.shared.channel.getTags()
136
+ return try AirshipProxy.shared.channel.tags
130
137
 
131
138
  case "channel#editTagGroups":
132
139
  try AirshipProxy.shared.channel.editTagGroups(
133
- json: try call.requireAnyArg()
140
+ operations: try call.requireCodableArg()
134
141
  )
135
142
  return nil
136
143
 
@@ -142,12 +149,12 @@ public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin {
142
149
 
143
150
  case "channel#editAttributes":
144
151
  try AirshipProxy.shared.channel.editAttributes(
145
- json: try call.requireAnyArg()
152
+ operations: try call.requireCodableArg()
146
153
  )
147
154
  return nil
148
155
 
149
156
  case "channel#getSubscriptionLists":
150
- return try await AirshipProxy.shared.channel.getSubscriptionLists()
157
+ return try await AirshipProxy.shared.channel.fetchSubscriptionLists()
151
158
 
152
159
  case "channel#enableChannelCreation":
153
160
  try AirshipProxy.shared.channel.enableChannelCreation()
@@ -156,19 +163,19 @@ public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin {
156
163
  // Contact
157
164
  case "contact#editTagGroups":
158
165
  try AirshipProxy.shared.contact.editTagGroups(
159
- json: try call.requireAnyArg()
166
+ operations: try call.requireCodableArg()
160
167
  )
161
168
  return nil
162
169
 
163
170
  case "contact#editSubscriptionLists":
164
171
  try AirshipProxy.shared.contact.editSubscriptionLists(
165
- json: try call.requireAnyArg()
172
+ operations: try call.requireCodableArg()
166
173
  )
167
174
  return nil
168
175
 
169
176
  case "contact#editAttributes":
170
177
  try AirshipProxy.shared.contact.editAttributes(
171
- json: try call.requireAnyArg()
178
+ operations: try call.requireCodableArg()
172
179
  )
173
180
  return nil
174
181
 
@@ -190,7 +197,7 @@ public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin {
190
197
  return nil
191
198
 
192
199
  case "contact#getNamedUserId":
193
- return try await AirshipProxy.shared.contact.getNamedUser()
200
+ return try await AirshipProxy.shared.contact.namedUserID
194
201
 
195
202
 
196
203
  // Push
@@ -212,10 +219,10 @@ public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin {
212
219
  return try AirshipProxy.shared.push.isUserNotificationsEnabled()
213
220
 
214
221
  case "push#getNotificationStatus":
215
- return try await AirshipProxy.shared.push.getNotificationStatus()
222
+ return try await AirshipProxy.shared.push.notificationStatus
216
223
 
217
224
  case "push#getActiveNotifications":
218
- return await AirshipProxy.shared.push.getActiveNotifications()
225
+ return try await AirshipProxy.shared.push.getActiveNotifications()
219
226
 
220
227
  case "push#clearNotification":
221
228
  AirshipProxy.shared.push.clearNotification(
@@ -283,7 +290,7 @@ public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin {
283
290
  return nil
284
291
 
285
292
  case "push#ios#getQuietTime":
286
- return try AirshipProxy.shared.push.getQuietTime()
293
+ return try AirshipJSON.wrap(try AirshipProxy.shared.push.getQuietTime())
287
294
 
288
295
  // In-App
289
296
  case "inApp#setPaused":
@@ -297,7 +304,7 @@ public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin {
297
304
 
298
305
  case "inApp#setDisplayInterval":
299
306
  try AirshipProxy.shared.inApp.setDisplayInterval(
300
- try call.requireIntArg()
307
+ milliseconds: try call.requireIntArg()
301
308
  )
302
309
  return nil
303
310
 
@@ -330,7 +337,7 @@ public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin {
330
337
 
331
338
  // Message Center
332
339
  case "messageCenter#getMessages":
333
- return try? await AirshipProxy.shared.messageCenter.getMessages()
340
+ return try await AirshipProxy.shared.messageCenter.messages
334
341
 
335
342
  case "messageCenter#display":
336
343
  try AirshipProxy.shared.messageCenter.display(
@@ -367,7 +374,7 @@ public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin {
367
374
  return nil
368
375
 
369
376
  case "messageCenter#getUnreadCount":
370
- return try await AirshipProxy.shared.messageCenter.getUnreadCount()
377
+ return try await AirshipProxy.shared.messageCenter.unreadCount
371
378
 
372
379
  case "messageCenter#refreshMessages":
373
380
  try await AirshipProxy.shared.messageCenter.refresh()
@@ -446,7 +453,7 @@ public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin {
446
453
  return nil
447
454
 
448
455
  case "locale#getCurrentLocale":
449
- return try AirshipProxy.shared.locale.getCurrentLocale()
456
+ return try AirshipProxy.shared.locale.currentLocale
450
457
 
451
458
  // Actions
452
459
  case "actions#run":
@@ -459,11 +466,10 @@ public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin {
459
466
  }
460
467
 
461
468
  let arg = try? AirshipJSON.wrap(args[1])
462
- let result = try await AirshipProxy.shared.action.runAction(
469
+ return try await AirshipProxy.shared.action.runAction(
463
470
  actionName,
464
471
  value: args.count == 2 ? arg : nil
465
- ) as? AirshipJSON
466
- return result?.unWrap()
472
+ )
467
473
 
468
474
  // Feature Flag
469
475
  case "featureFlagManager#flag":
@@ -631,3 +637,12 @@ extension CAPPluginCall {
631
637
  throw AirshipErrors.error("Argument must be a double")
632
638
  }
633
639
  }
640
+
641
+ fileprivate extension Encodable {
642
+ func unwrapped<T>() throws -> T {
643
+ guard let value = try AirshipJSON.wrap(self).unWrap() as? T else {
644
+ throw AirshipErrors.error("Failed to unwrap codable")
645
+ }
646
+ return value
647
+ }
648
+ }
@@ -1,4 +1,7 @@
1
- import AirshipFrameworkProxy
1
+
2
+ public import AirshipFrameworkProxy
3
+ public import Foundation
4
+ public import UIKit
2
5
 
3
6
  @objc(AirshipPluginLoader)
4
7
  public class AirshipPluginLoader: NSObject, AirshipPluginLoaderProtocol {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ua/capacitor-airship",
3
- "version": "3.1.0",
3
+ "version": "4.0.1",
4
4
  "description": "Airship capacitor plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -35,31 +35,31 @@
35
35
  "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
36
36
  "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
37
37
  "eslint": "eslint . --ext ts",
38
- "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
38
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
39
39
  "build:docs": "typedoc src/index.ts",
40
- "build": "npm run clean && npm run build:docs && tsc && rollup -c rollup.config.js",
40
+ "build": "npm run clean && npm run build:docs && tsc && rollup -c rollup.config.mjs",
41
41
  "clean": "rimraf ./dist",
42
42
  "watch": "tsc --watch",
43
43
  "prepublishOnly": "npm run build"
44
44
  },
45
45
  "devDependencies": {
46
- "@capacitor/android": "^6.0.0",
47
- "@capacitor/core": "^6.0.0",
48
- "@capacitor/ios": "^6.0.0",
49
- "@capacitor/cli": "^6.0.0",
50
- "@ionic/eslint-config": "^0.3.0",
51
- "@ionic/prettier-config": "^1.0.1",
52
- "@ionic/swiftlint-config": "^1.1.2",
53
- "eslint": "^7.11.0",
54
- "prettier": "~2.3.0",
55
- "prettier-plugin-java": "~1.0.2",
56
- "rimraf": "^3.0.2",
57
- "rollup": "^2.32.0",
46
+ "@capacitor/android": "^7.0.0",
47
+ "@capacitor/core": "^7.0.0",
48
+ "@capacitor/ios": "^7.0.0",
49
+ "@capacitor/cli": "^7.0.0",
50
+ "@ionic/eslint-config": "^0.4.0",
51
+ "@ionic/prettier-config": "^4.0.0",
52
+ "@ionic/swiftlint-config": "^2.0.0",
53
+ "eslint": "^8.57.0",
54
+ "prettier": "^3.4.2",
55
+ "prettier-plugin-java": "^2.6.6",
56
+ "rimraf": "^6.0.1",
57
+ "rollup": "^4.30.1",
58
58
  "typescript": "~4.8.0",
59
59
  "typedoc": "0.23.24"
60
60
  },
61
61
  "peerDependencies": {
62
- "@capacitor/core": "^6.0.0"
62
+ "@capacitor/core": ">=7.0.0"
63
63
  },
64
64
  "prettier": "@ionic/prettier-config",
65
65
  "eslintConfig": {