diff --git a/.idea/misc.xml b/.idea/misc.xml index c9a9385..438bac6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,7 @@ - + \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index fd957d5..2c0c90b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -26,6 +26,7 @@ kotlin { } } val jvmTest by getting + val resourcesDir = "src/common/resources" } } diff --git a/src/jvmMain/kotlin/Constant.kt b/src/jvmMain/kotlin/Constant.kt index 507fd90..28c695f 100644 --- a/src/jvmMain/kotlin/Constant.kt +++ b/src/jvmMain/kotlin/Constant.kt @@ -1,8 +1,18 @@ +import java.io.File +import java.net.URLDecoder + object Constant { const val SUCCESS = 0 const val FAILURE = 1 + private const val bundleToolFileName = "bundletool-all-1.15.6.jar" fun getCommand(): String { + if(Utils.isWindowsOS()){ + val jarFileEncodedUrl = object {}.javaClass.classLoader.getResource(bundleToolFileName) + val decodedJarPath = URLDecoder.decode(jarFileEncodedUrl.path, "UTF-8") + val bundletool = File(decodedJarPath) + return "java -jar \"${bundletool.absolutePath}\" build-apks --mode=universal --bundle=\"INPUT_FILE_PATH\" --output=\"OUTPUT_FILE_NAME.apks\"" + } return "bundletool build-apks --mode=universal --bundle=INPUT_FILE_PATH --output=OUTPUT_FILE_NAME.apks" } } \ No newline at end of file diff --git a/src/jvmMain/kotlin/Main.kt b/src/jvmMain/kotlin/Main.kt index affe12f..f145912 100644 --- a/src/jvmMain/kotlin/Main.kt +++ b/src/jvmMain/kotlin/Main.kt @@ -5,7 +5,6 @@ import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @@ -15,20 +14,20 @@ import kotlinx.coroutines.launch import theme.Styles import java.awt.FileDialog import java.awt.Frame -import javax.swing.text.Style +import java.io.BufferedReader +import java.io.InputStreamReader @Composable @Preview fun App() { - val coroutineScope = rememberCoroutineScope() - var logs by remember { mutableStateOf("========== Logs View ==========\n\n") } var isLoading by remember { mutableStateOf(false) } var isOpen by remember { mutableStateOf(false) } if (isOpen) { FileDialog { fileName, directory -> isOpen = false + //Get Command to Execute val cmd = Constant.getCommand().replace("INPUT_FILE_PATH", "${directory}$fileName") .replace("OUTPUT_FILE_NAME", "${directory}${fileName.split(".")[0]}") Log.i("Command $cmd") @@ -39,12 +38,20 @@ fun App() { val runtime = Runtime.getRuntime() val startTime = System.currentTimeMillis() try { + //Launch Runtime to execute command val process = runtime.exec(cmd) + // Read and log error output + val errorReader = BufferedReader(InputStreamReader(process.errorStream)) + Log.i("Process Error Output:") + while (errorReader.readLine().also { logs += "\n ERROR -> $it" } != null) { + isLoading = false + } process.waitFor() val endTime = System.currentTimeMillis() if (process.exitValue() == 0) { Log.i("Command Executed in ${((endTime - startTime) / 1000)}s") logs += "\nCommand Executed in ${((endTime - startTime) / 1000)}s\n" + // Do further file operation after new apks is generated FileHelper.performFileOperations(directory, fileName) { status, message -> isLoading = false Log.i("STATUS - $status\nMESSAGE - $message") diff --git a/src/jvmMain/kotlin/Utils.kt b/src/jvmMain/kotlin/Utils.kt new file mode 100644 index 0000000..22bc2da --- /dev/null +++ b/src/jvmMain/kotlin/Utils.kt @@ -0,0 +1,10 @@ +import androidx.compose.ui.text.toLowerCase +import java.util.* + +object Utils { + + fun isWindowsOS(): Boolean{ + return System.getProperty("os.name").lowercase(Locale.getDefault()).contains("windows") + } + +} \ No newline at end of file diff --git a/src/jvmMain/resources/bundletool-all-1.15.6.jar b/src/jvmMain/resources/bundletool-all-1.15.6.jar new file mode 100644 index 0000000..6d7f4a2 Binary files /dev/null and b/src/jvmMain/resources/bundletool-all-1.15.6.jar differ