native-update 1.1.1 → 1.1.3

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.
@@ -214,12 +214,12 @@ class AppUpdatePlugin {
214
214
 
215
215
  // MARK: - Data Models
216
216
 
217
- struct AppUpdateInfo {
218
- let updateAvailable: Bool
219
- let currentVersion: String
220
- let availableVersion: String?
217
+ public struct AppUpdateInfo {
218
+ public let updateAvailable: Bool
219
+ public let currentVersion: String
220
+ public let availableVersion: String?
221
221
 
222
- func toDictionary() -> [String: Any] {
222
+ public func toDictionary() -> [String: Any] {
223
223
  var obj: [String: Any] = [
224
224
  "updateAvailable": updateAvailable,
225
225
  "currentVersion": currentVersion
@@ -8,20 +8,17 @@ public class BackgroundUpdatePlugin: CAPPlugin {
8
8
 
9
9
  private let backgroundTaskIdentifier = "com.aoneahsan.nativeupdate.background"
10
10
  private var backgroundUpdateConfig: BackgroundUpdateConfig?
11
- private var backgroundUpdateStatus: BackgroundUpdateStatus
11
+ private var backgroundUpdateStatus = BackgroundUpdateStatus(
12
+ enabled: false,
13
+ isRunning: false,
14
+ checkCount: 0,
15
+ failureCount: 0
16
+ )
12
17
  private var notificationManager: BackgroundNotificationManager?
13
18
 
14
19
  public override func load() {
15
20
  super.load()
16
21
 
17
- // Initialize background update status
18
- backgroundUpdateStatus = BackgroundUpdateStatus(
19
- enabled: false,
20
- isRunning: false,
21
- checkCount: 0,
22
- failureCount: 0
23
- )
24
-
25
22
  // Initialize notification manager
26
23
  notificationManager = BackgroundNotificationManager(plugin: self)
27
24
 
@@ -33,6 +30,11 @@ public class BackgroundUpdatePlugin: CAPPlugin {
33
30
  }
34
31
  }
35
32
 
33
+ func configure(_ config: [String: Any]) throws {
34
+ // Configuration is handled in enableBackgroundUpdates
35
+ // This method exists for consistency with other plugins
36
+ }
37
+
36
38
  @objc func enableBackgroundUpdates(_ call: CAPPluginCall) {
37
39
  guard let configData = call.options else {
38
40
  call.reject("Missing configuration")
@@ -40,7 +42,13 @@ public class BackgroundUpdatePlugin: CAPPlugin {
40
42
  }
41
43
 
42
44
  do {
43
- let config = try BackgroundUpdateConfig.from(configData)
45
+ // Convert [AnyHashable: Any] to [String: Any]
46
+ let stringKeyedConfig = configData.reduce(into: [String: Any]()) { result, pair in
47
+ if let key = pair.key as? String {
48
+ result[key] = pair.value
49
+ }
50
+ }
51
+ let config = try BackgroundUpdateConfig.from(stringKeyedConfig)
44
52
  backgroundUpdateConfig = config
45
53
  backgroundUpdateStatus.enabled = config.enabled
46
54
 
@@ -88,7 +96,14 @@ public class BackgroundUpdatePlugin: CAPPlugin {
88
96
  return
89
97
  }
90
98
 
91
- notificationManager?.setPreferences(preferences)
99
+ // Convert [AnyHashable: Any] to [String: Any]
100
+ let stringKeyedPreferences = preferences.reduce(into: [String: Any]()) { result, pair in
101
+ if let key = pair.key as? String {
102
+ result[key] = pair.value
103
+ }
104
+ }
105
+
106
+ notificationManager?.setPreferences(stringKeyedPreferences)
92
107
  call.resolve()
93
108
  }
94
109
 
@@ -172,6 +187,8 @@ public class BackgroundUpdatePlugin: CAPPlugin {
172
187
  return BackgroundCheckResult(
173
188
  success: false,
174
189
  updatesFound: false,
190
+ appUpdate: nil,
191
+ liveUpdate: nil,
175
192
  notificationSent: false,
176
193
  error: UpdateError(code: "INVALID_CONFIG", message: "Background updates not enabled")
177
194
  )
@@ -214,7 +231,8 @@ public class BackgroundUpdatePlugin: CAPPlugin {
214
231
  updatesFound: updatesFound,
215
232
  appUpdate: appUpdate,
216
233
  liveUpdate: liveUpdate,
217
- notificationSent: notificationSent
234
+ notificationSent: notificationSent,
235
+ error: nil
218
236
  )
219
237
 
220
238
  } catch {
@@ -230,6 +248,8 @@ public class BackgroundUpdatePlugin: CAPPlugin {
230
248
  return BackgroundCheckResult(
231
249
  success: false,
232
250
  updatesFound: false,
251
+ appUpdate: nil,
252
+ liveUpdate: nil,
233
253
  notificationSent: false,
234
254
  error: updateError
235
255
  )
@@ -7,7 +7,7 @@ class LiveUpdatePlugin {
7
7
  private var config: [String: Any]?
8
8
  private var progressListener: (([String: Any]) -> Void)?
9
9
  private var stateChangeListener: (([String: Any]) -> Void)?
10
- private var session: URLSession
10
+ private var session: URLSession!
11
11
  private var downloadTask: URLSessionDownloadTask?
12
12
  private let securityManager = SecurityManager()
13
13
 
@@ -444,10 +444,15 @@ class LiveUpdatePlugin {
444
444
  }
445
445
 
446
446
  private func getCurrentVersion() -> String {
447
- if let bundle = getCurrentBundleInfo(),
448
- let version = bundle["version"] as? String {
447
+ // First check if we have an active bundle with version
448
+ let defaults = UserDefaults.standard
449
+ if let activeBundleId = defaults.string(forKey: "native_update_active_bundle"),
450
+ let bundles = defaults.dictionary(forKey: "native_update_bundles"),
451
+ let bundleInfo = bundles[activeBundleId] as? [String: Any],
452
+ let version = bundleInfo["version"] as? String {
449
453
  return version
450
454
  }
455
+ // Fall back to app version
451
456
  return Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "1.0.0"
452
457
  }
453
458
 
@@ -484,7 +489,7 @@ class LiveUpdatePlugin {
484
489
  // Return default bundle
485
490
  return [
486
491
  "bundleId": "default",
487
- "version": getCurrentVersion(),
492
+ "version": Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "1.0.0",
488
493
  "path": "/",
489
494
  "downloadTime": Date().timeIntervalSince1970 * 1000,
490
495
  "size": 0,
@@ -555,19 +560,14 @@ class LiveUpdatePlugin {
555
560
  // Create destination directory
556
561
  try FileManager.default.createDirectory(at: destinationUrl, withIntermediateDirectories: true)
557
562
 
558
- // Use system unzip command
559
- let process = Process()
560
- process.executableURL = URL(fileURLWithPath: "/usr/bin/unzip")
561
- process.arguments = ["-o", zipUrl.path, "-d", destinationUrl.path]
563
+ // Use FileManager to extract (requires iOS unzip library or manual implementation)
564
+ // For now, we'll use a simple file copy as placeholder
565
+ // In production, you would use a library like ZIPFoundation or SSZipArchive
562
566
 
563
- try process.run()
564
- process.waitUntilExit()
565
-
566
- if process.terminationStatus != 0 {
567
- throw NSError(domain: "LiveUpdatePlugin", code: 5, userInfo: [
568
- NSLocalizedDescriptionKey: "Failed to extract bundle"
569
- ])
570
- }
567
+ // This is a placeholder - in real implementation, use a proper unzip library
568
+ throw NSError(domain: "LiveUpdatePlugin", code: 5, userInfo: [
569
+ NSLocalizedDescriptionKey: "Unzip functionality not implemented. Please integrate a zip library like ZIPFoundation."
570
+ ])
571
571
  }
572
572
 
573
573
  private func configureWebViewPath(_ path: String) {
@@ -581,11 +581,11 @@ class LiveUpdatePlugin {
581
581
 
582
582
  // MARK: - Data Models
583
583
 
584
- struct LatestVersion {
585
- let available: Bool
586
- let version: String?
584
+ public struct LatestVersion {
585
+ public let available: Bool
586
+ public let version: String?
587
587
 
588
- func toDictionary() -> [String: Any] {
588
+ public func toDictionary() -> [String: Any] {
589
589
  var obj: [String: Any] = [
590
590
  "available": available
591
591
  ]
@@ -646,8 +646,8 @@ class CertificatePinningDelegate: NSObject, URLSessionDelegate {
646
646
 
647
647
  private func getCertificatePins(for host: String) -> [String] {
648
648
  // Get pins from security manager configuration
649
- guard let securityInfo = securityManager.getSecurityInfo(),
650
- let certificatePinning = securityInfo["certificatePinning"] as? [String: Any],
649
+ let securityInfo = securityManager.getSecurityInfo()
650
+ guard let certificatePinning = securityInfo["certificatePinning"] as? [String: Any],
651
651
  certificatePinning["enabled"] as? Bool == true,
652
652
  let hostPins = certificatePinning["pins"] as? [String: [String]] else {
653
653
  return []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-update",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Foundation package for building a comprehensive update system for Capacitor apps. Provides architecture and interfaces but requires backend implementation.",
5
5
  "type": "module",
6
6
  "main": "dist/plugin.cjs.js",