Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import kotlinx.coroutines.withTimeout
import timber.log.Timber
import java.io.BufferedReader
import javax.inject.Inject
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

internal class LoggingRepositoryImpl @Inject constructor(
Expand All @@ -42,6 +43,7 @@ internal class LoggingRepositoryImpl @Inject constructor(
terminal = terminal,
command = command,
startingId = startingId,
readLineTimeout = 10.seconds,
)
}.flowOn(ioDispatcher)

Expand All @@ -52,13 +54,15 @@ internal class LoggingRepositoryImpl @Inject constructor(
terminal = terminal,
command = command,
startingId = 0,
readLineTimeout = 1.seconds,
)
}.flowOn(ioDispatcher)

private suspend fun FlowCollector<LogLine>.emitLines(
terminal: Terminal,
command: Array<String>,
startingId: Long,
readLineTimeout: Duration,
) {
if (terminal.isSupported().not()) {
Timber.d("Terminal $terminal is not supported")
Expand All @@ -79,7 +83,7 @@ internal class LoggingRepositoryImpl @Inject constructor(

while (true) {
Timber.d("Started awaiting line")
val line = withTimeout(10.seconds) {
val line = withTimeout(readLineTimeout) {
reader.readLineCancellable()
}
Timber.d("Got line $line")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.f0x1d.logfox.feature.terminals.api.base.Terminal
import com.f0x1d.logfox.feature.terminals.api.base.TerminalType
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOn
Expand Down Expand Up @@ -82,6 +83,8 @@ internal class RecordingsRepositoryImpl @Inject constructor(
context.toast(Strings.error_saving_logs)
}
e.printStackTrace()
} catch (_: TimeoutCancellationException) {
// Collection of logs finished!
}

LogRecording(
Expand Down