refactor(domain): сгруппировать по подпакетам и согласовать имена

Файлы domain разложены по ssh/proxy/share/update (server уже был).
CmdResult вынесен из ServerOutputParser в свой файл; InstallOutcome ->
вложенный SshRepository.InstallResult; ServerSetupRepository.startServer
-> start; journalLoading -> logsLoading.
This commit is contained in:
samosvalishe committed 2026-06-14 02:05:18 +03:00
1 parent afefe0a91d
commit 74d3044309
26 files changed
+107 -102

No files matched your search

@@ -15,7 +15,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import com.freeturn.app.domain.LinkImportBus import com.freeturn.app.domain.share.LinkImportBus
import com.freeturn.app.ui.util.HapticUtil import com.freeturn.app.ui.util.HapticUtil
import com.freeturn.app.ui.navigation.AppNavigation import com.freeturn.app.ui.navigation.AppNavigation
import com.freeturn.app.ui.theme.FreeTurnTheme import com.freeturn.app.ui.theme.FreeTurnTheme
@@ -1,14 +1,14 @@
package com.freeturn.app.di package com.freeturn.app.di
import com.freeturn.app.data.AppPreferences import com.freeturn.app.data.AppPreferences
import com.freeturn.app.domain.AppUpdater import com.freeturn.app.domain.update.AppUpdater
import com.freeturn.app.domain.LinkImportBus import com.freeturn.app.domain.share.LinkImportBus
import com.freeturn.app.domain.LocalProxyManager import com.freeturn.app.domain.proxy.LocalProxyManager
import com.freeturn.app.domain.ProxyOrchestrator import com.freeturn.app.domain.proxy.ProxyOrchestrator
import com.freeturn.app.domain.SSHManager import com.freeturn.app.domain.ssh.SSHManager
import com.freeturn.app.domain.ServerSetupRepository import com.freeturn.app.domain.server.ServerSetupRepository
import com.freeturn.app.domain.ShareRepository import com.freeturn.app.domain.share.ShareRepository
import com.freeturn.app.domain.SshRepository import com.freeturn.app.domain.ssh.SshRepository
import com.freeturn.app.viewmodel.ImportViewModel import com.freeturn.app.viewmodel.ImportViewModel
import com.freeturn.app.viewmodel.ProxyViewModel import com.freeturn.app.viewmodel.ProxyViewModel
import com.freeturn.app.viewmodel.ServerSetupViewModel import com.freeturn.app.viewmodel.ServerSetupViewModel
@@ -1,4 +1,4 @@
package com.freeturn.app.domain package com.freeturn.app.domain.proxy
/** Событие, распознанное в строке лога клиентского ядра. */ /** Событие, распознанное в строке лога клиентского ядра. */
sealed interface CoreLogEvent { sealed interface CoreLogEvent {
@@ -1,9 +1,12 @@
package com.freeturn.app.domain package com.freeturn.app.domain.proxy
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build import android.os.Build
import com.freeturn.app.data.ClientConfig import com.freeturn.app.data.ClientConfig
import com.freeturn.app.domain.ConnectionStats
import com.freeturn.app.domain.ProxyState
import com.freeturn.app.domain.StartupResult
import com.freeturn.app.proxy.CoreProcessController import com.freeturn.app.proxy.CoreProcessController
import com.freeturn.app.proxy.ProxyService import com.freeturn.app.proxy.ProxyService
import com.freeturn.app.proxy.ProxyServiceState import com.freeturn.app.proxy.ProxyServiceState
@@ -1,6 +1,8 @@
package com.freeturn.app.domain package com.freeturn.app.domain.proxy
import com.freeturn.app.data.AppPreferences import com.freeturn.app.data.AppPreferences
import com.freeturn.app.domain.ServerState
import com.freeturn.app.domain.ssh.SshRepository
import com.freeturn.app.proxy.ProxyServiceState import com.freeturn.app.proxy.ProxyServiceState
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withTimeoutOrNull import kotlinx.coroutines.withTimeoutOrNull
@@ -1,4 +1,4 @@
package com.freeturn.app.domain package com.freeturn.app.domain.proxy
import android.content.Context import android.content.Context
import com.freeturn.app.data.ClientConfig import com.freeturn.app.data.ClientConfig
@@ -0,0 +1,28 @@
package com.freeturn.app.domain.server
/**
* Результат серверной команды: k=v значения, LOG-строки и статус (RESULT=ok/err).
* Строится из stdout в [ServerOutputParser].
*/
sealed class CmdResult {
abstract val logs: List<String>
data class Ok(val kv: Map<String, String>, override val logs: List<String>) : CmdResult()
data class Err(val message: String, override val logs: List<String>) : CmdResult()
}
/** Ошибка серверной команды; message - текст из скрипта/SSH для UI. */
class ServerCommandException(message: String) : Exception(message)
/** Текст ошибки + хвост LOG-строк для диагностики. */
fun CmdResult.Err.errMessage(): String {
val tail = logs.takeLast(2).filter { it.isNotBlank() }
return if (tail.isEmpty()) message else message + "\n" + tail.joinToString("\n")
}
fun CmdResult.Err.toFailure(): Result<Nothing> =
Result.failure(ServerCommandException(errMessage()))
fun CmdResult.asUnit(): Result<Unit> = when (this) {
is CmdResult.Ok -> Result.success(Unit)
is CmdResult.Err -> toFailure()
}
@@ -1,7 +1,7 @@
package com.freeturn.app.domain.server package com.freeturn.app.domain.server
import android.content.Context import android.content.Context
import com.freeturn.app.domain.SSHManager import com.freeturn.app.domain.ssh.SSHManager
import com.freeturn.app.data.SshConfig import com.freeturn.app.data.SshConfig
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@@ -1,15 +1,6 @@
package com.freeturn.app.domain.server package com.freeturn.app.domain.server
/** /** Парсит stdout серверной команды в [CmdResult]: `LOG:` префиксы, k=v значения и `RESULT`. */
* Результат выполнения серверной команды (из stdout).
* Парсит k=v значения, `LOG:` префиксы и статус (`RESULT=ok/err`).
*/
sealed class CmdResult {
abstract val logs: List<String>
data class Ok(val kv: Map<String, String>, override val logs: List<String>) : CmdResult()
data class Err(val message: String, override val logs: List<String>) : CmdResult()
}
object ServerOutputParser { object ServerOutputParser {
fun parse(raw: String): CmdResult { fun parse(raw: String): CmdResult {
// Проброс транспортных ошибок от SSHManager. // Проброс транспортных ошибок от SSHManager.
@@ -43,23 +34,6 @@ object ServerOutputParser {
} }
} }
/** Ошибка серверной команды; message - текст из скрипта/SSH для UI. */
class ServerCommandException(message: String) : Exception(message)
/** Текст ошибки + хвост LOG-строк для диагностики. */
fun CmdResult.Err.errMessage(): String {
val tail = logs.takeLast(2).filter { it.isNotBlank() }
return if (tail.isEmpty()) message else message + "\n" + tail.joinToString("\n")
}
fun CmdResult.Err.toFailure(): Result<Nothing> =
Result.failure(ServerCommandException(errMessage()))
fun CmdResult.asUnit(): Result<Unit> = when (this) {
is CmdResult.Ok -> Result.success(Unit)
is CmdResult.Err -> toFailure()
}
/** base64 -> UTF-8 текст; битое значение -> null. */ /** base64 -> UTF-8 текст; битое значение -> null. */
fun decodeBase64(s: String): String? = fun decodeBase64(s: String): String? =
runCatching { String(java.util.Base64.getDecoder().decode(s.trim()), Charsets.UTF_8) }.getOrNull() runCatching { String(java.util.Base64.getDecoder().decode(s.trim()), Charsets.UTF_8) }.getOrNull()
@@ -1,14 +1,8 @@
package com.freeturn.app.domain package com.freeturn.app.domain.server
import android.content.Context import android.content.Context
import com.freeturn.app.data.SshConfig import com.freeturn.app.data.SshConfig
import com.freeturn.app.domain.server.CmdResult import com.freeturn.app.domain.ssh.SSHManager
import com.freeturn.app.domain.server.ServerCommand
import com.freeturn.app.domain.server.ServerControl
import com.freeturn.app.domain.server.ServerOptions
import com.freeturn.app.domain.server.asUnit
import com.freeturn.app.domain.server.decodeBase64
import com.freeturn.app.domain.server.toFailure
/** /**
* SSH-операции мастера добавления self-hosted сервера. Собственный [SSHManager] и * SSH-операции мастера добавления self-hosted сервера. Собственный [SSHManager] и
@@ -66,6 +60,6 @@ class ServerSetupRepository(context: Context, private val ssh: SSHManager) {
) )
} }
suspend fun startServer(cfg: SshConfig, opts: ServerOptions): Result<Unit> = suspend fun start(cfg: SshConfig, opts: ServerOptions): Result<Unit> =
control.run(cfg, ServerCommand.Start(opts)).asUnit() control.run(cfg, ServerCommand.Start(opts)).asUnit()
} }
@@ -1,4 +1,4 @@
package com.freeturn.app.domain package com.freeturn.app.domain.share
import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
@@ -1,4 +1,4 @@
package com.freeturn.app.domain package com.freeturn.app.domain.share
import android.content.Context import android.content.Context
import com.freeturn.app.data.SshConfig import com.freeturn.app.data.SshConfig
@@ -14,6 +14,7 @@ import com.freeturn.app.domain.server.ServerControl
import com.freeturn.app.domain.server.asUnit import com.freeturn.app.domain.server.asUnit
import com.freeturn.app.domain.server.decodeBase64 import com.freeturn.app.domain.server.decodeBase64
import com.freeturn.app.domain.server.toFailure import com.freeturn.app.domain.server.toFailure
import com.freeturn.app.domain.ssh.SSHManager
import java.util.Base64 import java.util.Base64
/** /**
@@ -1,4 +1,4 @@
package com.freeturn.app.domain package com.freeturn.app.domain.ssh
import com.jcraft.jsch.ChannelExec import com.jcraft.jsch.ChannelExec
import com.jcraft.jsch.HostKey import com.jcraft.jsch.HostKey
@@ -1,7 +1,9 @@
package com.freeturn.app.domain package com.freeturn.app.domain.ssh
import android.content.Context import android.content.Context
import com.freeturn.app.data.SshConfig import com.freeturn.app.data.SshConfig
import com.freeturn.app.domain.ServerState
import com.freeturn.app.domain.SshConnectionState
import com.freeturn.app.domain.server.CmdResult import com.freeturn.app.domain.server.CmdResult
import com.freeturn.app.domain.server.ServerCommand import com.freeturn.app.domain.server.ServerCommand
import com.freeturn.app.domain.server.ServerControl import com.freeturn.app.domain.server.ServerControl
@@ -34,8 +36,8 @@ class SshRepository(
// Идёт ли запрос server.log. Сам вывод уходит в sshLog (через runCmd -> logCmdResult), // Идёт ли запрос server.log. Сам вывод уходит в sshLog (через runCmd -> logCmdResult),
// отдельного состояния журнала нет - он часть единого SSH-лога. // отдельного состояния журнала нет - он часть единого SSH-лога.
private val _journalLoading = MutableStateFlow(false) private val _logsLoading = MutableStateFlow(false)
val journalLoading: StateFlow<Boolean> = _journalLoading.asStateFlow() val logsLoading: StateFlow<Boolean> = _logsLoading.asStateFlow()
private val timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss") private val timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss")
private fun timestamp(): String = LocalTime.now().format(timeFormatter) private fun timestamp(): String = LocalTime.now().format(timeFormatter)
@@ -144,15 +146,15 @@ class SshRepository(
} }
/** Идемпотентная установка: скрипт сам решает, скачивать или нет (по sha256). */ /** Идемпотентная установка: скрипт сам решает, скачивать или нет (по sha256). */
suspend fun installServer(): InstallOutcome { suspend fun installServer(): InstallResult {
val cfg = activeSshConfig ?: return InstallOutcome.Failed("not connected") val cfg = activeSshConfig ?: return InstallResult.Failed("not connected")
if (cfg.ip.isEmpty()) return InstallOutcome.Failed("no SSH config") if (cfg.ip.isEmpty()) return InstallResult.Failed("no SSH config")
_serverState.value = ServerState.Working("Установка free-turn-proxy...") _serverState.value = ServerState.Working("Установка free-turn-proxy...")
return when (val result = runCmd(cfg, "Установка", ServerCommand.Install)) { return when (val result = runCmd(cfg, "Установка", ServerCommand.Install)) {
is CmdResult.Err -> { is CmdResult.Err -> {
_serverState.value = ServerState.Error(result.message) _serverState.value = ServerState.Error(result.message)
InstallOutcome.Failed(result.message) InstallResult.Failed(result.message)
} }
is CmdResult.Ok -> { is CmdResult.Ok -> {
val stage = result.kv["STAGE"] ?: "ok" val stage = result.kv["STAGE"] ?: "ok"
@@ -170,7 +172,7 @@ class SshRepository(
} }
delay(300) delay(300)
checkServerState(cfg, silent = true) checkServerState(cfg, silent = true)
InstallOutcome.Success(stage = stage, version = version, needsRestart = needsRestart) InstallResult.Success(stage = stage, version = version, needsRestart = needsRestart)
} }
} }
} }
@@ -227,11 +229,11 @@ class SshRepository(
suspend fun fetchServerLogs(lines: Int = 200) { suspend fun fetchServerLogs(lines: Int = 200) {
val cfg = activeSshConfig ?: return val cfg = activeSshConfig ?: return
if (cfg.ip.isEmpty()) return if (cfg.ip.isEmpty()) return
_journalLoading.value = true _logsLoading.value = true
try { try {
runCmd(cfg, "server.log", ServerCommand.FetchLogs(lines)) runCmd(cfg, "server.log", ServerCommand.FetchLogs(lines))
} finally { } finally {
_journalLoading.value = false _logsLoading.value = false
} }
} }
@@ -247,18 +249,18 @@ class SshRepository(
disconnect() disconnect()
_sshLog.value = emptyList() _sshLog.value = emptyList()
} }
}
sealed class InstallOutcome { sealed class InstallResult {
/** /**
* stage: cached | downloaded; version - только если ядро вернуло. * stage: cached | downloaded; version - только если ядро вернуло.
* needsRestart - true, если бинарь был переустановлен поверх работающего * needsRestart - true, если бинарь был переустановлен поверх работающего
* процесса; перед использованием новой версии нужен start. * процесса; перед использованием новой версии нужен start.
*/ */
data class Success( data class Success(
val stage: String, val stage: String,
val version: String?, val version: String?,
val needsRestart: Boolean = false val needsRestart: Boolean = false
) : InstallOutcome() ) : InstallResult()
data class Failed(val message: String) : InstallOutcome() data class Failed(val message: String) : InstallResult()
}
} }
@@ -1,9 +1,10 @@
package com.freeturn.app.domain package com.freeturn.app.domain.update
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import com.freeturn.app.domain.UpdateState
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
@@ -9,11 +9,11 @@ import com.freeturn.app.data.AppPreferences
import com.freeturn.app.data.CoreArgs import com.freeturn.app.data.CoreArgs
import com.freeturn.app.domain.CaptchaSession import com.freeturn.app.domain.CaptchaSession
import com.freeturn.app.domain.ConnectionStats import com.freeturn.app.domain.ConnectionStats
import com.freeturn.app.domain.CoreConnectionTracker import com.freeturn.app.domain.proxy.CoreConnectionTracker
import com.freeturn.app.domain.CoreLogEvent import com.freeturn.app.domain.proxy.CoreLogEvent
import com.freeturn.app.domain.CoreLogParser import com.freeturn.app.domain.proxy.CoreLogParser
import com.freeturn.app.domain.StartupResult import com.freeturn.app.domain.StartupResult
import com.freeturn.app.domain.WireGuardTunnelManager import com.freeturn.app.domain.proxy.WireGuardTunnelManager
import java.io.BufferedReader import java.io.BufferedReader
import java.io.File import java.io.File
import java.io.InputStreamReader import java.io.InputStreamReader
@@ -37,7 +37,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.freeturn.app.R import com.freeturn.app.R
import com.freeturn.app.data.share.FreeturnLink import com.freeturn.app.data.share.FreeturnLink
import com.freeturn.app.domain.LinkImportBus import com.freeturn.app.domain.share.LinkImportBus
import com.freeturn.app.ui.components.SectionLabel import com.freeturn.app.ui.components.SectionLabel
import com.freeturn.app.ui.components.SettingsContentMaxWidth import com.freeturn.app.ui.components.SettingsContentMaxWidth
import com.freeturn.app.ui.components.SettingsEntryRow import com.freeturn.app.ui.components.SettingsEntryRow
@@ -137,7 +137,7 @@ private fun NerdContent(
val serverId = server.id val serverId = server.id
val client = server.client val client = server.client
val sshLog by serverViewModel.sshLog.collectAsStateWithLifecycle() val sshLog by serverViewModel.sshLog.collectAsStateWithLifecycle()
val journalLoading by serverViewModel.journalLoading.collectAsStateWithLifecycle() val logsLoading by serverViewModel.logsLoading.collectAsStateWithLifecycle()
// Per-server отладочные флаги. updateServerClient разводит active/inactive и // Per-server отладочные флаги. updateServerClient разводит active/inactive и
// применяет logsEnabled живьём - отдельные VM-сеттеры не нужны. // применяет logsEnabled живьём - отдельные VM-сеттеры не нужны.
@@ -177,7 +177,7 @@ private fun NerdContent(
SshLogCard( SshLogCard(
lines = sshLog, lines = sshLog,
canFetchJournal = online != null, canFetchJournal = online != null,
journalLoading = journalLoading, logsLoading = logsLoading,
onFetchJournal = { onFetchJournal = {
HapticUtil.perform(context, HapticUtil.Pattern.CLICK) HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
serverViewModel.fetchServerLogs() serverViewModel.fetchServerLogs()
@@ -57,7 +57,7 @@ import com.freeturn.app.ui.theme.Spacing
internal fun SshLogCard( internal fun SshLogCard(
lines: List<String>, lines: List<String>,
canFetchJournal: Boolean, canFetchJournal: Boolean,
journalLoading: Boolean, logsLoading: Boolean,
onFetchJournal: () -> Unit, onFetchJournal: () -> Unit,
onClear: () -> Unit onClear: () -> Unit
) { ) {
@@ -110,10 +110,10 @@ internal fun SshLogCard(
if (canFetchJournal) { if (canFetchJournal) {
FilledTonalButton( FilledTonalButton(
onClick = onFetchJournal, onClick = onFetchJournal,
enabled = !journalLoading, enabled = !logsLoading,
modifier = Modifier.weight(1f) modifier = Modifier.weight(1f)
) { ) {
if (journalLoading) { if (logsLoading) {
LoadingIndicator(modifier = Modifier.size(22.dp)) LoadingIndicator(modifier = Modifier.size(22.dp))
} else { } else {
Icon( Icon(
@@ -55,7 +55,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.LifecycleEventObserver
import com.freeturn.app.R import com.freeturn.app.R
import com.freeturn.app.data.share.FreeturnLink import com.freeturn.app.data.share.FreeturnLink
import com.freeturn.app.domain.LinkImportBus import com.freeturn.app.domain.share.LinkImportBus
import com.freeturn.app.ui.util.HapticUtil import com.freeturn.app.ui.util.HapticUtil
import com.google.mlkit.vision.barcode.BarcodeScannerOptions import com.google.mlkit.vision.barcode.BarcodeScannerOptions
import com.google.mlkit.vision.barcode.BarcodeScanning import com.google.mlkit.vision.barcode.BarcodeScanning
@@ -11,7 +11,7 @@ import com.freeturn.app.data.ServerOpts
import com.freeturn.app.data.SshConfig import com.freeturn.app.data.SshConfig
import com.freeturn.app.data.TunnelTransport import com.freeturn.app.data.TunnelTransport
import com.freeturn.app.data.share.FreeturnLink import com.freeturn.app.data.share.FreeturnLink
import com.freeturn.app.domain.LinkImportBus import com.freeturn.app.domain.share.LinkImportBus
import com.freeturn.app.ui.util.HapticUtil import com.freeturn.app.ui.util.HapticUtil
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
@@ -3,7 +3,7 @@ package com.freeturn.app.viewmodel
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.freeturn.app.data.AppPreferences import com.freeturn.app.data.AppPreferences
import com.freeturn.app.domain.LocalProxyManager import com.freeturn.app.domain.proxy.LocalProxyManager
import com.freeturn.app.domain.ProxyState import com.freeturn.app.domain.ProxyState
import com.freeturn.app.proxy.ProxyServiceState import com.freeturn.app.proxy.ProxyServiceState
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
@@ -10,8 +10,8 @@ import com.freeturn.app.data.Server
import com.freeturn.app.data.ServerOpts import com.freeturn.app.data.ServerOpts
import com.freeturn.app.data.SshConfig import com.freeturn.app.data.SshConfig
import com.freeturn.app.data.TunnelTransport import com.freeturn.app.data.TunnelTransport
import com.freeturn.app.domain.ProxyOrchestrator import com.freeturn.app.domain.proxy.ProxyOrchestrator
import com.freeturn.app.domain.ServerSetupRepository import com.freeturn.app.domain.server.ServerSetupRepository
import com.freeturn.app.domain.server.ServerOptions import com.freeturn.app.domain.server.ServerOptions
import com.freeturn.app.ui.util.HapticUtil import com.freeturn.app.ui.util.HapticUtil
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
@@ -316,7 +316,7 @@ class ServerSetupViewModel(
} }
val obfOn = c.obfProfile != ObfProfile.NONE val obfOn = c.obfProfile != ObfProfile.NONE
repo.startServer( repo.start(
cfg, cfg,
ServerOptions( ServerOptions(
listen = "0.0.0.0:${c.listenPort}", listen = "0.0.0.0:${c.listenPort}",
@@ -7,10 +7,10 @@ import com.freeturn.app.data.AppPreferences
import com.freeturn.app.data.ObfProfile import com.freeturn.app.data.ObfProfile
import com.freeturn.app.data.ServerOpts import com.freeturn.app.data.ServerOpts
import com.freeturn.app.data.SshConfig import com.freeturn.app.data.SshConfig
import com.freeturn.app.domain.ProxyOrchestrator import com.freeturn.app.domain.proxy.ProxyOrchestrator
import com.freeturn.app.domain.ServerState import com.freeturn.app.domain.ServerState
import com.freeturn.app.domain.SshConnectionState import com.freeturn.app.domain.SshConnectionState
import com.freeturn.app.domain.SshRepository import com.freeturn.app.domain.ssh.SshRepository
import com.freeturn.app.ui.util.HapticUtil import com.freeturn.app.ui.util.HapticUtil
import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
@@ -33,7 +33,7 @@ class ServerViewModel(
val sshState: StateFlow<SshConnectionState> = sshRepository.sshState val sshState: StateFlow<SshConnectionState> = sshRepository.sshState
val serverState: StateFlow<ServerState> = sshRepository.serverState val serverState: StateFlow<ServerState> = sshRepository.serverState
val sshLog: StateFlow<List<String>> = sshRepository.sshLog val sshLog: StateFlow<List<String>> = sshRepository.sshLog
val journalLoading: StateFlow<Boolean> = sshRepository.journalLoading val logsLoading: StateFlow<Boolean> = sshRepository.logsLoading
val serverOpts: StateFlow<ServerOpts> = prefs.serverOptsFlow val serverOpts: StateFlow<ServerOpts> = prefs.serverOptsFlow
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), ServerOpts()) .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), ServerOpts())
@@ -94,7 +94,7 @@ class ServerViewModel(
fun installServer() { fun installServer() {
viewModelScope.launch { viewModelScope.launch {
val outcome = sshRepository.installServer() val outcome = sshRepository.installServer()
if (outcome is com.freeturn.app.domain.InstallOutcome.Success) { if (outcome is SshRepository.InstallResult.Success) {
if (outcome.stage == "downloaded" && prefs.serverOptsFlow.first().obfKey.isBlank()) { if (outcome.stage == "downloaded" && prefs.serverOptsFlow.first().obfKey.isBlank()) {
prefs.updateActiveServer { it.copy(opts = it.opts.copy(obfKey = ObfProfile.generateKey())) } prefs.updateActiveServer { it.copy(opts = it.opts.copy(obfKey = ObfProfile.generateKey())) }
} }
@@ -9,10 +9,10 @@ import com.freeturn.app.data.ClientConfig
import com.freeturn.app.data.ObfProfile import com.freeturn.app.data.ObfProfile
import com.freeturn.app.data.Server import com.freeturn.app.data.Server
import com.freeturn.app.data.ServersSnapshot import com.freeturn.app.data.ServersSnapshot
import com.freeturn.app.domain.AppUpdater import com.freeturn.app.domain.update.AppUpdater
import com.freeturn.app.domain.LocalProxyManager import com.freeturn.app.domain.proxy.LocalProxyManager
import com.freeturn.app.domain.ProxyOrchestrator import com.freeturn.app.domain.proxy.ProxyOrchestrator
import com.freeturn.app.domain.SshRepository import com.freeturn.app.domain.ssh.SshRepository
import com.freeturn.app.domain.UpdateState import com.freeturn.app.domain.UpdateState
import com.freeturn.app.proxy.ProxyService import com.freeturn.app.proxy.ProxyService
import com.freeturn.app.proxy.ProxyServiceState import com.freeturn.app.proxy.ProxyServiceState
@@ -11,7 +11,7 @@ import com.freeturn.app.data.share.ShareInfo
import com.freeturn.app.data.share.ShareLinkBuilder import com.freeturn.app.data.share.ShareLinkBuilder
import com.freeturn.app.data.share.SharedClient import com.freeturn.app.data.share.SharedClient
import com.freeturn.app.data.share.WgPeer import com.freeturn.app.data.share.WgPeer
import com.freeturn.app.domain.ShareRepository import com.freeturn.app.domain.share.ShareRepository
import com.freeturn.app.ui.util.HapticUtil import com.freeturn.app.ui.util.HapticUtil
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow