Skip to content

Commit 38d3f13

Browse files
committed
Let a log host say it has no verbose stream
The logs screen has always offered two streams to unfold between, on the assumption that a host can always read the whole device log as well as the routed subset. A host that has lost the privileged backend it reads the device through is reduced to its own process's log, where the two streams would be the same lines under two names, and the toggle becomes a control that changes nothing. LogSource gains hasVerboseStream, defaulting to true so every existing host keeps both. The screen reads it live rather than through the view model, since the backend can come and go while the screen is open: the toggle disappears with the stream, and a reader left standing on the verbose pane is moved back to the modules one instead of staring at a stream the host no longer serves.
1 parent 35b510c commit 38d3f13

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

manager-ui/src/main/kotlin/org/matrix/vector/ui/logs/LogSource.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ interface LogSource {
4242
*/
4343
suspend fun open(verbose: Boolean, part: String?): Result<LogContent?>
4444

45+
/**
46+
* Whether the host actually has a second, verbose stream to unfold into.
47+
*
48+
* A host can be reduced to a single log — one that reads only its own process because the
49+
* privileged backend it normally reads the device through is unavailable — and then the two
50+
* streams would be the same lines under two names. Saying so drops the unfold control instead of
51+
* offering a choice that changes nothing.
52+
*/
53+
val hasVerboseStream: Boolean
54+
get() = true
55+
4556
// --- Verbose-logging preference (distinct from which stream is on screen) ------------------
4657

4758
/** Whether the host has a persistent "write verbose lines at all" preference to toggle. */

manager-ui/src/main/kotlin/org/matrix/vector/ui/logs/LogsScreen.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ fun LogsScreen(
151151
// search boxes, two filter states and two scroll positions for what is one question — "what
152152
// does the log say" — whose answer often has to be looked for in both streams.
153153
var currentTab by rememberSaveable { mutableStateOf(LogTab.MODULES) }
154+
// Read from the source rather than snapshotted in the view model: a host can gain or lose its
155+
// verbose stream while the screen is open (a backend granted, a service lost), and the control
156+
// has to follow. Losing it mid-read also has to move the reader back, or the pane would stay on
157+
// a stream the host no longer serves.
158+
val hasVerboseStream = source.hasVerboseStream
159+
LaunchedEffect(hasVerboseStream) {
160+
if (!hasVerboseStream && currentTab == LogTab.VERBOSE) currentTab = LogTab.MODULES
161+
}
154162
val currentState by viewModel.state(currentTab).collectAsStateWithLifecycle()
155163
val wordWrap by viewModel.wordWrap.collectAsStateWithLifecycle()
156164
val saveState by viewModel.saveState.collectAsStateWithLifecycle()
@@ -223,6 +231,7 @@ fun LogsScreen(
223231
state = currentState,
224232
viewModel = viewModel,
225233
onSelectTab = { currentTab = it },
234+
showSourceToggle = hasVerboseStream,
226235
)
227236
},
228237
actions = {
@@ -560,14 +569,15 @@ private fun LogSearch(
560569
state: LogPaneState,
561570
viewModel: LogsViewModel,
562571
onSelectTab: (LogTab) -> Unit,
572+
showSourceToggle: Boolean,
563573
) {
564574
var filterOpen by remember { mutableStateOf(false) }
565575
SearchField(
566576
query = state.query.text,
567577
onQueryChange = { viewModel.setQuery(tab, it) },
568578
placeholder = stringResource(R.string.logs_search_hint),
569579
trailing = {
570-
LogSourceToggle(tab = tab, onSelect = onSelectTab)
580+
if (showSourceToggle) LogSourceToggle(tab = tab, onSelect = onSelectTab)
571581
IconButton(
572582
onClick = {
573583
filterOpen = true

0 commit comments

Comments
 (0)