Skip to content

Commit

Permalink
Parallelize badge comunication
Browse files Browse the repository at this point in the history
  • Loading branch information
mariobodemann authored and Mario Bodemann committed Sep 11, 2023
1 parent 57c516f commit b7cf17c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
package de.berlindroid.zekompanion.desktop


import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.material.MaterialTheme
import androidx.compose.ui.awt.ComposePanel
import androidx.compose.ui.graphics.toAwtImage
import androidx.compose.ui.res.painterResource
Expand All @@ -19,7 +18,8 @@ import de.berlindroid.zekompanion.ditherFloydSteinberg
import de.berlindroid.zekompanion.resize
import de.berlindroid.zekompanion.toBinary
import de.berlindroid.zekompanion.zipit
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.awt.BorderLayout
import java.awt.Dimension
import java.awt.GraphicsEnvironment
Expand All @@ -33,12 +33,12 @@ import javax.swing.JFrame
fun main() = application {
val painter = painterResource("icon.png")

Window(
title = "ZeBadge - Kompanion",
icon = painter,
onCloseRequest = ::exitApplication,
) {
Column {
MaterialTheme {
Window(
title = "ZeBadge - Kompanion",
icon = painter,
onCloseRequest = ::exitApplication,
) {
ZeDesktopApp(
sendToBadge = { state ->
when (state) {
Expand Down Expand Up @@ -115,7 +115,7 @@ private fun State.EditNameBadge.toBufferedImage(): BufferedImage {

private fun sendImageToBadge(image: BufferedImage, callback: (Result<Int>) -> Unit) {
try {
runBlocking {
GlobalScope.launch {
with(buildBadgeManager("")) {
if (isConnected()) {
val payload = BadgePayload(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -39,18 +38,16 @@ fun ZeDesktopApp(sendToBadge: (State) -> Unit) {

var state: State by remember { mutableStateOf(Undecided) }

MaterialTheme {
Column {
Header(state) { state = it }
Column {
Header(state) { state = it }

Content(
state = state,
sendToBadge = { sendToBadge(state) },
stateUpdated = { state = it },
)
Content(
state = state,
sendToBadge = { sendToBadge(state) },
stateUpdated = { state = it },
)

Footer(platform)
}
Footer(platform)
}
}

Expand Down

0 comments on commit b7cf17c

Please sign in to comment.