@bravemobile/react-native-code-push 12.4.0 → 13.0.0
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/CodePush.podspec +14 -1
- package/README.md +4 -1
- package/android/app/build.gradle +7 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +45 -10
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +82 -98
- package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgress.java +4 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressEventDispatcher.java +23 -0
- package/cli/dist/functions/runHermesEmitBinaryCommand.js +50 -26
- package/cli/functions/runHermesEmitBinaryCommand.ts +55 -25
- package/ios/CodePush/CodePush.h +40 -8
- package/ios/CodePush/{CodePush.m → CodePush.mm} +61 -62
- package/ios/CodePush.xcodeproj/project.pbxproj +6 -6
- package/package.json +19 -2
- package/react-native.config.js +3 -1
- package/src/CodePush.js +144 -93
- package/src/native/NativeCodePush.ts +162 -0
- package/src/package-mixins.js +4 -9
- package/src/specs/NativeCodePush.ts +43 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java +0 -102
- package/src/AlertAdapter.js +0 -24
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
2
|
+
import type { TurboModule } from 'react-native';
|
|
3
|
+
import type {
|
|
4
|
+
EventEmitter,
|
|
5
|
+
UnsafeObject,
|
|
6
|
+
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
7
|
+
|
|
8
|
+
export type DownloadProgress = {
|
|
9
|
+
receivedBytes: number;
|
|
10
|
+
totalBytes: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export interface Spec extends TurboModule {
|
|
14
|
+
downloadUpdate(updatePackage: UnsafeObject, notifyProgress: boolean): Promise<UnsafeObject>;
|
|
15
|
+
getConfiguration(): Promise<UnsafeObject>;
|
|
16
|
+
getUpdateMetadata(updateState: number): Promise<UnsafeObject | null>;
|
|
17
|
+
getNewStatusReport(): Promise<UnsafeObject | null>;
|
|
18
|
+
installUpdate(
|
|
19
|
+
updatePackage: UnsafeObject,
|
|
20
|
+
installMode: number,
|
|
21
|
+
minimumBackgroundDuration: number,
|
|
22
|
+
): Promise<void>;
|
|
23
|
+
isFailedUpdate(packageHash: string): Promise<boolean>;
|
|
24
|
+
getLatestRollbackInfo(): Promise<UnsafeObject | null>;
|
|
25
|
+
setLatestRollbackInfo(packageHash: string): Promise<void>;
|
|
26
|
+
isFirstRun(packageHash: string): Promise<boolean>;
|
|
27
|
+
notifyApplicationReady(): Promise<void>;
|
|
28
|
+
allow(): void;
|
|
29
|
+
disallow(): void;
|
|
30
|
+
clearPendingRestart(): void;
|
|
31
|
+
restartApp(onlyIfUpdateIsPending: boolean): void;
|
|
32
|
+
recordStatusReported(statusReport: UnsafeObject): void;
|
|
33
|
+
saveStatusReportForRetry(statusReport: UnsafeObject): void;
|
|
34
|
+
clearUpdates(): void;
|
|
35
|
+
|
|
36
|
+
readonly onDownloadProgress: EventEmitter<DownloadProgress>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function getNativeCodePushTurboModule(): Spec | null {
|
|
40
|
+
return TurboModuleRegistry.get<Spec>('CodePush');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default getNativeCodePushTurboModule();
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
package com.microsoft.codepush.react;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.app.AlertDialog;
|
|
5
|
-
import android.content.DialogInterface;
|
|
6
|
-
|
|
7
|
-
import com.facebook.react.bridge.Callback;
|
|
8
|
-
import com.facebook.react.bridge.LifecycleEventListener;
|
|
9
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
10
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
11
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
12
|
-
|
|
13
|
-
public class CodePushDialog extends ReactContextBaseJavaModule{
|
|
14
|
-
|
|
15
|
-
public CodePushDialog(ReactApplicationContext reactContext) {
|
|
16
|
-
super(reactContext);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@ReactMethod
|
|
20
|
-
public void showDialog(final String title, final String message, final String button1Text,
|
|
21
|
-
final String button2Text, final Callback successCallback, Callback errorCallback) {
|
|
22
|
-
Activity currentActivity = getCurrentActivity();
|
|
23
|
-
if (currentActivity == null || currentActivity.isFinishing()) {
|
|
24
|
-
// If getCurrentActivity is null, it could be because the app is backgrounded,
|
|
25
|
-
// so we show the dialog when the app resumes)
|
|
26
|
-
getReactApplicationContext().addLifecycleEventListener(new LifecycleEventListener() {
|
|
27
|
-
@Override
|
|
28
|
-
public void onHostResume() {
|
|
29
|
-
Activity currentActivity = getCurrentActivity();
|
|
30
|
-
if (currentActivity != null) {
|
|
31
|
-
getReactApplicationContext().removeLifecycleEventListener(this);
|
|
32
|
-
showDialogInternal(title, message, button1Text, button2Text, successCallback, currentActivity);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@Override
|
|
37
|
-
public void onHostPause() {
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@Override
|
|
42
|
-
public void onHostDestroy() {
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
} else {
|
|
47
|
-
showDialogInternal(title, message, button1Text, button2Text, successCallback, currentActivity);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
private void showDialogInternal(String title, String message, String button1Text,
|
|
52
|
-
String button2Text, final Callback successCallback, Activity currentActivity) {
|
|
53
|
-
AlertDialog.Builder builder = new AlertDialog.Builder(currentActivity);
|
|
54
|
-
|
|
55
|
-
builder.setCancelable(false);
|
|
56
|
-
|
|
57
|
-
DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
|
|
58
|
-
@Override
|
|
59
|
-
public void onClick(DialogInterface dialog, int which) {
|
|
60
|
-
try {
|
|
61
|
-
dialog.cancel();
|
|
62
|
-
switch (which) {
|
|
63
|
-
case DialogInterface.BUTTON_POSITIVE:
|
|
64
|
-
successCallback.invoke(0);
|
|
65
|
-
break;
|
|
66
|
-
case DialogInterface.BUTTON_NEGATIVE:
|
|
67
|
-
successCallback.invoke(1);
|
|
68
|
-
break;
|
|
69
|
-
default:
|
|
70
|
-
throw new CodePushUnknownException("Unknown button ID pressed.");
|
|
71
|
-
}
|
|
72
|
-
} catch (Throwable e) {
|
|
73
|
-
CodePushUtils.log(e);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
if (title != null) {
|
|
79
|
-
builder.setTitle(title);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (message != null) {
|
|
83
|
-
builder.setMessage(message);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (button1Text != null) {
|
|
87
|
-
builder.setPositiveButton(button1Text, clickListener);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (button2Text != null) {
|
|
91
|
-
builder.setNegativeButton(button2Text, clickListener);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
AlertDialog dialog = builder.create();
|
|
95
|
-
dialog.show();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
@Override
|
|
99
|
-
public String getName() {
|
|
100
|
-
return "CodePushDialog";
|
|
101
|
-
}
|
|
102
|
-
}
|
package/src/AlertAdapter.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import React, { Platform } from "react-native";
|
|
2
|
-
let { Alert } = React;
|
|
3
|
-
|
|
4
|
-
if (Platform.OS === "android") {
|
|
5
|
-
const { NativeModules: { CodePushDialog } } = React;
|
|
6
|
-
|
|
7
|
-
Alert = {
|
|
8
|
-
alert(title, message, buttons) {
|
|
9
|
-
if (buttons.length > 2) {
|
|
10
|
-
throw "Can only show 2 buttons for Android dialog.";
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const button1Text = buttons[0] ? buttons[0].text : null,
|
|
14
|
-
button2Text = buttons[1] ? buttons[1].text : null;
|
|
15
|
-
|
|
16
|
-
CodePushDialog.showDialog(
|
|
17
|
-
title, message, button1Text, button2Text,
|
|
18
|
-
(buttonId) => { buttons[buttonId].onPress && buttons[buttonId].onPress(); },
|
|
19
|
-
(error) => { throw error; });
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
module.exports = { Alert };
|