@vanikya/ota-react-native 0.2.5 → 0.2.6

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.
@@ -49,4 +49,6 @@ repositories {
49
49
  dependencies {
50
50
  //noinspection GradleDynamicVersion
51
51
  implementation "com.facebook.react:react-android:+"
52
+ // ProcessPhoenix for graceful app restart
53
+ implementation "com.jakewharton:process-phoenix:3.0.0"
52
54
  }
@@ -6,6 +6,7 @@ import android.os.Handler
6
6
  import android.os.Looper
7
7
  import android.util.Base64
8
8
  import com.facebook.react.bridge.*
9
+ import com.jakewharton.processphoenix.ProcessPhoenix
9
10
  import java.io.File
10
11
  import java.io.FileOutputStream
11
12
  import java.io.InputStream
@@ -303,26 +304,35 @@ class OTAUpdateModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
303
304
  }
304
305
 
305
306
  if (restart) {
306
- android.util.Log.d("OTAUpdate", "Restarting app to apply bundle...")
307
+ android.util.Log.d("OTAUpdate", "Restarting app to apply bundle using ProcessPhoenix...")
307
308
 
308
309
  // Resolve promise before restarting so JS knows it succeeded
309
310
  promise.resolve(null)
310
311
 
311
312
  // Give a small delay to ensure the promise is sent back to JS
312
313
  mainHandler.postDelayed({
313
- // Restart the app
314
- val context = reactApplicationContext
315
- val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)
316
- intent?.addFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP)
317
- intent?.addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)
318
- intent?.addFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK)
319
- context.startActivity(intent)
320
-
321
- // Small delay before killing to allow activity to start
322
- mainHandler.postDelayed({
314
+ try {
315
+ // Use ProcessPhoenix for graceful app restart
316
+ // This properly kills the current process and starts a new one
317
+ val activity = currentActivity
318
+ if (activity != null) {
319
+ ProcessPhoenix.triggerRebirth(activity)
320
+ } else {
321
+ // Fallback to context-based restart
322
+ ProcessPhoenix.triggerRebirth(reactApplicationContext)
323
+ }
324
+ } catch (e: Exception) {
325
+ android.util.Log.e("OTAUpdate", "ProcessPhoenix restart failed: ${e.message}, using fallback")
326
+ // Fallback to manual restart
327
+ val context = reactApplicationContext
328
+ val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)
329
+ intent?.addFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP)
330
+ intent?.addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)
331
+ intent?.addFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK)
332
+ context.startActivity(intent)
323
333
  android.os.Process.killProcess(android.os.Process.myPid())
324
- }, 100)
325
- }, 100)
334
+ }
335
+ }, 200)
326
336
  } else {
327
337
  promise.resolve(null)
328
338
  }
@@ -345,6 +355,24 @@ class OTAUpdateModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
345
355
  promise.resolve(null)
346
356
  }
347
357
 
358
+ // Reload the app - used to apply pending updates
359
+ @ReactMethod
360
+ fun reload() {
361
+ android.util.Log.d("OTAUpdate", "Reload requested...")
362
+ mainHandler.postDelayed({
363
+ try {
364
+ val activity = currentActivity
365
+ if (activity != null) {
366
+ ProcessPhoenix.triggerRebirth(activity)
367
+ } else {
368
+ ProcessPhoenix.triggerRebirth(reactApplicationContext)
369
+ }
370
+ } catch (e: Exception) {
371
+ android.util.Log.e("OTAUpdate", "Reload failed: ${e.message}")
372
+ }
373
+ }, 100)
374
+ }
375
+
348
376
  // Utility functions
349
377
 
350
378
  private fun hexStringToByteArray(hex: String): ByteArray {
@@ -103,5 +103,5 @@ var _verification = require("./utils/verification");
103
103
  // Utilities
104
104
 
105
105
  // Version info
106
- const VERSION = exports.VERSION = '0.2.5';
106
+ const VERSION = exports.VERSION = '0.2.6';
107
107
  //# sourceMappingURL=index.js.map
@@ -10,5 +10,5 @@ export { OTAApiClient, getDeviceInfo } from './utils/api';
10
10
  export { UpdateStorage, getStorageAdapter } from './utils/storage';
11
11
  export { calculateHash, verifyBundleHash, verifySignature, verifyBundle } from './utils/verification';
12
12
  // Version info
13
- export const VERSION = '0.2.5';
13
+ export const VERSION = '0.2.6';
14
14
  //# sourceMappingURL=index.js.map
@@ -9,5 +9,5 @@ export { UpdateStorage, getStorageAdapter } from './utils/storage';
9
9
  export type { StoredUpdate, StorageAdapter } from './utils/storage';
10
10
  export { calculateHash, verifyBundleHash, verifySignature, verifyBundle, } from './utils/verification';
11
11
  export type { VerificationResult } from './utils/verification';
12
- export declare const VERSION = "0.2.5";
12
+ export declare const VERSION = "0.2.6";
13
13
  //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanikya/ota-react-native",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "OTA Update SDK for React Native apps - self-hosted CodePush/EAS Updates alternative",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
package/src/index.ts CHANGED
@@ -36,4 +36,4 @@ export {
36
36
  export type { VerificationResult } from './utils/verification';
37
37
 
38
38
  // Version info
39
- export const VERSION = '0.2.5';
39
+ export const VERSION = '0.2.6';