@otaupdate/react-native 1.0.0 → 1.0.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.
- package/README.md +1 -0
- package/android/src/main/java/com/otaupdate/OtaUpdateModule.kt +26 -24
- package/lib/OtaUpdate.d.ts.map +1 -1
- package/lib/OtaUpdate.js +8 -4
- package/lib/OtaUpdate.js.map +1 -1
- package/package.json +1 -1
- package/plugin/build/index.d.ts +5 -2
- package/plugin/build/index.js +9 -12
- package/src/OtaUpdate.ts +8 -6
package/README.md
CHANGED
|
@@ -319,3 +319,4 @@ compatible with. Devices on other binary versions never receive it.
|
|
|
319
319
|
| Every update rolls back | `notifyAppReady()` is never reached — usually an early crash, or the call sits behind a screen the user has to navigate to. |
|
|
320
320
|
| `no_matching_binary_version` | The release's `targetBinaryVersion` does not cover the installed native version. |
|
|
321
321
|
| Works in debug, not release | Debug builds load from Metro; the OTA path only runs in release builds. |
|
|
322
|
+
| Android: mandatory update reload-loops (bare RN) | Fixed in 1.0.2. Before that, `IMMEDIATE`/`ON_NEXT_RESUME` tried an in-place JS reload that reused a bundle path fixed at process start, so the same mandatory update kept re-triggering forever. 1.0.2 does a real process restart instead — update to it. |
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
package com.otaupdate
|
|
2
2
|
|
|
3
|
+
import android.content.Intent
|
|
3
4
|
import android.os.Handler
|
|
4
5
|
import android.os.Looper
|
|
5
6
|
import android.util.Log
|
|
6
|
-
import com.facebook.react.ReactApplication
|
|
7
7
|
import com.facebook.react.bridge.Arguments
|
|
8
8
|
import com.facebook.react.bridge.LifecycleEventListener
|
|
9
9
|
import com.facebook.react.bridge.Promise
|
|
@@ -221,33 +221,35 @@ class OtaUpdateModule(private val reactContext: ReactApplicationContext) :
|
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
/**
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
224
|
+
* Restarts the whole process so the new bundle is loaded.
|
|
225
|
+
*
|
|
226
|
+
* This used to try an in-place JS-context reload (ReactHost.reload() via
|
|
227
|
+
* reflection on the new architecture, recreateReactContextInBackground() as
|
|
228
|
+
* a bridge-mode fallback) — but on Android BOTH of those reuse a bundle
|
|
229
|
+
* loader/path that was fixed once at ReactInstanceManager/ReactHost
|
|
230
|
+
* construction time (see ReactInstanceManager#mBundleLoader, a `final`
|
|
231
|
+
* field, and DefaultReactHost's internal singleton caching). Neither ever
|
|
232
|
+
* re-consults MainApplication's getJSBundleFile()/jsBundleFilePath, so an
|
|
233
|
+
* IMMEDIATE or ON_NEXT_RESUME install silently kept reloading the OLD
|
|
234
|
+
* bundle forever — for a mandatory update this produced an infinite
|
|
235
|
+
* reload loop, since the freshly-reloaded old bundle immediately saw the
|
|
236
|
+
* same "mandatory update available" response and tried to install again.
|
|
237
|
+
*
|
|
238
|
+
* A genuine process kill + relaunch is the only reliable way to force
|
|
239
|
+
* MainApplication to re-run from scratch and pick up the new bundle path —
|
|
240
|
+
* the same technique restart libraries like react-native-restart use.
|
|
241
|
+
* iOS does not need this: RCTTriggerReloadCommandListeners re-queries
|
|
242
|
+
* bundleURL() fresh on every reload, so it was never affected.
|
|
227
243
|
*/
|
|
228
244
|
private fun reload() {
|
|
229
|
-
val
|
|
230
|
-
if (application !is ReactApplication) {
|
|
231
|
-
Log.e(OtaUpdateStore.TAG, "Application does not implement ReactApplication — cannot restart")
|
|
232
|
-
return
|
|
233
|
-
}
|
|
234
|
-
|
|
245
|
+
val context = reactContext.applicationContext
|
|
235
246
|
try {
|
|
236
|
-
val
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
if (reactHost != null) {
|
|
241
|
-
reactHost.javaClass.methods
|
|
242
|
-
.firstOrNull { it.name == "reload" && it.parameterTypes.size == 1 }
|
|
243
|
-
?.invoke(reactHost, "OTA update applied")
|
|
244
|
-
?: Log.e(OtaUpdateStore.TAG, "ReactHost has no reload(String) method")
|
|
245
|
-
return
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
application.reactNativeHost.reactInstanceManager.recreateReactContextInBackground()
|
|
247
|
+
val launchIntent = context.packageManager.getLaunchIntentForPackage(context.packageName)
|
|
248
|
+
?: throw IllegalStateException("no launch intent for ${context.packageName}")
|
|
249
|
+
context.startActivity(Intent.makeRestartActivityTask(launchIntent.component))
|
|
250
|
+
Runtime.getRuntime().exit(0)
|
|
249
251
|
} catch (e: Exception) {
|
|
250
|
-
Log.e(OtaUpdateStore.TAG, "failed to restart the
|
|
252
|
+
Log.e(OtaUpdateStore.TAG, "failed to restart the app process", e)
|
|
251
253
|
}
|
|
252
254
|
}
|
|
253
255
|
|
package/lib/OtaUpdate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OtaUpdate.d.ts","sourceRoot":"","sources":["../src/OtaUpdate.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,UAAU,EACV,KAAK,WAAW,EAChB,KAAK,cAAc,EAGnB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EAEf,KAAK,WAAW,EACjB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"OtaUpdate.d.ts","sourceRoot":"","sources":["../src/OtaUpdate.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,UAAU,EACV,KAAK,WAAW,EAChB,KAAK,cAAc,EAGnB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EAEf,KAAK,WAAW,EACjB,MAAM,SAAS,CAAC;AAqGjB,qEAAqE;AACrE,wBAAsB,cAAc,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAOjF;AAED;;;GAGG;AACH,wBAAsB,IAAI,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAUzE;AAqDD;;;;;GAKG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAcpD;AAED,wBAAsB,UAAU,CAAC,qBAAqB,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7E;AAED,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAaxE;AAED,kFAAkF;AAClF,wBAAsB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAElD;AAED,wBAAsB,SAAS,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAE3D;AAMD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,UAAe,GAAG,MAAM,IAAI,CAoClE;AAED,gEAAgE;AAChE,wBAAgB,eAAe,IAAI,IAAI,CAKtC"}
|
package/lib/OtaUpdate.js
CHANGED
|
@@ -13,6 +13,12 @@ const react_native_1 = require("react-native");
|
|
|
13
13
|
const api_1 = require("./api");
|
|
14
14
|
const native_1 = require("./native");
|
|
15
15
|
const types_1 = require("./types");
|
|
16
|
+
/**
|
|
17
|
+
* The one hosted server every app talks to. Native config (Info.plist /
|
|
18
|
+
* strings.xml) can still override this for internal staging use, but no
|
|
19
|
+
* user of the published SDK needs to set it — this is why.
|
|
20
|
+
*/
|
|
21
|
+
const DEFAULT_SERVER_URL = 'https://api.otaupdate.dev';
|
|
16
22
|
let cachedConfig = null;
|
|
17
23
|
let syncInFlight = null;
|
|
18
24
|
let lastSyncAt = 0;
|
|
@@ -20,6 +26,8 @@ let appReadyNotified = false;
|
|
|
20
26
|
async function getConfiguration(overrideDeploymentKey) {
|
|
21
27
|
if (!cachedConfig) {
|
|
22
28
|
cachedConfig = await native_1.NativeOtaUpdate.getConfiguration();
|
|
29
|
+
if (!cachedConfig.serverUrl)
|
|
30
|
+
cachedConfig.serverUrl = DEFAULT_SERVER_URL;
|
|
23
31
|
}
|
|
24
32
|
// Re-read the running package on every call: it changes after an install.
|
|
25
33
|
const current = await native_1.NativeOtaUpdate.getCurrentPackage().catch(() => null);
|
|
@@ -36,10 +44,6 @@ function assertConfigured(config) {
|
|
|
36
44
|
'ota_deployment_key in strings.xml (Android), or pass `deploymentKey` to sync(). ' +
|
|
37
45
|
'With Expo, set it in the config plugin options.');
|
|
38
46
|
}
|
|
39
|
-
if (!config.serverUrl) {
|
|
40
|
-
throw new Error('No OTA server URL configured. Set OtaServerUrl (iOS) / ota_server_url (Android), ' +
|
|
41
|
-
'or the `serverUrl` config plugin option.');
|
|
42
|
-
}
|
|
43
47
|
}
|
|
44
48
|
function toRemotePackage(info, config) {
|
|
45
49
|
const remote = {
|
package/lib/OtaUpdate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OtaUpdate.js","sourceRoot":"","sources":["../src/OtaUpdate.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"OtaUpdate.js","sourceRoot":"","sources":["../src/OtaUpdate.ts"],"names":[],"mappings":";;AAoHA,wCAOC;AAMD,oBAUC;AA2DD,wCAcC;AAED,gCAEC;AAED,8CAaC;AAGD,oCAEC;AAED,8BAEC;AAUD,sCAoCC;AAGD,0CAKC;AAtSD,+CAA6D;AAC7D,+BAA+D;AAC/D,qCAAwF;AACxF,mCAWiB;AAEjB;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,2BAA2B,CAAC;AAEvD,IAAI,YAAY,GAA4B,IAAI,CAAC;AACjD,IAAI,YAAY,GAA+B,IAAI,CAAC;AACpD,IAAI,UAAU,GAAG,CAAC,CAAC;AACnB,IAAI,gBAAgB,GAAG,KAAK,CAAC;AAE7B,KAAK,UAAU,gBAAgB,CAAC,qBAA8B;IAC5D,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,MAAM,wBAAe,CAAC,gBAAgB,EAAE,CAAC;QACxD,IAAI,CAAC,YAAY,CAAC,SAAS;YAAE,YAAY,CAAC,SAAS,GAAG,kBAAkB,CAAC;IAC3E,CAAC;IACD,0EAA0E;IAC1E,MAAM,OAAO,GAAG,MAAM,wBAAe,CAAC,iBAAiB,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IAC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I,IAAI,CAAC,GAAG,EAAE,GAAG,UAAU,GAAG,mBAAmB,GAAG,IAAI;gBAAE,OAAO;YACjE,KAAK,IAAI,CAAC,WAAW,CAAC,CAAC;QACzB,CAAC,CAAC;QACF,MAAM,YAAY,GAAG,uBAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAClE,qBAAqB,GAAG,YAAY,CAAC;IACvC,CAAC;IAED,OAAO,GAAG,EAAE;QACV,qBAAqB,EAAE,MAAM,EAAE,CAAC;QAChC,qBAAqB,GAAG,IAAI,CAAC;IAC/B,CAAC,CAAC;AACJ,CAAC;AAED,gEAAgE;AAChE,SAAgB,eAAe;IAC7B,YAAY,GAAG,IAAI,CAAC;IACpB,YAAY,GAAG,IAAI,CAAC;IACpB,UAAU,GAAG,CAAC,CAAC;IACf,gBAAgB,GAAG,KAAK,CAAC;AAC3B,CAAC"}
|
package/package.json
CHANGED
package/plugin/build/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { ConfigPlugin } from '@expo/config-plugins';
|
|
2
2
|
export interface OtaPluginOptions {
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Overrides the hosted server the SDK talks to. Leave unset — the SDK
|
|
5
|
+
* already defaults to the hosted platform. Only for internal staging use.
|
|
6
|
+
*/
|
|
7
|
+
serverUrl?: string;
|
|
5
8
|
/** Deployment key used on both platforms unless overridden below. */
|
|
6
9
|
deploymentKey?: string;
|
|
7
10
|
iosDeploymentKey?: string;
|
package/plugin/build/index.js
CHANGED
|
@@ -8,15 +8,15 @@ function keysFor(options) {
|
|
|
8
8
|
if (!ios || !android) {
|
|
9
9
|
throw new Error(`[${PACKAGE_NAME}] Missing deployment key. Provide "deploymentKey", or both ` +
|
|
10
10
|
'"iosDeploymentKey" and "androidDeploymentKey", in the plugin options.\n\n' +
|
|
11
|
-
' ["@otaupdate/react-native", { "
|
|
12
|
-
'"iosDeploymentKey": "…", "androidDeploymentKey": "…" }]');
|
|
11
|
+
' ["@otaupdate/react-native", { "iosDeploymentKey": "…", "androidDeploymentKey": "…" }]');
|
|
13
12
|
}
|
|
14
13
|
return { ios, android };
|
|
15
14
|
}
|
|
16
15
|
// --- iOS ---------------------------------------------------------------------
|
|
17
16
|
const withOtaInfoPlist = (config, options) => (0, config_plugins_1.withInfoPlist)(config, (mod) => {
|
|
18
17
|
mod.modResults.OtaDeploymentKey = keysFor(options).ios;
|
|
19
|
-
|
|
18
|
+
if (options.serverUrl)
|
|
19
|
+
mod.modResults.OtaServerUrl = options.serverUrl;
|
|
20
20
|
return mod;
|
|
21
21
|
});
|
|
22
22
|
/**
|
|
@@ -65,11 +65,12 @@ const withOtaAppDelegate = (config) => (0, config_plugins_1.withAppDelegate)(con
|
|
|
65
65
|
// --- Android -----------------------------------------------------------------
|
|
66
66
|
const withOtaStrings = (config, options) => (0, config_plugins_1.withStringsXml)(config, (mod) => {
|
|
67
67
|
const { android } = keysFor(options);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
{ $: { name: 'ota_server_url', translatable: 'false' }, _: options.serverUrl }
|
|
72
|
-
|
|
68
|
+
// translatable=false keeps these out of localisation exports.
|
|
69
|
+
const items = [{ $: { name: 'ota_deployment_key', translatable: 'false' }, _: android }];
|
|
70
|
+
if (options.serverUrl) {
|
|
71
|
+
items.push({ $: { name: 'ota_server_url', translatable: 'false' }, _: options.serverUrl });
|
|
72
|
+
}
|
|
73
|
+
mod.modResults = config_plugins_1.AndroidConfig.Strings.setStringItem(items, mod.modResults);
|
|
73
74
|
return mod;
|
|
74
75
|
});
|
|
75
76
|
// Note: there is deliberately no MainApplication patch on Android.
|
|
@@ -84,10 +85,6 @@ const withOtaStrings = (config, options) => (0, config_plugins_1.withStringsXml)
|
|
|
84
85
|
// changes — it already did, against the RN 0.86 template.
|
|
85
86
|
// --- Entry point --------------------------------------------------------------
|
|
86
87
|
const withOtaUpdate = (config, options) => {
|
|
87
|
-
if (!options?.serverUrl) {
|
|
88
|
-
throw new Error(`[${PACKAGE_NAME}] "serverUrl" is required.\n\n` +
|
|
89
|
-
' ["@otaupdate/react-native", { "serverUrl": "https://ota.example.com", "deploymentKey": "…" }]');
|
|
90
|
-
}
|
|
91
88
|
keysFor(options); // fail fast at config time rather than at build time
|
|
92
89
|
config = withOtaInfoPlist(config, options);
|
|
93
90
|
config = withOtaAppDelegate(config);
|
package/src/OtaUpdate.ts
CHANGED
|
@@ -14,6 +14,13 @@ import {
|
|
|
14
14
|
type SyncOptions,
|
|
15
15
|
} from './types';
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* The one hosted server every app talks to. Native config (Info.plist /
|
|
19
|
+
* strings.xml) can still override this for internal staging use, but no
|
|
20
|
+
* user of the published SDK needs to set it — this is why.
|
|
21
|
+
*/
|
|
22
|
+
const DEFAULT_SERVER_URL = 'https://api.otaupdate.dev';
|
|
23
|
+
|
|
17
24
|
let cachedConfig: OtaConfiguration | null = null;
|
|
18
25
|
let syncInFlight: Promise<SyncStatus> | null = null;
|
|
19
26
|
let lastSyncAt = 0;
|
|
@@ -22,6 +29,7 @@ let appReadyNotified = false;
|
|
|
22
29
|
async function getConfiguration(overrideDeploymentKey?: string): Promise<OtaConfiguration> {
|
|
23
30
|
if (!cachedConfig) {
|
|
24
31
|
cachedConfig = await NativeOtaUpdate.getConfiguration();
|
|
32
|
+
if (!cachedConfig.serverUrl) cachedConfig.serverUrl = DEFAULT_SERVER_URL;
|
|
25
33
|
}
|
|
26
34
|
// Re-read the running package on every call: it changes after an install.
|
|
27
35
|
const current = await NativeOtaUpdate.getCurrentPackage().catch(() => null);
|
|
@@ -41,12 +49,6 @@ function assertConfigured(config: OtaConfiguration): void {
|
|
|
41
49
|
'With Expo, set it in the config plugin options.',
|
|
42
50
|
);
|
|
43
51
|
}
|
|
44
|
-
if (!config.serverUrl) {
|
|
45
|
-
throw new Error(
|
|
46
|
-
'No OTA server URL configured. Set OtaServerUrl (iOS) / ota_server_url (Android), ' +
|
|
47
|
-
'or the `serverUrl` config plugin option.',
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
function toRemotePackage(
|