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 com.artemchep.keyguard.common.service.text.TextService
|
||||||
import dev.icerock.moko.resources.FileResource
|
import dev.icerock.moko.resources.FileResource
|
||||||
import org.kodein.di.DirectDI
|
import org.kodein.di.DirectDI
|
||||||
|
import java.io.File
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import kotlin.io.path.Path
|
import java.net.URI
|
||||||
|
|
||||||
class TextServiceJvm() : TextService {
|
class TextServiceJvm() : TextService {
|
||||||
constructor(
|
constructor(
|
||||||
@ -19,14 +20,14 @@ class TextServiceJvm() : TextService {
|
|||||||
.getResourceAsStream(filePath)!!
|
.getResourceAsStream(filePath)!!
|
||||||
|
|
||||||
override fun readFromFile(uri: String): InputStream {
|
override fun readFromFile(uri: String): InputStream {
|
||||||
when {
|
val parsedUri = URI.create(uri)
|
||||||
uri.startsWith("file://") -> {
|
return when (parsedUri.scheme) {
|
||||||
return Path(uri)
|
"file" -> {
|
||||||
.toFile()
|
val file = parsedUri.path.let(::File)
|
||||||
.inputStream()
|
file.inputStream()
|
||||||
}
|
}
|
||||||
else -> {
|
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(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…
x
Reference in New Issue
Block a user