feat(settings): пункт Always-on VPN в разделе "Работа в фоне"

Ведёт в системные настройки VPN: система сама поднимает туннель
после перезагрузки и убийства процесса - надёжнее исключения из
экономии батареи.
This commit is contained in:
samosvalishe committed 2026-08-18 00:46:43 +03:00
1 parent 9c05bd9e76
commit 429affa0a1
2 files changed
+41 -1

No files matched your search

@@ -5,7 +5,11 @@
package com.freeturn.app.ui.screens.settings
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.Settings
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedContent
@@ -40,6 +44,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
@@ -68,6 +73,7 @@ import com.freeturn.app.ui.util.hapticClickable
import com.freeturn.app.viewmodel.settings.BackupEvent
import com.freeturn.app.viewmodel.settings.RestoreFailReason
import com.freeturn.app.viewmodel.settings.SettingsViewModel
import kotlinx.coroutines.launch
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
@@ -90,6 +96,7 @@ fun AppScreen(
var showExportDialog by rememberSaveable { mutableStateOf(false) }
var exportPassword by rememberSaveable { mutableStateOf("") }
val snackbarHostState = remember { SnackbarHostState() }
val scope = rememberCoroutineScope()
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
// SAF: имя выбирает пользователь, пароль уже введён в диалоге выше.
@@ -176,6 +183,27 @@ fun AppScreen(
}
}
SectionLabel(stringResource(R.string.app_section_background))
SettingsGroup {
SettingsGroupItem(0, 1) {
SettingsEntryRow(
iconRes = R.drawable.vpn_key_24px,
title = stringResource(R.string.always_on_vpn_title),
subtitle = stringResource(R.string.always_on_vpn_desc),
onClick = {
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
if (!openVpnSettings(context)) {
scope.launch {
snackbarHostState.showSnackbar(
context.getString(R.string.always_on_vpn_unavailable)
)
}
}
}
)
}
}
SectionLabel(stringResource(R.string.app_section_updates))
UpdateCard(
state = updateState,
@@ -257,8 +285,16 @@ fun AppScreen(
}
}
/** false - экрана VPN в системных настройках нет (урезанные прошивки). */
private fun openVpnSettings(context: Context): Boolean = try {
context.startActivity(Intent(Settings.ACTION_VPN_SETTINGS))
true
} catch (_: ActivityNotFoundException) {
false
}
/** Текст снекбара по результату экспорта/восстановления (строки выбирает UI, не ViewModel). */
internal fun backupEventMessage(context: android.content.Context, event: BackupEvent): String =
internal fun backupEventMessage(context: Context, event: BackupEvent): String =
when (event) {
BackupEvent.ExportSuccess -> context.getString(R.string.backup_export_ok)
BackupEvent.ExportFailed -> context.getString(R.string.backup_export_fail)
+4
View File
@@ -494,6 +494,10 @@
<string name="suppress_update_prompt_desc">Не показывать диалог с предложением обновиться</string>
<string name="suppress_tg_prompt_title">Не предлагать Telegram</string>
<string name="suppress_tg_prompt_desc">Не показывать диалог с предложением подписаться на канал</string>
<string name="app_section_background">Работа в фоне</string>
<string name="always_on_vpn_title">Always-on VPN</string>
<string name="always_on_vpn_desc">Система сама поднимает туннель при загрузке и после сбоя. Надёжнее исключения из экономии батареи; нужен режим WireGuard</string>
<string name="always_on_vpn_unavailable">Настройки VPN недоступны на этом устройстве</string>
<string name="app_section_updates">Обновления</string>
<string name="app_section_reset">Сброс</string>
<string name="app_reset_desc">Удалить все данные приложения</string>