diff --git a/src/jvmMain/kotlin/Main.kt b/src/jvmMain/kotlin/Main.kt index 70cd810..affe12f 100644 --- a/src/jvmMain/kotlin/Main.kt +++ b/src/jvmMain/kotlin/Main.kt @@ -1,54 +1,60 @@ import androidx.compose.desktop.ui.tooling.preview.Preview import androidx.compose.foundation.layout.* -import androidx.compose.material.Button -import androidx.compose.material.CircularProgressIndicator -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Text +import androidx.compose.material.* 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.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.compose.ui.window.* +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import theme.Styles import java.awt.FileDialog import java.awt.Frame +import javax.swing.text.Style @Composable @Preview fun App() { - var logs by remember { mutableStateOf("Logs:") } + val coroutineScope = rememberCoroutineScope() + var logs by remember { mutableStateOf("========== Logs View ==========\n\n") } + var isLoading by remember { mutableStateOf(false) } var isOpen by remember { mutableStateOf(false) } - var showLoading by remember { mutableStateOf(false) } if (isOpen) { FileDialog { fileName, directory -> - logs = "Logs: " isOpen = false val cmd = Constant.getCommand().replace("INPUT_FILE_PATH", "${directory}$fileName") .replace("OUTPUT_FILE_NAME", "${directory}${fileName.split(".")[0]}") Log.i("Command $cmd") - showLoading = true - val runtime = Runtime.getRuntime() - val startTime = System.currentTimeMillis() - val process = runtime.exec(cmd) - process.waitFor() - val endTime = System.currentTimeMillis() - logs += if (process.exitValue() == 0) { - Log.i("Command Executed in ${((endTime - startTime) / 1000)}s") - "Command Executed in ${((endTime - startTime) / 1000)}s\n" - }else{ - "Failed while running command" - } + logs += "Executing Command : \n$cmd\n" - FileHelper.performFileOperations(directory, fileName) { status, message -> - Log.i("STATUS - $status\nMESSAGE - $message") - logs += "STATUS - $status\nMESSAGE - $message" - showLoading = false + coroutineScope.launch(Dispatchers.IO) { + isLoading = true + val runtime = Runtime.getRuntime() + val startTime = System.currentTimeMillis() + try { + val process = runtime.exec(cmd) + 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" + FileHelper.performFileOperations(directory, fileName) { status, message -> + isLoading = false + Log.i("STATUS - $status\nMESSAGE - $message") + logs += "\nFiles Operations Starting...\n$message\n" + } + } + } catch (e: Exception) { + isLoading = false + logs += "Failed -> ${e.printStackTrace()}" + } } } } @@ -61,39 +67,37 @@ fun App() { Spacer(modifier = Modifier.padding(12.dp)) Text( text = "Aab To Apk", - style = TextStyle( - fontSize = 28.sp - ) + style = Styles.TextStyleBold(28.sp) ) Spacer(modifier = Modifier.padding(8.dp)) - Button( - onClick = { - isOpen = true - }, - modifier = Modifier.padding(start = 16.dp, top = 8.dp, end = 16.dp, bottom = 8.dp) - .fillMaxWidth(0.32f), - ) { - Text( - text = "Choose File", - color = Color.White, - fontWeight = FontWeight.Medium, - ) - } - Spacer(modifier = Modifier.padding(8.dp)) - Text( - textAlign = TextAlign.Center, - text = logs, - style = TextStyle( - color = Color.Blue, - fontSize = 18.sp - ) - ) - if (showLoading) { + if (isLoading) { CircularProgressIndicator( - modifier = Modifier.size(size = 64.dp), - strokeWidth = 6.dp + modifier = Modifier.size(size = 30.dp), + strokeWidth = 4.dp ) + } else { + Button( + onClick = { + isOpen = true + }, + modifier = Modifier.padding(start = 16.dp, top = 8.dp, end = 16.dp, bottom = 8.dp) + .fillMaxWidth(0.32f), + ) { + Text( + text = "Choose File", + style = Styles.TextStyleMedium(16.sp), + color = Color.White, + fontWeight = FontWeight.Medium, + ) + } } + Spacer(modifier = Modifier.padding(8.dp)) + TextField( + modifier = Modifier.fillMaxSize().padding(start = 20.dp, end = 20.dp, bottom = 20.dp), + value = logs, + textStyle = Styles.TextStyleMedium(16.sp), + onValueChange = {}, + ) } } } diff --git a/src/jvmMain/kotlin/theme/Styles.kt b/src/jvmMain/kotlin/theme/Styles.kt new file mode 100644 index 0000000..4d61e80 --- /dev/null +++ b/src/jvmMain/kotlin/theme/Styles.kt @@ -0,0 +1,37 @@ +package theme + +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.TextUnit + +object Styles { + + fun TextStyleNormal(size: TextUnit) = + TextStyle( + fontWeight = FontWeight.Normal, + fontFamily = codeFontFamily, + fontSize = size, + ) + + fun TextStyleMedium(size: TextUnit) = + TextStyle( + fontWeight = FontWeight.Medium, + fontFamily = codeFontFamily, + fontSize = size, + ) + + fun TextStyleSemiBold(size: TextUnit) = + TextStyle( + fontWeight = FontWeight.SemiBold, + fontFamily = codeFontFamily, + fontSize = size, + ) + + fun TextStyleBold(size: TextUnit) = + TextStyle( + fontWeight = FontWeight.Bold, + fontFamily = codeFontFamily, + fontSize = size, + ) + +} \ No newline at end of file diff --git a/src/jvmMain/kotlin/theme/Typography.kt b/src/jvmMain/kotlin/theme/Typography.kt new file mode 100644 index 0000000..22249f2 --- /dev/null +++ b/src/jvmMain/kotlin/theme/Typography.kt @@ -0,0 +1,84 @@ +package theme + +import androidx.compose.material.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.platform.Font +import androidx.compose.ui.unit.sp + +val codeFontFamily = FontFamily( + Font(resource = "fonts/sans_regular.ttf", weight = FontWeight.Light), + Font( resource = "fonts/sans_thin.ttf", weight = FontWeight.Normal), + Font( resource = "fonts/sans_medium.ttf", weight = FontWeight.Medium), + Font( resource = "fonts/sans_bold.ttf", weight = FontWeight.Bold) +) + +val typography = Typography( + defaultFontFamily = codeFontFamily, + h1 = TextStyle( + fontWeight = FontWeight.Light, + fontSize = 96.sp, + letterSpacing = (-1.5).sp + ), + h2 = TextStyle( + fontWeight = FontWeight.Light, + fontSize = 60.sp, + letterSpacing = (-0.5).sp + ), + h3 = TextStyle( + fontWeight = FontWeight.Normal, + fontSize = 48.sp, + letterSpacing = 0.sp + ), + h4 = TextStyle( + fontWeight = FontWeight.Normal, + fontSize = 30.sp, + letterSpacing = 0.sp + ), + h5 = TextStyle( + fontWeight = FontWeight.Normal, + fontSize = 24.sp, + letterSpacing = 0.sp + ), + h6 = TextStyle( + fontWeight = FontWeight.Bold, + fontSize = 20.sp, + letterSpacing = 0.sp + ), + subtitle1 = TextStyle( + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + letterSpacing = 0.15.sp + ), + subtitle2 = TextStyle( + fontWeight = FontWeight.Bold, + fontSize = 14.sp, + letterSpacing = 0.1.sp + ), + body1 = TextStyle( + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + letterSpacing = 0.5.sp + ), + body2 = TextStyle( + fontWeight = FontWeight.Normal, + fontSize = 14.sp, + letterSpacing = 0.25.sp + ), + button = TextStyle( + fontWeight = FontWeight.Bold, + fontSize = 14.sp, + letterSpacing = 0.25.sp + ), + caption = TextStyle( + fontWeight = FontWeight.Normal, + fontSize = 12.sp, + letterSpacing = 0.4.sp + ), + overline = TextStyle( + fontWeight = FontWeight.Normal, + fontSize = 10.sp, + letterSpacing = 1.sp + ) +) \ No newline at end of file diff --git a/src/jvmMain/resources/fonts/sans_bold.ttf b/src/jvmMain/resources/fonts/sans_bold.ttf new file mode 100644 index 0000000..8049766 Binary files /dev/null and b/src/jvmMain/resources/fonts/sans_bold.ttf differ diff --git a/src/jvmMain/resources/fonts/sans_medium.ttf b/src/jvmMain/resources/fonts/sans_medium.ttf new file mode 100644 index 0000000..1543660 Binary files /dev/null and b/src/jvmMain/resources/fonts/sans_medium.ttf differ diff --git a/src/jvmMain/resources/fonts/sans_regular.ttf b/src/jvmMain/resources/fonts/sans_regular.ttf new file mode 100644 index 0000000..ab605f9 Binary files /dev/null and b/src/jvmMain/resources/fonts/sans_regular.ttf differ diff --git a/src/jvmMain/resources/fonts/sans_thin.ttf b/src/jvmMain/resources/fonts/sans_thin.ttf new file mode 100644 index 0000000..5e046b5 Binary files /dev/null and b/src/jvmMain/resources/fonts/sans_thin.ttf differ