Skip to content

Commit

Permalink
Feat/new settings UI (#11)
Browse files Browse the repository at this point in the history
* move files to correct packages

* wip new settings ui

* icons

* stats tab

* move some files around

* style tab

* app settings and footer

* Fine tune layout
Use material 3 switch

* drag window

* change color per bar upon threshold

* link build version to footer

* update both position and location when anything changes on the overlay data class

* configure build

* report correct unit
  • Loading branch information
Danil0v3s authored Oct 22, 2024
1 parent 449280b commit 392bf7b
Show file tree
Hide file tree
Showing 35 changed files with 1,303 additions and 298 deletions.
6 changes: 6 additions & 0 deletions core/common/src/main/kotlin/mahm/Data.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ val Data.GpuTemp: Int
get() = (entries.firstOrNull { it.dwSrcId == SourceID.MONITORING_SOURCE_ID_GPU_TEMPERATURE }?.data?.toInt()
?: 0).coerceAtLeast(1)

val Data.GpuTempUnit: String
get() = entries.firstOrNull { it.dwSrcId == SourceID.MONITORING_SOURCE_ID_GPU_TEMPERATURE }?.szLocalisedSrcUnits ?: "c"

val Data.GpuUsage: Int
get() = (entries.firstOrNull { it.dwSrcId == SourceID.MONITORING_SOURCE_ID_GPU_USAGE }?.data?.toInt()
?: 0).coerceAtLeast(1)
Expand All @@ -37,6 +40,9 @@ val Data.CpuTemp: Int
get() = (entries.firstOrNull { it.dwSrcId == SourceID.MONITORING_SOURCE_ID_CPU_TEMPERATURE }?.data?.toInt()
?: 0).coerceAtLeast(1)

val Data.CpuTempUnit: String
get() = entries.firstOrNull { it.dwSrcId == SourceID.MONITORING_SOURCE_ID_CPU_TEMPERATURE }?.szLocalisedSrcUnits ?: "c"

val Data.CpuUsage: Int
get() = (entries.firstOrNull { it.dwSrcId == SourceID.MONITORING_SOURCE_ID_CPU_USAGE }?.data?.toInt()
?: 0).coerceAtLeast(1)
Expand Down
2 changes: 1 addition & 1 deletion core/native/src/main/kotlin/mahm/MahmReader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class MahmReader {
val array = ByteArray(MAX_STRING_LENGTH)
get(array, 0, MAX_STRING_LENGTH)

return String(trim(array), StandardCharsets.UTF_8)
return String(trim(array), StandardCharsets.ISO_8859_1)
}

private fun trim(bytes: ByteArray): ByteArray {
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "

[libraries]
compose-material-icons = "org.jetbrains.compose.material:material-icons-extended-desktop:1.3.1"
compose-material = "org.jetbrains.compose.material3:material3-desktop:1.2.1"

ktor-client-auth = { module = "io.ktor:ktor-client-auth", version.ref = "ktor" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
Expand Down
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ rootProject.name = "CleanMeter"

include("core:common")
include("core:native")
include("target:client")
include("target:server")
19 changes: 18 additions & 1 deletion target/server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {

implementation(compose.desktop.currentOs)
implementation(libs.compose.material.icons)
implementation(libs.compose.material)

implementation(projects.core.common)
implementation(projects.core.native)
Expand All @@ -32,10 +33,26 @@ sourceSets {
compose.desktop {
application {
mainClass = "br.com.firstsoft.target.server.ServerMainKt"

buildTypes.release.proguard {
isEnabled = false
optimize.set(false)
}


nativeDistributions {
targetFormats(TargetFormat.Msi)
targetFormats(TargetFormat.Exe, TargetFormat.Deb)

packageName = "Clean Meter"
packageVersion = "0.0.1"

windows {
iconFile.set(project.file("src/main/resources/imgs/favicon.ico"))
}

linux {
iconFile.set(project.file("src/main/resources/imgs/logo.png"))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import com.github.kwhat.jnativehook.keyboard.NativeKeyListener
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import ui.PREFERENCE_START_MINIMIZED
import ui.app.OVERLAY_SETTINGS_PREFERENCE_KEY
import ui.app.Overlay
import ui.app.OverlaySettings
import ui.app.Settings
Expand All @@ -42,6 +45,20 @@ val positions = listOf(
Alignment.BottomEnd,
)

private fun loadOverlaySettings(): OverlaySettings {
val json = PreferencesRepository.getPreferenceString(OVERLAY_SETTINGS_PREFERENCE_KEY)
val settings = if (json != null) {
try {
Json.decodeFromString<OverlaySettings>(json)
} catch (e: Exception) {
OverlaySettings()
}
} else {
OverlaySettings()
}
return settings
}

fun main() {
val channel = Channel<Unit>()

Expand All @@ -59,13 +76,13 @@ fun main() {
})

application {
var overlaySettings by remember { mutableStateOf(OverlaySettings()) }
var overlaySettings by remember { mutableStateOf(loadOverlaySettings()) }

OverlayWindow(channel, overlaySettings)

SettingsWindow {
SettingsWindow(overlaySettings, {
overlaySettings = it
}
})
}
}

Expand All @@ -81,11 +98,9 @@ private fun ApplicationScope.OverlayWindow(
}
}

val alignment = remember(overlaySettings.positionIndex) { positions[overlaySettings.positionIndex] }
val overlayState = rememberWindowState().apply {
size = if (overlaySettings.isHorizontal) DpSize(1024.dp, 80.dp) else DpSize(350.dp, 1024.dp)
placement = WindowPlacement.Floating
position = WindowPosition.Aligned(alignment)
}

val graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment()
Expand All @@ -105,7 +120,8 @@ private fun ApplicationScope.OverlayWindow(
focusable = false,
enabled = false,
) {
LaunchedEffect(alignment, overlaySettings.selectedDisplayIndex) {
LaunchedEffect(overlaySettings) {
val alignment = positions[overlaySettings.positionIndex]
val location = when (alignment) {
Alignment.TopStart -> IntSize(graphicsConfiguration.bounds.x, graphicsConfiguration.bounds.y)
Alignment.TopCenter -> IntSize(
Expand Down Expand Up @@ -135,6 +151,7 @@ private fun ApplicationScope.OverlayWindow(

else -> IntSize.Zero
}
overlayState.position = WindowPosition.Aligned(alignment)
window.setLocation(location.width, location.height)
window.toFront()
}
Expand All @@ -146,6 +163,7 @@ private fun ApplicationScope.OverlayWindow(

@Composable
private fun ApplicationScope.SettingsWindow(
overlaySettings: OverlaySettings,
onOverlaySettings: (OverlaySettings) -> Unit
) {
var isVisible by remember {
Expand All @@ -157,7 +175,7 @@ private fun ApplicationScope.SettingsWindow(
}
val icon = painterResource("imgs/logo.png")
val state = rememberWindowState().apply {
size = DpSize(500.dp, 500.dp)
size = DpSize(650.dp, 900.dp)
}

Window(
Expand All @@ -166,9 +184,16 @@ private fun ApplicationScope.SettingsWindow(
icon = icon,
visible = isVisible,
title = "Clean Meter",
resizable = false
resizable = false,
undecorated = true,
transparent = true,
) {
Settings(onOverlaySettings = onOverlaySettings)
Settings(
overlaySettings = overlaySettings,
onOverlaySettings = onOverlaySettings,
onCloseRequest = { isVisible = false },
onMinimizeRequest = { state.isMinimized = true }
)
}

if (!isVisible) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package br.com.firstsoft.target.server.ui

import androidx.compose.ui.graphics.Color

object ColorTokens {
val Green = Color(0xff1cad69)
val Yellow = Color(0xfffcc748)
val Red = Color(0xffed4335)
val ClearGray = Color(0x11d3d3d3)
val OffWhite = Color(0xffc0c0c0)

val BackgroundOffWhite = Color(0xffF0F1F1)
val BarelyVisibleGray = Color(0x0C111D1A)
val AlmostVisibleGray = Color(0xFFCECFD2)
val DarkGray = Color(0xFF0C111D)
val MutedGray = Color(0xFF475467)
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 392bf7b

Please sign in to comment.