Browse Source

Move to 0.5.0-build262

debug-writer
Roman Sedaikin 3 years ago committed by Rsedaikin
parent
commit
2a3575dd00
  1. 4
      debug-writer/build.gradle.kts
  2. 73
      debug-writer/src/main/kotlin/debugwriter/Main.kt
  3. 14
      debug-writer/src/main/kotlin/debugwriter/Utils.kt

4
debug-writer/build.gradle.kts

@ -3,9 +3,9 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat
plugins { plugins {
// __KOTLIN_COMPOSE_VERSION__ // __KOTLIN_COMPOSE_VERSION__
kotlin("jvm") version "1.4.32" kotlin("jvm") version "1.5.21"
// __LATEST_COMPOSE_RELEASE_VERSION__ // __LATEST_COMPOSE_RELEASE_VERSION__
id("org.jetbrains.compose") version (System.getenv("COMPOSE_TEMPLATE_COMPOSE_VERSION") ?: "0.4.0-build188") id("org.jetbrains.compose") version (System.getenv("COMPOSE_TEMPLATE_COMPOSE_VERSION") ?: "0.5.0-build262")
} }
repositories { repositories {

73
debug-writer/src/main/kotlin/debugwriter/Main.kt

@ -35,50 +35,55 @@ fun main() {
if (!result) { if (!result) {
output = "Failed to cteate file: $fileName" output = "Failed to cteate file: $fileName"
} }
try {
Window(
title = "DebugWriter",
size = IntSize(650, 450)
) {
val window = LocalAppWindow.current
Window( AppTheme {
title = "DebugWriter", Surface(
size = IntSize(650, 450) modifier = Modifier.fillMaxSize()
) {
val window = LocalAppWindow.current
AppTheme {
Surface(
modifier = Modifier.fillMaxSize()
) {
Box(
modifier = Modifier.fillMaxSize().padding(20.dp),
contentAlignment = Alignment.Center
) { ) {
Column { Box(
Header("Click [Refresh] to refresh info or [Open file] to see the output file.") modifier = Modifier.fillMaxSize().padding(20.dp),
if (isReady) { contentAlignment = Alignment.Center
TextBox(output, Modifier.weight(1f).padding(start = 30.dp, end = 30.dp)) ) {
} else { Column {
Loader(Modifier.weight(1f).fillMaxWidth()) Header("Click [Refresh] to refresh info or [Open file] to see the output file.")
} if (isReady) {
Row(modifier = Modifier.fillMaxWidth()) { TextBox(output, Modifier.weight(1f).padding(start = 30.dp, end = 30.dp))
Button("Refresh", Modifier.weight(1f), { writeDebugInfo() }) } else {
Button( Loader(Modifier.weight(1f).fillMaxWidth())
text = "Open file", }
modifier = Modifier.weight(1f), Row(modifier = Modifier.fillMaxWidth()) {
action = { Button("Refresh", Modifier.weight(1f), { writeDebugInfo() })
if(!revealDebugOutput(fileName)) { Button(
output = "Failed to open file: $fileName" text = "Open file",
modifier = Modifier.weight(1f),
action = {
if(!revealDebugOutput(fileName)) {
output = "Failed to open file: $fileName"
}
} }
} )
) Button("Close", Modifier.weight(1f), { window.close() })
Button("Close", Modifier.weight(1f), { window.close() }) }
} }
} }
} }
} }
}
if (result) { if (result) {
writeDebugInfo() writeDebugInfo()
}
} }
} }
catch(e: Exception) {
writeException(fileName, e)
System.exit(0)
}
} }
private fun writeDebugInfo() { private fun writeDebugInfo() {

14
debug-writer/src/main/kotlin/debugwriter/Utils.kt

@ -24,6 +24,20 @@ fun enableDebugWritingTo(fileName: String = "output.txt"): Boolean {
} }
} }
fun writeException(fileName: String = "output.txt", e: Exception) {
try {
val directory = File(Paths.get(fileName).getParent().toString())
if (!directory.exists()) {
directory.mkdir()
}
val stream = PrintStream(FileOutputStream("$fileName"))
e.printStackTrace(stream)
revealDebugOutput(fileName)
} catch(e: Exception) {
}
}
fun readDebugOutput(fileName: String = "output.txt"): String { fun readDebugOutput(fileName: String = "output.txt"): String {
val file = File("$fileName") val file = File("$fileName")
if (!file.exists()) { if (!file.exists()) {

Loading…
Cancel
Save