refactor(data): константа имени WG-туннеля и флаг загрузки снапшота профилей

DEFAULT_TUNNEL_NAME вместо хардкода "freeturn-wg" по всему data-слою.
ProfilesSnapshot.loaded отличает initial-значение stateIn от первой
эмиссии DataStore — нужно UI, чтобы на холодном старте не мигало
"несохранённый профиль".
This commit is contained in:
samosvalishe committed 2026-06-02 17:39:44 +03:00
1 parent 4b942d9bd6
commit bdfdc3e06d
2 files changed
+13 -6

No files matched your search

@@ -57,6 +57,8 @@ object ObfProfile {
*/
object TunnelTransport {
const val WIREGUARD = "wireguard"
/** Имя WG-туннеля по умолчанию (GoBackend). */
const val DEFAULT_TUNNEL_NAME = "freeturn-wg"
val ALL = listOf(WIREGUARD)
}
@@ -110,7 +112,7 @@ data class ClientConfig(
/** Конфиг WireGuard (.conf). Пусто = WG-туннель не поднимается. */
val wireGuardConfig: String = "",
/** Имя WG-туннеля для GoBackend. */
val wireGuardTunnelName: String = "freeturn-wg",
val wireGuardTunnelName: String = TunnelTransport.DEFAULT_TUNNEL_NAME,
/** Режим split-tunneling: all | include | exclude. */
val splitTunnelMode: String = SplitTunnelMode.ALL,
/** Список package-имён для include/exclude (разделители: запятая/пробел/перенос строки). */
@@ -229,7 +231,8 @@ class AppPreferences(context: Context) {
if (it in TunnelTransport.ALL) it else TunnelTransport.WIREGUARD
},
wireGuardConfig = prefs[CLIENT_WG_CONFIG] ?: "",
wireGuardTunnelName = (prefs[CLIENT_WG_TUNNEL_NAME] ?: "freeturn-wg").ifBlank { "freeturn-wg" },
wireGuardTunnelName = (prefs[CLIENT_WG_TUNNEL_NAME] ?: TunnelTransport.DEFAULT_TUNNEL_NAME)
.ifBlank { TunnelTransport.DEFAULT_TUNNEL_NAME },
splitTunnelMode = (prefs[CLIENT_SPLIT_TUNNEL_MODE] ?: SplitTunnelMode.ALL).let {
if (it in SplitTunnelMode.VALUES) it else SplitTunnelMode.ALL
},
@@ -358,7 +361,8 @@ class AppPreferences(context: Context) {
if (config.tunnelTransport in TunnelTransport.ALL) config.tunnelTransport
else TunnelTransport.WIREGUARD
prefs[CLIENT_WG_CONFIG] = config.wireGuardConfig.trim()
prefs[CLIENT_WG_TUNNEL_NAME] = config.wireGuardTunnelName.trim().ifBlank { "freeturn-wg" }
prefs[CLIENT_WG_TUNNEL_NAME] =
config.wireGuardTunnelName.trim().ifBlank { TunnelTransport.DEFAULT_TUNNEL_NAME }
prefs[CLIENT_SPLIT_TUNNEL_MODE] =
if (config.splitTunnelMode in SplitTunnelMode.VALUES) config.splitTunnelMode
else SplitTunnelMode.ALL
@@ -395,7 +399,8 @@ class AppPreferences(context: Context) {
.map { prefs ->
ProfilesSnapshot(
list = ProfileJson.decodeList(prefs[PROFILES_JSON]),
activeId = prefs[ACTIVE_PROFILE_ID]?.takeIf { it.isNotBlank() }
activeId = prefs[ACTIVE_PROFILE_ID]?.takeIf { it.isNotBlank() },
loaded = true
)
}
@@ -23,7 +23,9 @@ data class Profile(
data class ProfilesSnapshot(
val list: List<Profile> = emptyList(),
val activeId: String? = null
val activeId: String? = null,
/** false = initial-значение stateIn до первой эмиссии DataStore. */
val loaded: Boolean = false
) {
val active: Profile? get() = list.firstOrNull { it.id == activeId }
}
@@ -136,7 +138,7 @@ internal object ProfileJson {
if (it in TunnelTransport.ALL) it else TunnelTransport.WIREGUARD
},
wireGuardConfig = cliO.optString("wireGuardConfig"),
wireGuardTunnelName = cliO.optString("wireGuardTunnelName").ifBlank { "freeturn-wg" },
wireGuardTunnelName = cliO.optString("wireGuardTunnelName").ifBlank { TunnelTransport.DEFAULT_TUNNEL_NAME },
splitTunnelMode = cliO.optString("splitTunnelMode", SplitTunnelMode.ALL).let {
if (it in SplitTunnelMode.VALUES) it else SplitTunnelMode.ALL
},