Skip to content

Commit a59f0c6

Browse files
authored
Fix/mobile-env-vars-ios-crashes (#3124)
* fix android env var passthrough * fix android studio build * fix ios crash on captcha
1 parent 7fcf314 commit a59f0c6

File tree

8 files changed

+76
-62
lines changed

8 files changed

+76
-62
lines changed

packages/desktop/.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Node environment
22
COLORIZE=true
33
QSS_ALLOWED=true
4+
QPS_ALLOWED=true
45
QSS_ENDPOINT=ws://127.0.0.1:3003
56
LOG_TO_FILE=true
67
ENVFILE=.env.development

packages/mobile/.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ SHOULD_RUN_BACKEND_WORKER=true
44
COLORIZE=false
55
QSS_ALLOWED=true
66
QSS_ENDPOINT=ws://127.0.0.1:3003
7+
QPS_ALLOWED=true

packages/mobile/android/app/build.gradle

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,6 @@ android {
213213
}
214214
}
215215
}
216-
buildTypes.each {
217-
it.buildConfigField("Boolean", "SHOULD_RUN_BACKEND_WORKER", "true")
218-
it.buildConfigField("Boolean", "QSS_ALLOWED", "false")
219-
it.buildConfigField("String", "QSS_ENDPOINT", "\"\"")
220-
it.buildConfigField("Boolean", "DEBUG", "false")
221-
}
222216
buildTypes {
223217
debug {
224218
signingConfig = signingConfigs.debug

packages/mobile/android/app/src/main/java/com/quietmobile/Backend/BackendWorker.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,18 @@ class BackendWorker(private val context: Context, workerParams: WorkerParameters
232232
command.add(scriptPath)
233233
command.addAll(args)
234234

235-
val envVars = mutableListOf<String>()
236-
envVars.add("QSS_ALLOWED=${BuildConfig.QSS_ALLOWED}")
237-
envVars.add("QSS_ENDPOINT=${BuildConfig.QSS_ENDPOINT}")
235+
val standardFields = setOf(
236+
"DEBUG", "APPLICATION_ID", "BUILD_TYPE", "FLAVOR",
237+
"VERSION_CODE", "VERSION_NAME", "LIBRARY_PACKAGE_NAME",
238+
"IS_NEW_ARCHITECTURE_ENABLED", "IS_HERMES_ENABLED"
239+
)
240+
val envVars = BuildConfig::class.java.fields
241+
.filter { it.name !in standardFields }
242+
.mapNotNull { field ->
243+
field.get(null)?.let { value -> "${field.name}=$value" }
244+
}
245+
.also { vars -> vars.forEach { Log.d("BackendWorker", "Passing env var: $it") } }
246+
.toMutableList()
238247

239248
nodeProject.waitForInit()
240249

packages/mobile/android/app/src/main/java/com/quietmobile/MainActivity.kt

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,17 @@ class MainActivity : ReactActivity() {
3535
* which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
3636
*/
3737
override fun createReactActivityDelegate(): ReactActivityDelegate =
38-
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
38+
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
3939

4040
override fun onCreate(savedInstanceState: Bundle?) {
41-
// pass null to super.onCreate https://github.com/software-mansion/react-native-screens?tab=readme-ov-file#android
41+
// pass null to super.onCreate
42+
// https://github.com/software-mansion/react-native-screens?tab=readme-ov-file#android
4243
super.onCreate(null)
4344

4445
val intent = intent
4546
checkAgainstIntentUpdate(intent)
4647

47-
if (BuildConfig.SHOULD_RUN_BACKEND_WORKER) {
48+
if (BuildConfig.SHOULD_RUN_BACKEND_WORKER == "true") {
4849
val context = applicationContext
4950
BackendWorkManager(context).enqueueRequests()
5051
}
@@ -63,16 +64,14 @@ class MainActivity : ReactActivity() {
6364

6465
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
6566
private fun checkNotificationsPermission() {
66-
if (ContextCompat.checkSelfPermission(
67-
this,
68-
Manifest.permission.POST_NOTIFICATIONS
69-
) != PackageManager.PERMISSION_GRANTED
67+
if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) !=
68+
PackageManager.PERMISSION_GRANTED
7069
) {
7170
// Requesting the permission
7271
ActivityCompat.requestPermissions(
73-
this,
74-
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
75-
NOTIFICATION_PERMISSION_REQUEST_CODE
72+
this,
73+
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
74+
NOTIFICATION_PERMISSION_REQUEST_CODE
7675
)
7776
}
7877
}
@@ -103,12 +102,13 @@ class MainActivity : ReactActivity() {
103102

104103
@Throws(java.lang.Exception::class)
105104
private fun respondOnNotification(bundle: Bundle) {
106-
val channel = bundle.getString("channel")
107-
?: throw java.lang.Exception("respondOnNotification() failed because of missing channel")
105+
val channel =
106+
bundle.getString("channel")
107+
?: throw java.lang.Exception(
108+
"respondOnNotification() failed because of missing channel"
109+
)
108110

109-
getCurrentReactContext { context: ReactContext ->
110-
emitSwitchChannelEvent(context, channel)
111-
}
111+
getCurrentReactContext { context: ReactContext -> emitSwitchChannelEvent(context, channel) }
112112
}
113113

114114
@SuppressLint("VisibleForTests")
@@ -117,19 +117,20 @@ class MainActivity : ReactActivity() {
117117
if (null != reactContext) {
118118
callback(reactContext)
119119
} else {
120-
reactInstanceManager.addReactInstanceEventListener(object : ReactInstanceEventListener {
121-
override fun onReactContextInitialized(context: ReactContext) {
122-
callback(context)
123-
reactInstanceManager.removeReactInstanceEventListener(this)
124-
}
125-
})
120+
reactInstanceManager.addReactInstanceEventListener(
121+
object : ReactInstanceEventListener {
122+
override fun onReactContextInitialized(context: ReactContext) {
123+
callback(context)
124+
reactInstanceManager.removeReactInstanceEventListener(this)
125+
}
126+
}
127+
)
126128
}
127129
}
128130

129131
private fun emitSwitchChannelEvent(reactContext: ReactContext, channel: String) {
130-
val deviceEventEmitter: RCTDeviceEventEmitter = reactContext.getJSModule(
131-
RCTDeviceEventEmitter::class.java
132-
)
132+
val deviceEventEmitter: RCTDeviceEventEmitter =
133+
reactContext.getJSModule(RCTDeviceEventEmitter::class.java)
133134

134135
deviceEventEmitter.emit("notification", channel)
135136
}

packages/mobile/android/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ allprojects {
3737
}
3838

3939
apply plugin: "com.facebook.react.rootproject"
40+
41+
ext {
42+
REACT_NATIVE_NODE_MODULES_DIR = file("$rootDir/../node_modules/react-native")
43+
}

packages/mobile/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"version": "7.0.0",
44
"scripts": {
55
"build": "tsc -p tsconfig.build.json --noEmit",
6-
"storybook-android": "ENVFILE=.env.storybook react-native run-android --mode=storybookDebug --appIdSuffix=storybook.debug",
6+
"storybook-android": "react-native run-android --mode=storybookDebug --appIdSuffix=storybook.debug",
77
"storybook-ios": "ENVFILE=.env.storybook react-native run-ios",
8-
"android": "ENVFILE=.env.development react-native run-android --mode=standardDebug --appIdSuffix=debug",
8+
"android": "react-native run-android --mode=standardDebug --appIdSuffix=debug",
99
"ios": "ENVFILE=.env.development react-native run-ios",
1010
"start": "react-native start",
1111
"test": "TZ=UTC jest --testPathIgnorePatterns=\"./e2e\" --transformIgnorePatterns \"./node_modules/(?!@d11/react-native-fast-image)/\"",

packages/mobile/src/components/ModalBottomDrawer/drawers/Captcha.drawer.tsx

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -130,35 +130,39 @@ export const CaptchaDrawer: FC = () => {
130130
)
131131

132132
return (
133-
<ModalBottomDrawer visible={visible} onClose={closeScreen} heightRatio={1}>
134-
<View style={styles.container}>
135-
<View style={styles.content}>
136-
<Text style={styles.title}>Prove you are human</Text>
137-
<Text style={styles.description}>Complete the challenge to continue.</Text>
138-
{status === 'loading' && (
139-
<View style={styles.indicatorRow}>
140-
<ActivityIndicator color={defaultTheme.palette.background.lushSky} />
141-
<Text style={styles.secondaryText}>Loading challenge…</Text>
142-
</View>
143-
)}
144-
{errorMessage && (
145-
<View style={styles.errorBanner}>
146-
<Text style={styles.errorText}>{errorMessage}</Text>
147-
<TouchableOpacity style={styles.retryButton} onPress={handleRetry}>
148-
<Text style={styles.retryLabel}>Try again</Text>
149-
</TouchableOpacity>
150-
</View>
151-
)}
152-
<TouchableOpacity
153-
onPress={() => closeScreen('Captcha screen cancelled via button')}
154-
style={styles.cancelButton}
155-
>
156-
<Text style={styles.cancelLabel}>Cancel</Text>
157-
</TouchableOpacity>
133+
<>
134+
<ModalBottomDrawer visible={visible} onClose={closeScreen} heightRatio={1}>
135+
<View style={styles.container}>
136+
<View style={styles.content}>
137+
<Text style={styles.title}>Prove you are human</Text>
138+
<Text style={styles.description}>Complete the challenge to continue.</Text>
139+
{status === 'loading' && (
140+
<View style={styles.indicatorRow}>
141+
<ActivityIndicator color={defaultTheme.palette.background.lushSky} />
142+
<Text style={styles.secondaryText}>Loading challenge…</Text>
143+
</View>
144+
)}
145+
{errorMessage && (
146+
<View style={styles.errorBanner}>
147+
<Text style={styles.errorText}>{errorMessage}</Text>
148+
<TouchableOpacity style={styles.retryButton} onPress={handleRetry}>
149+
<Text style={styles.retryLabel}>Try again</Text>
150+
</TouchableOpacity>
151+
</View>
152+
)}
153+
<TouchableOpacity
154+
onPress={() => closeScreen('Captcha screen cancelled via button')}
155+
style={styles.cancelButton}
156+
>
157+
<Text style={styles.cancelLabel}>Cancel</Text>
158+
</TouchableOpacity>
159+
</View>
158160
</View>
161+
</ModalBottomDrawer>
162+
{siteKey !== '' && (
159163
<ConfirmHcaptcha ref={captchaRef} siteKey={siteKey} onMessage={handleMessage} size={'invisible'} />
160-
</View>
161-
</ModalBottomDrawer>
164+
)}
165+
</>
162166
)
163167
}
164168

0 commit comments

Comments
 (0)