Skip to content

Commit

Permalink
Revert "Revert "Set up codepush (#3109)""
Browse files Browse the repository at this point in the history
This reverts commit cc7bfe1.
  • Loading branch information
estebanmino committed Apr 5, 2022
1 parent e739f3d commit 6754fc9
Show file tree
Hide file tree
Showing 15 changed files with 596 additions and 41 deletions.
5 changes: 4 additions & 1 deletion android/app/build.gradle
Expand Up @@ -112,7 +112,7 @@ project.ext.react = [

apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/@sentry/react-native/sentry.gradle"

apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"

/**
* Set this to true to create two separate APKs instead of one:
Expand Down Expand Up @@ -185,6 +185,9 @@ android {
}

defaultConfig {
// https://github.com/microsoft/react-native-code-push/issues/1961#issuecomment-710698621
resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())
resValue 'string', "CodePushDeploymentKey", env.get('CODE_PUSH_DEPLOYMENT_KEY_ANDROID')
applicationId "me.rainbow"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
Expand Down
7 changes: 6 additions & 1 deletion android/app/src/main/java/me/rainbow/MainApplication.java
Expand Up @@ -25,7 +25,7 @@
import me.rainbow.NativeModules.RNReview.RNReviewPackage;
import me.rainbow.NativeModules.RNTextAnimatorPackage.RNTextAnimatorPackage;
import me.rainbow.NativeModules.RNZoomableButton.RNZoomableButtonPackage;

import com.microsoft.codepush.react.CodePush;

class RainbowJSIModulePackage extends ReanimatedJSIModulePackage {
@Override
Expand All @@ -45,6 +45,11 @@ public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}

@Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
}

@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/res/values/strings.xml
@@ -1,3 +1,5 @@
<resources>
<string name="app_name">Rainbow</string>
<string name="appCenterCrashes_whenToSendCrashes" moduleConfig="true" translatable="false">DONT_SEND</string>
<string name="appCenterAnalytics_whenToEnableAnalytics" moduleConfig="true" translatable="false">DONT_SEND</string>
</resources>
3 changes: 2 additions & 1 deletion audit-ci.json
Expand Up @@ -9,7 +9,8 @@
1059778,
1065064,
1067259,
1067282
1067282,
1067309
],
"registry": "https://registry.npmjs.org"
}
33 changes: 33 additions & 0 deletions ios/Podfile.lock
@@ -1,10 +1,22 @@
PODS:
- Analytics (4.1.6)
- appcenter-core (4.4.3):
- AppCenterReactNativeShared (~> 4.0)
- React-Core
- AppCenter/Core (4.4.1)
- AppCenterReactNativeShared (4.4.3):
- AppCenter/Core (= 4.4.1)
- Base64 (1.1.2)
- boost (1.76.0)
- Branch (1.40.2)
- BVLinearGradient (2.5.6):
- React
- CocoaAsyncSocket (7.6.5)
- CodePush (7.0.4):
- Base64 (~> 1.1)
- JWT (~> 3.0.0-beta.12)
- React-Core
- SSZipArchive (~> 2.2.2)
- DoubleConversion (1.1.6)
- FBLazyVector (0.66.4)
- FBReactNativeSpec (0.66.4):
Expand Down Expand Up @@ -88,6 +100,8 @@ PODS:
- GoogleUtilities/UserDefaults (7.7.0):
- GoogleUtilities/Logger
- hermes-engine (0.9.0)
- JWT (3.0.0-beta.14):
- Base64 (~> 1.1.2)
- KTVCocoaHTTPServer (1.0.0):
- CocoaAsyncSocket
- KTVHTTPCache (2.0.1):
Expand Down Expand Up @@ -586,6 +600,7 @@ PODS:
- Shimmer (1.0.2)
- SRSRadialGradient (1.0.9):
- React
- SSZipArchive (2.2.3)
- swift-vibrant (1.0.0)
- TcpSockets (3.3.2):
- CocoaAsyncSocket
Expand All @@ -596,8 +611,10 @@ PODS:
- Yoga (1.14.0)

DEPENDENCIES:
- appcenter-core (from `../node_modules/appcenter/ios`)
- boost (from `../node_modules/react-native/third-party-podspecs/boost.podspec`)
- BVLinearGradient (from `../node_modules/react-native-linear-gradient`)
- CodePush (from `../node_modules/react-native-code-push`)
- DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`)
- FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`)
- FBReactNativeSpec (from `../node_modules/react-native/React/FBReactNativeSpec`)
Expand Down Expand Up @@ -706,6 +723,9 @@ DEPENDENCIES:
SPEC REPOS:
trunk:
- Analytics
- AppCenter
- AppCenterReactNativeShared
- Base64
- Branch
- CocoaAsyncSocket
- Firebase
Expand All @@ -721,6 +741,7 @@ SPEC REPOS:
- GoogleDataTransport
- GoogleUtilities
- hermes-engine
- JWT
- KTVCocoaHTTPServer
- KTVHTTPCache
- libevent
Expand All @@ -733,14 +754,19 @@ SPEC REPOS:
- SDWebImageWebPCoder
- Sentry
- Shimmer
- SSZipArchive
- swift-vibrant
- TOCropViewController

EXTERNAL SOURCES:
appcenter-core:
:path: "../node_modules/appcenter/ios"
boost:
:podspec: "../node_modules/react-native/third-party-podspecs/boost.podspec"
BVLinearGradient:
:path: "../node_modules/react-native-linear-gradient"
CodePush:
:path: "../node_modules/react-native-code-push"
DoubleConversion:
:podspec: "../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec"
FBLazyVector:
Expand Down Expand Up @@ -942,10 +968,15 @@ CHECKOUT OPTIONS:

SPEC CHECKSUMS:
Analytics: eefe524436f904b8bb3f8c8c3425280e43b34efc
AppCenter: b0b6f1190215b5f983c42934db718f3b46fff3c0
appcenter-core: 6ea4754df4a3d8917a5803e2681a58179d7f7a21
AppCenterReactNativeShared: ac6961204492735ce2507df0a14ce59b13e9c1c5
Base64: cecfb41a004124895a7bcee567a89bae5a89d49b
boost: a7c83b31436843459a1961bfd74b96033dc77234
Branch: c1b244bf1170b0ea5c5eefa897648de8d14ff0d2
BVLinearGradient: e3aad03778a456d77928f594a649e96995f1c872
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
CodePush: b51b7ac64c07d4eacfc8cc5750a1dd28adbf2528
DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662
FBLazyVector: e5569e42a1c79ca00521846c223173a57aca1fe1
FBReactNativeSpec: fe08c1cd7e2e205718d77ad14b34957cce949b58
Expand All @@ -963,6 +994,7 @@ SPEC CHECKSUMS:
GoogleDataTransport: 629c20a4d363167143f30ea78320d5a7eb8bd940
GoogleUtilities: e0913149f6b0625b553d70dae12b49fc62914fd1
hermes-engine: bf7577d12ac6ccf53ab8b5af3c6ccf0dd8458c5c
JWT: ef71dfb03e1f842081e64dc42eef0e164f35d251
KTVCocoaHTTPServer: df8d7b861e603ff8037e9b2138aca2563a6b768d
KTVHTTPCache: 588c3eb16f6bd1e6fde1e230dabfb7bd4e490a4d
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
Expand Down Expand Up @@ -1064,6 +1096,7 @@ SPEC CHECKSUMS:
Sentry: 2f7e91f247cfb05b05bd01e0b5d0692557a7687b
Shimmer: c5374be1c2b0c9e292fb05b339a513cf291cac86
SRSRadialGradient: a372b4b3bc65a2f3b1a16b906485cff204e1db3e
SSZipArchive: 62d4947b08730e4cda640473b0066d209ff033c9
swift-vibrant: 3def73c5c281db74f420ec386590d9c1c5b0995c
TcpSockets: bd31674146c0931a064fc254a59812dfd1a73ae0
TOCropViewController: edfd4f25713d56905ad1e0b9f5be3fbe0f59c863
Expand Down
4 changes: 2 additions & 2 deletions ios/Rainbow/AppDelegate.mm
Expand Up @@ -16,7 +16,7 @@
#import "RNSplashScreen.h"
#import <AVFoundation/AVFoundation.h>
#import <mach/mach.h>

#import <CodePush/CodePush.h>


@interface RainbowSplashScreenManager : NSObject <RCTBridgeModule>
Expand Down Expand Up @@ -126,7 +126,7 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
return [CodePush bundleURL];
#endif
}

Expand Down
2 changes: 2 additions & 0 deletions ios/Rainbow/Info.plist
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CodePushDeploymentKey</key>
<string>$(CODE_PUSH_DEPLOYMENT_KEY_IOS)</string>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -110,6 +110,7 @@
"@unstoppabledomains/resolution": "5.0.2",
"@walletconnect/client": "1.6.6",
"@walletconnect/utils": "1.6.6",
"appcenter": "4.4.3",
"assert": "1.5.0",
"async-mutex": "0.3.2",
"asyncstorage-down": "4.2.0",
Expand Down Expand Up @@ -185,6 +186,7 @@
"react-native-camera": "4.2.1",
"react-native-circular-progress": "1.3.6",
"react-native-cloud-fs": "brunobar79/react-native-cloud-fs#e7e3111fb427b6df5e97f61c700ca1e64636cad8",
"react-native-code-push": "7.0.4",
"react-native-crypto": "2.2.0",
"react-native-dark-mode": "0.2.2",
"react-native-device-info": "5.3.1",
Expand Down
5 changes: 5 additions & 0 deletions scripts/postinstall.sh
Expand Up @@ -44,6 +44,11 @@ source .env
cat .env | grep "GOOGLE" | sed 's/=/ = /g' >> ./ios/localrelease.xcconfig
cat .env | grep "GOOGLE" | sed 's/=/ = /g' >> ./ios/staging.xcconfig

cat .env | grep "CODE_PUSH_DEPLOYMENT_KEY_IOS" | sed 's/=/ = /g' >> ./ios/debug.xcconfig
cat .env | grep "CODE_PUSH_DEPLOYMENT_KEY_IOS" | sed 's/=/ = /g' >> ./ios/release.xcconfig
cat .env | grep "CODE_PUSH_DEPLOYMENT_KEY_IOS" | sed 's/=/ = /g' >> ./ios/localrelease.xcconfig
cat .env | grep "CODE_PUSH_DEPLOYMENT_KEY_IOS" | sed 's/=/ = /g' >> ./ios/staging.xcconfig

# Override Google Services API Key
if [ -n "$GOOGLE_SERVICE_API_KEY" ]; then
sed -i''-e "s/\$(GOOGLE_SERVICE_API_KEY)/$GOOGLE_SERVICE_API_KEY/" ./ios/Frameworks/GoogleService-Info.plist
Expand Down
38 changes: 27 additions & 11 deletions src/App.js
Expand Up @@ -16,6 +16,8 @@ import {
StatusBar,
View,
} from 'react-native';
// eslint-disable-next-line import/default
import codePush from 'react-native-code-push';
import {
REACT_APP_SEGMENT_API_WRITE_KEY,
SENTRY_ENDPOINT,
Expand All @@ -26,6 +28,7 @@ import {
import RNIOS11DeviceCheck from 'react-native-ios11-devicecheck';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { enableScreens } from 'react-native-screens';
import VersionNumber from 'react-native-version-number';
import { QueryClientProvider } from 'react-query';
import { connect, Provider } from 'react-redux';
import { RecoilRoot } from 'recoil';
Expand Down Expand Up @@ -77,17 +80,26 @@ if (__DEV__) {
(showNetworkRequests || showNetworkResponses) &&
monitorNetwork(showNetworkRequests, showNetworkResponses);
} else {
let sentryOptions = {
dsn: SENTRY_ENDPOINT,
enableAutoSessionTracking: true,
environment: SENTRY_ENVIRONMENT,
integrations: [
new Sentry.ReactNativeTracing({
tracingOrigins: ['localhost', /^\//],
// eslint-disable-next-line no-inner-declarations
async function initSentry() {
const metadata = await codePush.getUpdateMetadata();
const sentryOptions = {
dsn: SENTRY_ENDPOINT,
enableAutoSessionTracking: true,
environment: SENTRY_ENVIRONMENT,
integrations: [
new Sentry.ReactNativeTracing({
tracingOrigins: ['localhost', /^\//],
}),
],
...(metadata && {
dist: metadata.label,
release: `${metadata.appVersion} (${VersionNumber.buildVersion}) (CP ${metadata.label})`,
}),
],
};
Sentry.init(sentryOptions);
};
Sentry.init(sentryOptions);
}
initSentry();
}

enableScreens();
Expand Down Expand Up @@ -306,6 +318,10 @@ const AppWithRedux = connect(

const AppWithReduxStore = () => <AppWithRedux store={store} />;

const AppWithSentry = Sentry.wrap(AppWithReduxStore);

const AppWithCodePush = codePush(AppWithSentry);

AppRegistry.registerComponent('Rainbow', () =>
designSystemPlaygroundEnabled ? Playground : Sentry.wrap(AppWithReduxStore)
designSystemPlaygroundEnabled ? Playground : AppWithCodePush
);
13 changes: 10 additions & 3 deletions src/components/AppVersionStamp.js
Expand Up @@ -24,7 +24,7 @@ const StampText = styled(Text).attrs(({ theme: { colors } }) => ({
}))({});

export default function AppVersionStamp() {
const appVersion = useAppVersion();
const [appVersion, codePushVersion] = useAppVersion();
const [numberOfTaps, setNumberOfTaps] = useState(0);
const [startTimeout, stopTimeout] = useTimeout();
const { navigate } = useNavigation();
Expand All @@ -41,10 +41,17 @@ export default function AppVersionStamp() {
}
startTimeout(() => setNumberOfTaps(0), 3000);
}, [navigate, numberOfTaps, startTimeout, stopTimeout]);
const [showCodePushVersion, setShowCodePushVersion] = useState(false);

return (
<StyledButton onPress={handleVersionPress}>
<StampText>{appVersion}</StampText>
<StyledButton
onLongPress={() => setShowCodePushVersion(true)}
onPress={handleVersionPress}
onPressOut={() => setTimeout(() => setShowCodePushVersion(false), 500)}
>
<StampText>
{showCodePushVersion ? `Update: ${codePushVersion}` : appVersion}
</StampText>
</StyledButton>
);
}
30 changes: 30 additions & 0 deletions src/components/settings-menu/DevSection.js
@@ -1,10 +1,13 @@
import AsyncStorage from '@react-native-community/async-storage';
import React, { useCallback, useContext } from 'react';
import { Alert, ScrollView } from 'react-native';
// eslint-disable-next-line import/default
import codePush from 'react-native-code-push';
import { HARDHAT_URL_ANDROID, HARDHAT_URL_IOS } from 'react-native-dotenv';
import Restart from 'react-native-restart';
import { useDispatch } from 'react-redux';
import { defaultConfig } from '../../config/experimental';
import useAppVersion from '../../hooks/useAppVersion';
import { ListFooter, ListItem } from '../list';
import { RadioListItem } from '../radio-list';
import UserDevSection from './UserDevSection';
Expand Down Expand Up @@ -52,6 +55,26 @@ const DevSection = () => {
dispatch(explorerInit());
}, [dispatch, navigate]);

const syncCodepush = useCallback(async () => {
const isUpdate = !!(await codePush.checkForUpdate());
if (!isUpdate) {
Alert.alert('No update');
} else {
// dismissing not to fuck up native nav structure
navigate(Routes.PROFILE_SCREEN);
Alert.alert('Installing update');

const result = await codePush.sync({
installMode: codePush.InstallMode.IMMEDIATE,
});

const resultString = Object.entries(codePush.syncStatus).find(
e => e[1] === result
)[0];
Alert.alert(resultString);
}
}, [navigate]);

const checkAlert = useCallback(async () => {
try {
const request = await fetch(
Expand Down Expand Up @@ -89,6 +112,8 @@ const DevSection = () => {
setErrorObj({ error: 'this throws render error' });
};

const codePushVersion = useAppVersion()[1];

return (
<ScrollView testID="developer-settings-modal">
<ListItem label="💥 Clear async storage" onPress={AsyncStorage.clear} />
Expand Down Expand Up @@ -126,6 +151,11 @@ const DevSection = () => {

<UserDevSection scrollEnabled={false} />

<ListItem
label={`‍⏩ Sync codepush, current: ${codePushVersion}`}
onPress={syncCodepush}
/>

{Object.keys(config)
.sort()
.filter(key => defaultConfig[key]?.settings)
Expand Down

0 comments on commit 6754fc9

Please sign in to comment.