fix: Unable to read text from a file on Desktop
This commit is contained in:
parent
1e6b20268f
commit
992ce89bea
|
@ -3,8 +3,9 @@ package com.artemchep.keyguard.copy
|
|||
import com.artemchep.keyguard.common.service.text.TextService
|
||||
import dev.icerock.moko.resources.FileResource
|
||||
import org.kodein.di.DirectDI
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import kotlin.io.path.Path
|
||||
import java.net.URI
|
||||
|
||||
class TextServiceJvm() : TextService {
|
||||
constructor(
|
||||
|
@ -19,14 +20,14 @@ class TextServiceJvm() : TextService {
|
|||
.getResourceAsStream(filePath)!!
|
||||
|
||||
override fun readFromFile(uri: String): InputStream {
|
||||
when {
|
||||
uri.startsWith("file://") -> {
|
||||
return Path(uri)
|
||||
.toFile()
|
||||
.inputStream()
|
||||
val parsedUri = URI.create(uri)
|
||||
return when (parsedUri.scheme) {
|
||||
"file" -> {
|
||||
val file = parsedUri.path.let(::File)
|
||||
file.inputStream()
|
||||
}
|
||||
else -> {
|
||||
throw IllegalStateException("Unsupported URI protocol.")
|
||||
throw IllegalStateException("Unsupported URI protocol, could not read '$uri'.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,4 +12,4 @@ data class LeUriImpl(
|
|||
|
||||
actual fun leParseUri(uri: String): LeUri = LeUriImpl(uri)
|
||||
|
||||
actual fun leParseUri(file: File): LeUri = LeUriImpl(file.toPath().toString())
|
||||
actual fun leParseUri(file: File): LeUri = LeUriImpl(file.toURI().toString())
|
||||
|
|
Loading…
Reference in New Issue