Skip to content

Commit 576dfa6

Browse files
feat(android): add youtube_via_relay toggle to Advanced settings
Expose the `youtube_via_relay` config flag in the Android UI, matching the desktop checkbox. Adds the field to MhrvConfig with serialization round-trip (toJson / loadFromJson / encode), a Switch in the Advanced section, and EN + FA string resources. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8d0004c commit 576dfa6

4 files changed

Lines changed: 33 additions & 0 deletions

File tree

android/app/src/main/java/com/therealaleph/mhrv/ConfigStore.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ data class MhrvConfig(
135135
/** Package names used by ONLY and EXCEPT. Empty under ALL. */
136136
val splitApps: List<String> = emptyList(),
137137

138+
/**
139+
* Route YouTube traffic through Apps Script relay instead of the
140+
* SNI-rewrite tunnel. Avoids Google SafeSearch-on-SNI / restricted
141+
* mode, but slower for video. Maps to Rust `youtube_via_relay`.
142+
*/
143+
val youtubeViaRelay: Boolean = false,
144+
138145
/** UI language toggle. Non-Rust; honoured only by the Android wrapper. */
139146
val uiLang: UiLang = UiLang.AUTO,
140147
) {
@@ -212,6 +219,7 @@ data class MhrvConfig(
212219
put("passthrough_hosts", JSONArray().apply { passthroughHosts.forEach { put(it) } })
213220
}
214221
if (tunnelDoh) put("tunnel_doh", true)
222+
if (youtubeViaRelay) put("youtube_via_relay", true)
215223
// Trim/drop-empty/dedupe before serializing — symmetric with the
216224
// read-side normalization in loadFromJson(), so a user typing
217225
// " doh.foo " or accidentally adding a duplicate doesn't end up
@@ -317,6 +325,7 @@ object ConfigStore {
317325
if (cfg.upstreamSocks5.isNotBlank()) obj.put("upstream_socks5", cfg.upstreamSocks5)
318326
if (cfg.passthroughHosts.isNotEmpty()) obj.put("passthrough_hosts", JSONArray().apply { cfg.passthroughHosts.forEach { put(it) } })
319327
if (cfg.tunnelDoh != defaults.tunnelDoh) obj.put("tunnel_doh", cfg.tunnelDoh)
328+
if (cfg.youtubeViaRelay != defaults.youtubeViaRelay) obj.put("youtube_via_relay", cfg.youtubeViaRelay)
320329
val cleanBypassDohHosts = cfg.bypassDohHosts
321330
.map { it.trim() }
322331
.filter { it.isNotEmpty() }
@@ -420,6 +429,7 @@ object ConfigStore {
420429
buildList { for (i in 0 until arr.length()) add(arr.optString(i)) }
421430
}?.filter { it.isNotBlank() }.orEmpty(),
422431
tunnelDoh = obj.optBoolean("tunnel_doh", false),
432+
youtubeViaRelay = obj.optBoolean("youtube_via_relay", false),
423433
bypassDohHosts = obj.optJSONArray("bypass_doh_hosts")?.let { arr ->
424434
buildList { for (i in 0 until arr.length()) add(arr.optString(i)) }
425435
}?.filter { it.isNotBlank() }.orEmpty(),

android/app/src/main/java/com/therealaleph/mhrv/ui/HomeScreen.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,25 @@ private fun AdvancedSettings(
11961196
)
11971197
}
11981198

1199+
// youtube_via_relay
1200+
Row(
1201+
verticalAlignment = Alignment.CenterVertically,
1202+
modifier = Modifier.fillMaxWidth(),
1203+
) {
1204+
Column(modifier = Modifier.weight(1f)) {
1205+
Text(stringResource(R.string.adv_youtube_via_relay), style = MaterialTheme.typography.bodyMedium)
1206+
Text(
1207+
stringResource(R.string.adv_youtube_via_relay_help),
1208+
style = MaterialTheme.typography.labelSmall,
1209+
color = MaterialTheme.colorScheme.onSurfaceVariant,
1210+
)
1211+
}
1212+
Switch(
1213+
checked = cfg.youtubeViaRelay,
1214+
onCheckedChange = { onChange(cfg.copy(youtubeViaRelay = it)) },
1215+
)
1216+
}
1217+
11991218
// log_level dropdown
12001219
var expanded by remember { mutableStateOf(false) }
12011220
val levels = listOf("trace", "debug", "info", "warn", "error", "off")

android/app/src/main/res/values-fa/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
<!-- Advanced section -->
6868
<string name="adv_verify_tls">بررسی TLS طرف مقابل</string>
6969
<string name="adv_verify_tls_help">خاموش کردن، بررسی گواهی را برای لبهٔ گوگل غیرفعال می‌کند. فقط برای اشکال‌زدایی کاربرد دارد.</string>
70+
<string name="adv_youtube_via_relay">ارسال یوتیوب از طریق رله</string>
71+
<string name="adv_youtube_via_relay_help">ترافیک youtube.com / youtu.be / ytimg.com را به‌جای تونل SNI-rewrite از رلهٔ Apps Script عبور می‌دهد. حالت محدود را دور می‌زند ولی پخش ویدیو کندتر می‌شود.</string>
7072
<string name="adv_log_level">log_level</string>
7173
<string name="adv_parallel_relay">parallel_relay: %1$d</string>
7274
<string name="adv_parallel_relay_help">تعداد درخواست‌های موازی هر بار. ۱ عادی است؛ روی لینک‌های با افت، ۲-۳ را امتحان کنید.</string>

android/app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
<!-- Advanced section -->
6868
<string name="adv_verify_tls">Verify upstream TLS</string>
6969
<string name="adv_verify_tls_help">Off disables cert checks for the Google edge. Only useful for debugging.</string>
70+
<string name="adv_youtube_via_relay">Send YouTube through relay</string>
71+
<string name="adv_youtube_via_relay_help">Route youtube.com / youtu.be / ytimg.com through Apps Script relay instead of SNI-rewrite tunnel. Avoids restricted mode but slower for video.</string>
7072
<string name="adv_log_level">log_level</string>
7173
<string name="adv_parallel_relay">parallel_relay: %1$d</string>
7274
<string name="adv_parallel_relay_help">Fan-out per request. 1 is normal; bump to 2-3 on lossy links.</string>

0 commit comments

Comments
 (0)