Skip to content

Commit

Permalink
Add a Progress Indicator (#35)
Browse files Browse the repository at this point in the history
* Add a Progress Indicator

* Fix dependencies

Co-authored-by: Alon Albert <[email protected]>
  • Loading branch information
romainguy and alonalbert authored May 6, 2024
1 parent ae97935 commit 5961cef
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 26 deletions.
9 changes: 8 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ kotlin {
implementation(compose.desktop.currentOs) {
exclude(group = "org.jetbrains.compose.material")
}
implementation(libs.collection)
implementation(libs.compose.material3)
implementation(libs.compose.splitpane)
implementation(libs.jewel)
implementation(libs.jewel.decorated)
implementation(libs.jna)
implementation(libs.lifecycle)
implementation(libs.lifecycle.compose)
implementation(libs.lifecycle.viewmodel)
implementation(libs.lifecycle.viewmodel.compose)
implementation(libs.skiko.mac)
implementation(libs.rsyntaxtextarea)
implementation(libs.compose.splitpane)
implementation(libs.rstaui)
runtimeOnly(libs.skiko.linux)
}
Expand Down
11 changes: 10 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
[versions]
collection = "1.4.0"
compose = "1.6.10-rc01"
jewel = "0.18.1"
jna = '5.14.0'
jna = "5.14.0"
kotlin = "1.9.23"
lifecycle = "2.8.0-rc01"
rstaui = "3.3.1"
rsyntaxtextarea="3.4.0"
skiko="0.8.4"

[libraries]
collection = { group = "androidx.collection", name = "collection", version.ref = "collection" }
compose-material3 = { group = "org.jetbrains.compose.material3", name = "material3-desktop", version.ref = "compose" }
compose-splitpane = { group = "org.jetbrains.compose.components", name = "components-splitpane-desktop", version.ref = "compose" }
jewel = { group = "org.jetbrains.jewel", name = "jewel-int-ui-standalone-241", version.ref = "jewel" }
jewel-decorated = { group = "org.jetbrains.jewel", name = "jewel-int-ui-decorated-window-241", version.ref = "jewel" }
jna = { group = "net.java.dev.jna", name = "jna", version.ref = "jna" }
lifecycle = { group = "org.jetbrains.androidx.lifecycle", name = "lifecycle-runtime", version.ref = "lifecycle" }
lifecycle-compose = { group = "org.jetbrains.androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "lifecycle" }
lifecycle-viewmodel = { group = "org.jetbrains.androidx.lifecycle", name = "lifecycle-viewmodel", version.ref = "lifecycle" }
lifecycle-viewmodel-compose = { group = "org.jetbrains.androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "lifecycle" }
rstaui = { group = "com.fifesoft", name = "rstaui", version.ref = "rstaui" }
rsyntaxtextarea = { group = "com.fifesoft", name = "rsyntaxtextarea", version.ref = "rsyntaxtextarea" }
skiko-linux = { group = "org.jetbrains.skiko", name = "skiko-awt-runtime-linux-arm64", version.ref = "skiko" }
Expand Down
41 changes: 23 additions & 18 deletions src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/Disassembly.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,32 @@
package dev.romainguy.kotlin.explorer

import dev.romainguy.kotlin.explorer.dex.DexDumpParser
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.launch
import java.nio.file.Files
import java.nio.file.Path
import java.util.stream.Collectors
import kotlin.io.path.extension

private const val TotalSteps = 5
private const val Done = 1f

suspend fun disassemble(
toolPaths: ToolPaths,
source: String,
onDex: (String) -> Unit,
onOat: (String) -> Unit,
onStatusUpdate: (String) -> Unit,
onStatusUpdate: (String, Float) -> Unit,
optimize: Boolean
) = coroutineScope {
val ui = currentCoroutineContext()

launch(Dispatchers.IO) {
launch(ui) { onStatusUpdate("Compiling Kotlin…") }
var step = 0f

launch(ui) { onStatusUpdate("Compiling Kotlin…", step++ / TotalSteps) }

val directory = toolPaths.tempDirectory
cleanupClasses(directory)
Expand All @@ -50,17 +58,14 @@ suspend fun disassemble(
if (kotlinc.exitCode != 0) {
launch(ui) {
onDex(kotlinc.output.replace(path.parent.toString() + "/", ""))
onStatusUpdate("Ready")
onStatusUpdate("Ready", Done)
}
return@launch
}

launch(ui) {
onStatusUpdate(if (optimize) {
"Optimizing with R8…"
} else {
"Compiling with D8…"
})
val status = if (optimize) "Optimizing with R8…" else "Compiling with D8…"
onStatusUpdate(status, step++ / TotalSteps)
}

writeR8Rules(directory)
Expand All @@ -73,12 +78,12 @@ suspend fun disassemble(
if (r8.exitCode != 0) {
launch(ui) {
onDex(r8.output)
onStatusUpdate("Ready")
onStatusUpdate("Ready", Done)
}
return@launch
}

launch(ui) { onStatusUpdate("Disassembling DEX…") }
launch(ui) { onStatusUpdate("Disassembling DEX…", step++ / TotalSteps) }

val dexdump = process(
toolPaths.dexdump.toString(),
Expand All @@ -90,14 +95,14 @@ suspend fun disassemble(
if (dexdump.exitCode != 0) {
launch(ui) {
onDex(dexdump.output)
onStatusUpdate("Ready")
onStatusUpdate("Ready", Done)
}
return@launch
}

launch(ui) {
onDex(DexDumpParser(dexdump.output).parseDexDump())
onStatusUpdate("AOT compilation…")
onStatusUpdate("AOT compilation…", step++ / TotalSteps)
}

val push = process(
Expand All @@ -111,7 +116,7 @@ suspend fun disassemble(
if (push.exitCode != 0) {
launch(ui) {
onOat(push.output)
onStatusUpdate("Ready")
onStatusUpdate("Ready", Done)
}
return@launch
}
Expand All @@ -128,12 +133,12 @@ suspend fun disassemble(
if (dex2oat.exitCode != 0) {
launch(ui) {
onOat(dex2oat.output)
onStatusUpdate("Ready")
onStatusUpdate("Ready", Done)
}
return@launch
}

launch(ui) { onStatusUpdate("Disassembling OAT…") }
launch(ui) { onStatusUpdate("Disassembling OAT…", step++ / TotalSteps) }

val oatdump = process(
toolPaths.adb.toString(),
Expand All @@ -146,11 +151,11 @@ suspend fun disassemble(
launch(ui) { onOat(filterOat(oatdump.output)) }

if (oatdump.exitCode != 0) {
launch(ui) { onStatusUpdate("Ready") }
launch(ui) { onStatusUpdate("Ready", Done) }
return@launch
}

launch(ui) { onStatusUpdate("Ready") }
launch(ui) { onStatusUpdate("Ready", Done) }
}
}

Expand Down
22 changes: 16 additions & 6 deletions src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ package dev.romainguy.kotlin.explorer

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.CenterVertically
import androidx.compose.ui.Modifier
import androidx.compose.ui.awt.SwingPanel
import androidx.compose.ui.input.key.Key.Companion.D
Expand Down Expand Up @@ -76,6 +78,7 @@ private fun FrameWindowScope.KotlinExplorer(
// TODO: Move all those remembers to an internal private state object
var activeTextArea by remember { mutableStateOf<RSyntaxTextArea?>(null) }
var status by remember { mutableStateOf("Ready") }
var progress by remember { mutableStateOf(1f) }

val searchListener = remember { object : SearchListener {
override fun searchEvent(e: SearchEvent?) {
Expand Down Expand Up @@ -125,7 +128,11 @@ private fun FrameWindowScope.KotlinExplorer(
val dexPanel: @Composable () -> Unit = { TextPanel("DEX", dexTextArea, explorerState) }
val oatPanel: @Composable () -> Unit = { TextPanel("OAT", oatTextArea, explorerState) }
var panels by remember { mutableStateOf(explorerState.getPanels(sourcePanel, dexPanel, oatPanel)) }

val onProgressUpdate: (String, Float) -> Unit = { newStatus: String, newProgress: Float ->
status = newStatus
progress = newProgress
}

MainMenu(
explorerState,
sourceTextArea,
Expand All @@ -137,7 +144,7 @@ private fun FrameWindowScope.KotlinExplorer(
}
},
{ oat -> updateTextArea(oatTextArea, oat) },
{ statusUpdate -> status = statusUpdate },
onProgressUpdate,
{ findDialog.isVisible = true },
{ SearchEngine.find(activeTextArea, findDialog.searchContext) },
{ showSettings = true },
Expand All @@ -154,14 +161,17 @@ private fun FrameWindowScope.KotlinExplorer(
modifier = Modifier.background(JewelTheme.globalColors.paneBackground)
) {
MultiSplitter(modifier = Modifier.weight(1.0f), panels)
Row {
Row(verticalAlignment = CenterVertically) {
val width = 160.dp
Text(
modifier = Modifier
.weight(1.0f, true)
.align(Alignment.CenterVertically)
.widthIn(min = width, max = width)
.padding(8.dp),
text = status
)
if (progress < 1) {
LinearProgressIndicator({ progress })
}
}
}
}
Expand Down Expand Up @@ -253,7 +263,7 @@ private fun FrameWindowScope.MainMenu(
sourceTextArea: RSyntaxTextArea,
onDexUpdate: (String?) -> Unit,
onOatUpdate: (String) -> Unit,
onStatusUpdate: (String) -> Unit,
onStatusUpdate: (String, Float) -> Unit,
onFindClicked: () -> Unit,
onFindNextClicked: () -> Unit,
onOpenSettings: () -> Unit,
Expand Down

0 comments on commit 5961cef

Please sign in to comment.