Sfoglia il codice sorgente

window improvement

fix apps startup & parsing desktop file
Milan Jurkulak 2 anni fa
parent
commit
a8767143a6

+ 9 - 5
src/main/kotlin/eu/mjdev/desktop/extensions/Compose.kt

@@ -8,14 +8,12 @@ import androidx.compose.material.MaterialTheme
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.LaunchedEffect
 import androidx.compose.runtime.MutableState
+import androidx.compose.ui.Alignment
 import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.graphics.painter.Painter
 import androidx.compose.ui.input.key.KeyEvent
 import androidx.compose.ui.unit.*
-import androidx.compose.ui.window.FrameWindowScope
-import androidx.compose.ui.window.Window
-import androidx.compose.ui.window.WindowPlacement
-import androidx.compose.ui.window.rememberWindowState
+import androidx.compose.ui.window.*
 import eu.mjdev.desktop.provider.DesktopProvider.Companion.desktopLocalProvider
 import kotlinx.coroutines.CoroutineScope
 
@@ -125,9 +123,12 @@ object Compose {
     fun TopWindow(
         // todo
         @Suppress("UNUSED_PARAMETER") movable: Boolean = false,
+        position: WindowPosition = WindowPosition.Aligned(Alignment.BottomStart),
+        size: DpSize = DpSize(800.dp, 600.dp),
         resizable: Boolean = false,
         undecorated: Boolean = true,
         visible: Boolean = true,
+        minimized: Boolean = false,
         title: String = "",
         icon: Painter? = null,
         focusable: Boolean = true,
@@ -137,7 +138,10 @@ object Compose {
         content: @Composable FrameWindowScope.() -> Unit
     ) = Window(
         state = rememberWindowState(
-            placement = WindowPlacement.Floating
+            placement = WindowPlacement.Floating,
+            position = position,
+            size = size,
+            isMinimized = minimized
         ),
         resizable = resizable,
         undecorated = undecorated,

+ 4 - 1
src/main/kotlin/eu/mjdev/desktop/provider/data/App.kt

@@ -33,8 +33,11 @@ class App(
     var iconTint: Color? = null
 
     fun start() = runCatching {
+        println("Starting app: $name [$exec]")
         ProcessBuilder("/bin/bash", "-c", exec).start()
-    }.onFailure { error -> error.printStackTrace() }
+    }.onFailure { error ->
+        error.printStackTrace()
+    }
 
     companion object {
         val Empty: App = App()

+ 15 - 10
src/main/kotlin/eu/mjdev/desktop/provider/data/DesktopFile.kt

@@ -6,17 +6,22 @@ import java.io.File
 class DesktopFile(
     val file: File
 ) {
-    private val props by lazy {
-        file.readLines().mapNotNull { line ->
-            line.split("=").let { pair ->
-                when (pair.size) {
-                    2 -> Pair(pair[0], pair[1])
-                    1 -> Pair(pair[0], "")
-                    else -> null
-                }
-            }
+    private val content
+        get() = file.readText()
+
+    private val lines
+        get() = content.split("\n").map { line ->
+            line.trim()
+        }
+
+    private val props
+        get() = lines.mapNotNull { line ->
+            if (line.contains("=")) {
+                val first = line.substring(0, line.indexOf('='))
+                val second = line.substring(line.indexOf('=') + 1)
+                Pair(first, second)
+            } else null
         }.toMap()
-    }
 
     val type
         get() = props[Prop_Type] ?: ""