Skip to content

Commit

Permalink
Update FileSaverLauncher
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedRejeb committed Jul 16, 2024
1 parent d6a63fb commit a06132d
Showing 1 changed file with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,20 @@ import kotlinx.coroutines.launch

@Composable
fun rememberFileSaverLauncher(
bytes: ByteArray?,
baseName: String,
extension: String,
initialDirectory: String?,
onResult: (KmpFile?) -> Unit,
): FileSaverLauncher {
val scope = rememberCoroutineScope()

val currentBytes by rememberUpdatedState(bytes)
val currentBaseName by rememberUpdatedState(baseName)
val currentExtension by rememberUpdatedState(extension)
val currentInitialDirectory by rememberUpdatedState(initialDirectory)
val currentOnResult by rememberUpdatedState(onResult)

return FileSaverLauncher(
onLaunch = {
onLaunch = { bytes, baseName, extension, initialDirectory ->
scope.launch {
val file = AwtFileSaver.saveFile(
bytes = currentBytes,
baseName = currentBaseName,
extension = currentExtension,
initialDirectory = currentInitialDirectory,
bytes = bytes,
baseName = baseName,
extension = extension,
initialDirectory = initialDirectory,
parentWindow = null,
)

Expand All @@ -42,9 +34,24 @@ fun rememberFileSaverLauncher(
}

class FileSaverLauncher(
private val onLaunch: () -> Unit,
private val onLaunch: (
bytes: ByteArray?,
baseName: String,
extension: String,
initialDirectory: String?,
) -> Unit,
) {
fun launch() {
onLaunch()
fun launch(
bytes: ByteArray?,
baseName: String,
extension: String,
initialDirectory: String?,
) {
onLaunch(
bytes,
baseName,
extension,
initialDirectory,
)
}
}

0 comments on commit a06132d

Please sign in to comment.