-
Notifications
You must be signed in to change notification settings - Fork 28
Feat performances screen #489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
72a6548
e221126
f50d491
8a4873b
ac273ae
3631f0d
f02fc57
f1bd987
a8a8a30
9348975
fe4204d
f6c8e3f
cbeedb7
52a6c15
1410bc5
e17d0a7
efcc466
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package io.github.openflocon.flocondesktop.common.ui.window | ||
|
|
||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.CompositionLocalProvider | ||
| import androidx.compose.runtime.mutableStateListOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.input.key.Key | ||
| import androidx.compose.ui.input.key.KeyEventType | ||
| import androidx.compose.ui.input.key.key | ||
| import androidx.compose.ui.input.key.type | ||
| import androidx.compose.ui.unit.DpSize | ||
| import androidx.compose.ui.window.Window | ||
| import androidx.compose.ui.window.WindowPlacement | ||
| import androidx.compose.ui.window.WindowPosition | ||
| import androidx.compose.ui.window.WindowState | ||
| import flocondesktop.composeapp.generated.resources.Res | ||
| import flocondesktop.composeapp.generated.resources.app_icon | ||
| import io.github.openflocon.library.designsystem.components.escape.LocalEscapeHandlerStack | ||
| import org.jetbrains.compose.resources.painterResource | ||
|
|
||
| data class FloconWindowStateDesktop( | ||
| val windowState: WindowState, | ||
| ) : FloconWindowState | ||
|
|
||
| actual fun createFloconWindowState(size: DpSize?): FloconWindowState = FloconWindowStateDesktop( | ||
| WindowState( | ||
| placement = WindowPlacement.Floating, | ||
| position = WindowPosition(Alignment.Center), | ||
| size = size ?: defaultWindowSize | ||
| ) | ||
| ) | ||
|
|
||
| // TODO Use this component for main window too | ||
| @Composable | ||
| actual fun FloconWindow( | ||
| title: String, | ||
| state: FloconWindowState, | ||
| onCloseRequest: () -> Unit, | ||
| alwaysOnTop: Boolean, | ||
| content: @Composable () -> Unit, | ||
| ) { | ||
| val handlers = remember { mutableStateListOf<() -> Boolean>() } | ||
|
|
||
| Window( | ||
| title = title, | ||
| icon = painterResource(Res.drawable.app_icon), | ||
| state = (state as FloconWindowStateDesktop).windowState, | ||
| alwaysOnTop = alwaysOnTop, | ||
| onPreviewKeyEvent = { | ||
| when (it.key) { | ||
| Key.Escape if (it.type == KeyEventType.KeyDown) -> handlers.lastOrNull()?.invoke() ?: false | ||
|
|
||
| else -> false | ||
| } | ||
| }, | ||
| onCloseRequest = onCloseRequest, | ||
| ) { | ||
| CompositionLocalProvider(LocalEscapeHandlerStack provides handlers) { | ||
| content() | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package io.github.openflocon.flocondesktop.features.performance | ||
|
|
||
| import org.koin.core.module.dsl.singleOf | ||
| import org.koin.core.module.dsl.viewModel | ||
| import org.koin.compose.viewmodel.dsl.viewModelOf | ||
| import org.koin.dsl.module | ||
|
|
||
| val performanceModule = module { | ||
| singleOf(::PerformanceMetricsRepository) | ||
| viewModelOf(::PerformanceViewModel) | ||
| viewModel { (event: MetricEventUiModel) -> PerformanceDetailViewModel(event, get()) } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package io.github.openflocon.flocondesktop.features.performance | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class MetricEventUiModel( | ||
| val timestamp: String, | ||
| val ramMb: String?, | ||
| val rawRamMb: Long?, | ||
| val fps: String, | ||
| val rawFps: Double, | ||
| val jankPercentage: String, | ||
| val rawJankPercentage: Double, | ||
| val battery: String, | ||
| val screenshotPath: String?, | ||
| val isFpsDrop: Boolean, | ||
| ) | ||
|
|
||
| fun previewMetricsEvent() = MetricEventUiModel( | ||
| timestamp = "10:55:38.123", | ||
| ramMb = "150", | ||
| rawRamMb = 150L, | ||
| fps = "60.0", | ||
| rawFps = 60.0, | ||
| jankPercentage = "0.0%", | ||
| rawJankPercentage = 0.0, | ||
| battery = "85%", | ||
| screenshotPath = null, | ||
| isFpsDrop = false, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package io.github.openflocon.flocondesktop.features.performance | ||
|
|
||
| import androidx.compose.ui.unit.DpSize | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.navigation3.runtime.EntryProviderScope | ||
| import io.github.openflocon.flocondesktop.features.performance.view.PerformanceDetailScreen | ||
| import io.github.openflocon.flocondesktop.features.performance.view.PerformanceScreen | ||
| import io.github.openflocon.navigation.FloconRoute | ||
| import io.github.openflocon.navigation.WindowRoute | ||
| import io.github.openflocon.navigation.scene.WindowSceneStrategy | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| internal sealed interface PerformanceRoutes : FloconRoute { | ||
|
|
||
| @Serializable | ||
| data object Performance : PerformanceRoutes, WindowRoute { | ||
| override val singleTopKey = "performance" | ||
| } | ||
|
|
||
| @Serializable | ||
| data class Detail(val event: MetricEventUiModel) : PerformanceRoutes, WindowRoute { | ||
| override val singleTopKey = null | ||
| } | ||
| } | ||
|
|
||
| fun EntryProviderScope<FloconRoute>.performanceRoutes() { | ||
| entry<PerformanceRoutes.Performance>( | ||
| metadata = WindowSceneStrategy.window( | ||
| size = DpSize( | ||
| width = 1000.dp, | ||
| height = 800.dp | ||
| ) | ||
| ) | ||
| ) { | ||
| PerformanceScreen() | ||
| } | ||
| entry<PerformanceRoutes.Detail>( | ||
| metadata = WindowSceneStrategy.window( | ||
| size = DpSize( | ||
| width = 800.dp, | ||
| height = 1000.dp | ||
| ) | ||
| ) | ||
| ) { | ||
| PerformanceDetailScreen(initialEvent = it.event) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package io.github.openflocon.flocondesktop.features.performance | ||
|
|
||
| import androidx.lifecycle.ViewModel | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.asStateFlow | ||
| import kotlinx.coroutines.flow.update | ||
|
|
||
| class PerformanceDetailViewModel( | ||
| initialEvent: MetricEventUiModel, | ||
| private val repository: PerformanceMetricsRepository, | ||
| ) : ViewModel() { | ||
|
|
||
| private val _event = MutableStateFlow(initialEvent) | ||
| val event = _event.asStateFlow() | ||
|
|
||
| private val _hasNext = MutableStateFlow(false) | ||
| val hasNext = _hasNext.asStateFlow() | ||
|
|
||
| private val _hasPrevious = MutableStateFlow(false) | ||
| val hasPrevious = _hasPrevious.asStateFlow() | ||
|
|
||
| init { | ||
| updateNavigationState() | ||
| } | ||
|
|
||
| fun onNext() { | ||
| val metrics = repository.getMetrics() | ||
| val currentIndex = metrics.indexOfFirst { it.timestamp == _event.value.timestamp } | ||
| if (currentIndex > 0) { | ||
| _event.value = metrics[currentIndex - 1] | ||
| updateNavigationState() | ||
| } | ||
| } | ||
|
|
||
| fun onPrevious() { | ||
| val metrics = repository.getMetrics() | ||
| val currentIndex = metrics.indexOfFirst { it.timestamp == _event.value.timestamp } | ||
| if (currentIndex != -1 && currentIndex < metrics.size - 1) { | ||
| _event.value = metrics[currentIndex + 1] | ||
| updateNavigationState() | ||
| } | ||
| } | ||
|
|
||
| private fun updateNavigationState() { | ||
| val metrics = repository.getMetrics() | ||
| val currentIndex = metrics.indexOfFirst { it.timestamp == _event.value.timestamp } | ||
| _hasNext.value = currentIndex > 0 | ||
| _hasPrevious.value = currentIndex != -1 && currentIndex < metrics.size - 1 | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,20 @@ | ||||||||||||||||||||||||||||||||||||||||||
| package io.github.openflocon.flocondesktop.features.performance | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| import kotlinx.coroutines.flow.MutableStateFlow | ||||||||||||||||||||||||||||||||||||||||||
| import kotlinx.coroutines.flow.asStateFlow | ||||||||||||||||||||||||||||||||||||||||||
| import kotlinx.coroutines.flow.update | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| class PerformanceMetricsRepository { | ||||||||||||||||||||||||||||||||||||||||||
| private val _metrics = MutableStateFlow<List<MetricEventUiModel>>(emptyList()) | ||||||||||||||||||||||||||||||||||||||||||
| val metrics = _metrics.asStateFlow() | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| fun addMetric(metric: MetricEventUiModel) { | ||||||||||||||||||||||||||||||||||||||||||
| _metrics.update { listOf(metric) + it } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| fun clear() { | ||||||||||||||||||||||||||||||||||||||||||
| _metrics.value = emptyList() | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+8
to
+17
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation of Using a
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| fun getMetrics() = _metrics.value | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
onNextandonPreviousfunctions are inefficient as they fetch the full list of metrics from the repository and find the current index on every invocation. Since the list of metrics can grow, this should be optimized.Additionally, the naming is confusing.
onNextmoves to a newer event (lower index), whileonPreviousmoves to an older event (higher index). The UI uses forward/back arrows which might be interpreted differently by users.Consider caching the list of metrics and the current index within the ViewModel. You could also rename the functions to be more explicit, like
onNewerEvent()andonOlderEvent()to avoid ambiguity.