@hot-updater/react-native 0.18.1 → 0.18.2

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.
@@ -27,10 +27,11 @@ object HotUpdaterFactory {
27
27
  private fun createHotUpdaterImpl(context: Context): HotUpdaterImpl {
28
28
  val appContext = context.applicationContext
29
29
  val appVersion = HotUpdaterImpl.getAppVersion(appContext) ?: "unknown"
30
+ val appChannel = HotUpdaterImpl.getChannel(appContext)
30
31
 
31
32
  // Create services
32
33
  val fileSystem = FileManagerService(appContext)
33
- val preferences = VersionedPreferencesService(appContext, appVersion)
34
+ val preferences = VersionedPreferencesService(appContext, appVersion, appChannel)
34
35
  val downloadService = HttpDownloadService()
35
36
  val unzipService = ZipFileUnzipService()
36
37
 
@@ -57,6 +57,15 @@ class HotUpdaterImpl(
57
57
  } catch (e: Exception) {
58
58
  null
59
59
  }
60
+
61
+ fun getChannel(context: Context): String {
62
+ val id = context.resources.getIdentifier("hot_updater_channel", "string", context.packageName)
63
+ return if (id != 0) {
64
+ context.getString(id).takeIf { it.isNotEmpty() } ?: DEFAULT_CHANNEL
65
+ } else {
66
+ DEFAULT_CHANNEL
67
+ }
68
+ }
60
69
  }
61
70
 
62
71
  /**
@@ -33,11 +33,12 @@ interface PreferencesService {
33
33
  class VersionedPreferencesService(
34
34
  private val context: Context,
35
35
  private val appVersion: String,
36
+ private val appChannel: String,
36
37
  ) : PreferencesService {
37
38
  private val prefs: SharedPreferences
38
39
 
39
40
  init {
40
- val prefsName = "HotUpdaterPrefs_$appVersion"
41
+ val prefsName = "HotUpdaterPrefs_${appVersion}_$appChannel"
41
42
 
42
43
  val sharedPrefsDir = File(context.applicationInfo.dataDir, "shared_prefs")
43
44
  if (sharedPrefsDir.exists() && sharedPrefsDir.isDirectory) {
@@ -503,20 +503,19 @@ class BundleFileStorageService: BundleStorageService {
503
503
  ))))
504
504
  return
505
505
  }
506
-
506
+
507
507
  // 2. Create target directory
508
508
  do {
509
509
  let tempZipFileURL = URL(fileURLWithPath: tempZipFile)
510
510
  let tempZipFileDirectory = tempZipFileURL.deletingLastPathComponent()
511
-
511
+
512
512
  if !self.fileSystem.fileExists(atPath: tempZipFileDirectory.path) {
513
513
  try self.fileSystem.createDirectory(atPath: tempZipFileDirectory.path)
514
514
  NSLog("[BundleStorage] Created directory atPath: \(tempZipFileDirectory.path)")
515
515
  }
516
-
517
- try self.fileSystem.moveItem(atPath: location.path, toPath: tempZipFile)
518
- NSLog("[BundleStorage] Successfully moved file to: \(tempZipFile)")
519
-
516
+ NSLog("[BundleStorage] Successfully downloaded file to: \(tempZipFile)")
517
+
518
+ // 3. Unzip the file
520
519
  try self.unzipService.unzip(file: tempZipFile, to: extractedDir)
521
520
  NSLog("[BundleStorage] Successfully extracted to: \(extractedDir)")
522
521
 
@@ -549,7 +548,6 @@ class BundleFileStorageService: BundleStorageService {
549
548
  let setResult = self.setBundleURL(localPath: finalBundlePath)
550
549
  switch setResult {
551
550
  case .success:
552
- // 10. Cleanup
553
551
  self.cleanupTemporaryFiles([tempDirectory])
554
552
  completion(.success(true))
555
553
  case .failure(let error):
@@ -4,7 +4,9 @@ import React
4
4
  @objcMembers public class HotUpdaterImpl: NSObject {
5
5
  private let bundleStorage: BundleStorageService
6
6
  private let preferences: PreferencesService
7
-
7
+
8
+ private static let DEFAULT_CHANNEL = "production"
9
+
8
10
  // MARK: - Initialization
9
11
 
10
12
  /**
@@ -35,10 +37,13 @@ import React
35
37
  self.bundleStorage = bundleStorage
36
38
  self.preferences = preferences
37
39
  super.init()
38
-
40
+
39
41
  // Configure preferences with app version
40
42
  if let appVersion = HotUpdaterImpl.appVersion {
41
- (preferences as? VersionedPreferencesService)?.configure(appVersion: appVersion)
43
+ (preferences as? VersionedPreferencesService)?.configure(
44
+ appVersion: appVersion,
45
+ appChannel: HotUpdaterImpl.appChannel
46
+ )
42
47
  }
43
48
  }
44
49
 
@@ -50,15 +55,21 @@ import React
50
55
  public static var appVersion: String? {
51
56
  return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
52
57
  }
53
-
58
+
59
+ /**
60
+ * Returns the app version from main bundle info.
61
+ */
62
+ public static var appChannel: String {
63
+ return Bundle.main.object(forInfoDictionaryKey: "HOT_UPDATER_CHANNEL") as? String ?? Self.DEFAULT_CHANNEL
64
+ }
65
+
54
66
  // MARK: - Channel Management
55
67
 
56
68
  /**
57
69
  * Gets the current update channel.
58
70
  * @return The channel name or nil if not set
59
71
  */
60
- private static let DEFAULT_CHANNEL = "production"
61
-
72
+
62
73
  public func getChannel() -> String {
63
74
  return Bundle.main.object(forInfoDictionaryKey: "HOT_UPDATER_CHANNEL") as? String ?? Self.DEFAULT_CHANNEL
64
75
  }
@@ -23,8 +23,8 @@ class VersionedPreferencesService: PreferencesService {
23
23
  * Configures the service with app version for key prefixing.
24
24
  * @param appVersion The app version to use for key prefixing
25
25
  */
26
- func configure(appVersion: String?) {
27
- self.keyPrefix = "hotupdater_\(appVersion ?? "unknown")_"
26
+ func configure(appVersion: String?, appChannel: String) {
27
+ self.keyPrefix = "hotupdater_\(appVersion ?? "unknown")_\(appChannel)_"
28
28
  NSLog("[PreferencesService] Configured with appVersion: \(appVersion ?? "nil"). Key prefix: \(self.keyPrefix)")
29
29
  }
30
30
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/react-native",
3
- "version": "0.18.1",
3
+ "version": "0.18.2",
4
4
  "description": "React Native OTA solution for self-hosted",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -118,8 +118,8 @@
118
118
  },
119
119
  "dependencies": {
120
120
  "use-sync-external-store": "1.5.0",
121
- "@hot-updater/core": "0.18.1",
122
- "@hot-updater/js": "0.18.1"
121
+ "@hot-updater/core": "0.18.2",
122
+ "@hot-updater/js": "0.18.2"
123
123
  },
124
124
  "scripts": {
125
125
  "build": "bob build && tsc -p plugin/tsconfig.json",