mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-28 00:44:27 +00:00
desktop: video and audio players (#3052)
* desktop: video and audio players * making player working without preinstalled VLC * mac support * don't use vlc lib when not needed * updated jna version * changes in script * video player lazy loading * mac script changes * updated build gradle for preserving atrributes of file while copying * apply the same file stats on libs to make VLC checker happy * updated script * changes --------- Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
This commit is contained in:
co-authored by
Evgeny Poberezkin
parent
6de0ed4766
commit
2d7655281f
@@ -1,6 +1,5 @@
|
||||
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
|
||||
import java.util.*
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
@@ -22,6 +21,7 @@ kotlin {
|
||||
dependencies {
|
||||
implementation(project(":common"))
|
||||
implementation(compose.desktop.currentOs)
|
||||
implementation("net.java.dev.jna:jna:5.13.0")
|
||||
}
|
||||
}
|
||||
val jvmTest by getting
|
||||
@@ -33,16 +33,23 @@ compose {
|
||||
desktop {
|
||||
application {
|
||||
// For debugging via VisualVM
|
||||
/*jvmArgs += listOf(
|
||||
"-Dcom.sun.management.jmxremote.port=8080",
|
||||
"-Dcom.sun.management.jmxremote.ssl=false",
|
||||
"-Dcom.sun.management.jmxremote.authenticate=false"
|
||||
)*/
|
||||
val debugJava = false
|
||||
if (debugJava) {
|
||||
jvmArgs += listOf(
|
||||
"-Dcom.sun.management.jmxremote.port=8080",
|
||||
"-Dcom.sun.management.jmxremote.ssl=false",
|
||||
"-Dcom.sun.management.jmxremote.authenticate=false"
|
||||
)
|
||||
}
|
||||
mainClass = "chat.simplex.desktop.MainKt"
|
||||
nativeDistributions {
|
||||
// For debugging via VisualVM
|
||||
//modules("jdk.zipfs", "jdk.management.agent")
|
||||
modules("jdk.zipfs")
|
||||
if (debugJava) {
|
||||
modules("jdk.zipfs", "jdk.unsupported", "jdk.management.agent")
|
||||
} else {
|
||||
// 'jdk.unsupported' is for vlcj
|
||||
modules("jdk.zipfs", "jdk.unsupported")
|
||||
}
|
||||
//includeAllModules = true
|
||||
outputBaseDir.set(project.file("../release"))
|
||||
targetFormats(
|
||||
@@ -145,57 +152,119 @@ tasks.named("compileJava") {
|
||||
afterEvaluate {
|
||||
tasks.create("cmakeBuildAndCopy") {
|
||||
dependsOn("cmakeBuild")
|
||||
val copyDetails = mutableMapOf<String, ArrayList<FileCopyDetails>>()
|
||||
copy {
|
||||
from("${project(":desktop").buildDir}/cmake/main/linux-amd64", "$cppPath/desktop/libs/linux-x86_64", "$cppPath/desktop/libs/linux-x86_64/deps")
|
||||
into("src/jvmMain/resources/libs/linux-x86_64")
|
||||
include("*.so*")
|
||||
eachFile {
|
||||
path = name
|
||||
}
|
||||
includeEmptyDirs = false
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
}
|
||||
copy {
|
||||
val destinationDir = "src/jvmMain/resources/libs/linux-x86_64/vlc"
|
||||
from("$cppPath/desktop/libs/linux-x86_64/deps/vlc")
|
||||
into(destinationDir)
|
||||
includeEmptyDirs = false
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
copyIfNeeded(destinationDir, copyDetails)
|
||||
}
|
||||
copy {
|
||||
from("${project(":desktop").buildDir}/cmake/main/linux-aarch64", "$cppPath/desktop/libs/linux-aarch64", "$cppPath/desktop/libs/linux-aarch64/deps")
|
||||
into("src/jvmMain/resources/libs/linux-aarch64")
|
||||
include("*.so*")
|
||||
eachFile {
|
||||
path = name
|
||||
}
|
||||
includeEmptyDirs = false
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
}
|
||||
copy {
|
||||
val destinationDir = "src/jvmMain/resources/libs/linux-aarch64/vlc"
|
||||
from("$cppPath/desktop/libs/linux-aarch64/deps/vlc")
|
||||
into(destinationDir)
|
||||
includeEmptyDirs = false
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
copyIfNeeded(destinationDir, copyDetails)
|
||||
}
|
||||
copy {
|
||||
from("${project(":desktop").buildDir}/cmake/main/win-amd64", "$cppPath/desktop/libs/windows-x86_64", "$cppPath/desktop/libs/windows-x86_64/deps")
|
||||
into("src/jvmMain/resources/libs/windows-x86_64")
|
||||
include("*.dll")
|
||||
eachFile {
|
||||
path = name
|
||||
}
|
||||
includeEmptyDirs = false
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
}
|
||||
copy {
|
||||
val destinationDir = "src/jvmMain/resources/libs/windows-x86_64/vlc"
|
||||
from("$cppPath/desktop/libs/windows-x86_64/deps/vlc")
|
||||
into(destinationDir)
|
||||
includeEmptyDirs = false
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
copyIfNeeded(destinationDir, copyDetails)
|
||||
}
|
||||
copy {
|
||||
from("${project(":desktop").buildDir}/cmake/main/mac-x86_64", "$cppPath/desktop/libs/mac-x86_64", "$cppPath/desktop/libs/mac-x86_64/deps")
|
||||
into("src/jvmMain/resources/libs/mac-x86_64")
|
||||
include("*.dylib")
|
||||
eachFile {
|
||||
path = name
|
||||
}
|
||||
includeEmptyDirs = false
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
}
|
||||
copy {
|
||||
val destinationDir = "src/jvmMain/resources/libs/mac-x86_64/vlc"
|
||||
from("$cppPath/desktop/libs/mac-x86_64/deps/vlc")
|
||||
into(destinationDir)
|
||||
includeEmptyDirs = false
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
copyIfNeeded(destinationDir, copyDetails)
|
||||
}
|
||||
copy {
|
||||
from("${project(":desktop").buildDir}/cmake/main/mac-aarch64", "$cppPath/desktop/libs/mac-aarch64", "$cppPath/desktop/libs/mac-aarch64/deps")
|
||||
into("src/jvmMain/resources/libs/mac-aarch64")
|
||||
include("*.dylib")
|
||||
eachFile {
|
||||
path = name
|
||||
}
|
||||
includeEmptyDirs = false
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
}
|
||||
copy {
|
||||
val destinationDir = "src/jvmMain/resources/libs/mac-aarch64/vlc"
|
||||
from("$cppPath/desktop/libs/mac-aarch64/deps/vlc")
|
||||
into(destinationDir)
|
||||
includeEmptyDirs = false
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
copyIfNeeded(destinationDir, copyDetails)
|
||||
}
|
||||
doLast {
|
||||
copy {
|
||||
from("${project(":desktop").buildDir}/cmake/main/linux-amd64", "$cppPath/desktop/libs/linux-x86_64", "$cppPath/desktop/libs/linux-x86_64/deps")
|
||||
into("src/jvmMain/resources/libs/linux-x86_64")
|
||||
include("*.so*")
|
||||
eachFile {
|
||||
path = name
|
||||
copyDetails.forEach { (destinationDir, details) ->
|
||||
details.forEach { detail ->
|
||||
val target = File(projectDir.absolutePath + File.separator + destinationDir + File.separator + detail.path)
|
||||
if (target.exists()) {
|
||||
target.setLastModified(detail.lastModified)
|
||||
}
|
||||
}
|
||||
includeEmptyDirs = false
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
}
|
||||
copy {
|
||||
from("${project(":desktop").buildDir}/cmake/main/linux-aarch64", "$cppPath/desktop/libs/linux-aarch64", "$cppPath/desktop/libs/linux-aarch64/deps")
|
||||
into("src/jvmMain/resources/libs/linux-aarch64")
|
||||
include("*.so*")
|
||||
eachFile {
|
||||
path = name
|
||||
}
|
||||
includeEmptyDirs = false
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
}
|
||||
copy {
|
||||
from("${project(":desktop").buildDir}/cmake/main/win-amd64", "$cppPath/desktop/libs/windows-x86_64", "$cppPath/desktop/libs/windows-x86_64/deps")
|
||||
into("src/jvmMain/resources/libs/windows-x86_64")
|
||||
include("*.dll")
|
||||
eachFile {
|
||||
path = name
|
||||
}
|
||||
includeEmptyDirs = false
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
}
|
||||
copy {
|
||||
from("${project(":desktop").buildDir}/cmake/main/mac-x86_64", "$cppPath/desktop/libs/mac-x86_64", "$cppPath/desktop/libs/mac-x86_64/deps")
|
||||
into("src/jvmMain/resources/libs/mac-x86_64")
|
||||
include("*.dylib")
|
||||
eachFile {
|
||||
path = name
|
||||
}
|
||||
includeEmptyDirs = false
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
}
|
||||
copy {
|
||||
from("${project(":desktop").buildDir}/cmake/main/mac-aarch64", "$cppPath/desktop/libs/mac-aarch64", "$cppPath/desktop/libs/mac-aarch64/deps")
|
||||
into("src/jvmMain/resources/libs/mac-aarch64")
|
||||
include("*.dylib")
|
||||
eachFile {
|
||||
path = name
|
||||
}
|
||||
includeEmptyDirs = false
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun CopySpec.copyIfNeeded(destinationDir: String, into: MutableMap<String, ArrayList<FileCopyDetails>>) {
|
||||
val details = arrayListOf<FileCopyDetails>()
|
||||
eachFile {
|
||||
val targetFile = File(destinationDir, path)
|
||||
if (file.lastModified() == targetFile.lastModified() && file.length() == targetFile.length()) {
|
||||
exclude()
|
||||
} else {
|
||||
details.add(this)
|
||||
}
|
||||
}
|
||||
into[destinationDir] = details
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import chat.simplex.common.showApp
|
||||
import java.io.File
|
||||
import java.nio.file.*
|
||||
import java.nio.file.attribute.BasicFileAttributes
|
||||
import java.nio.file.attribute.FileTime
|
||||
import kotlin.io.path.setLastModifiedTime
|
||||
|
||||
fun main() {
|
||||
initHaskell()
|
||||
@@ -20,6 +22,15 @@ private fun initHaskell() {
|
||||
val libsTmpDir = File(tmpDir.absolutePath + File.separator + "libs")
|
||||
copyResources(desktopPlatform.libPath, libsTmpDir.toPath())
|
||||
System.load(File(libsTmpDir, libApp).absolutePath)
|
||||
|
||||
vlcDir.deleteRecursively()
|
||||
Files.move(File(libsTmpDir, "vlc").toPath(), vlcDir.toPath(), StandardCopyOption.REPLACE_EXISTING)
|
||||
// No picture without preloading it, only sound. However, with libs from AppImage it works without preloading
|
||||
//val libXcb = "libvlc_xcb_events.so.0.0.0"
|
||||
//System.load(File(File(vlcDir, "vlc"), libXcb).absolutePath)
|
||||
System.setProperty("jna.library.path", vlcDir.absolutePath)
|
||||
//discoverVlcLibs(File(File(vlcDir, "vlc"), "plugins").absolutePath)
|
||||
|
||||
libsTmpDir.deleteRecursively()
|
||||
initHS()
|
||||
}
|
||||
@@ -34,7 +45,12 @@ private fun copyResources(from: String, to: Path) {
|
||||
return FileVisitResult.CONTINUE
|
||||
}
|
||||
override fun visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult {
|
||||
Files.copy(file, to.resolve(resPath.relativize(file).toString()), StandardCopyOption.REPLACE_EXISTING)
|
||||
val dest = to.resolve(resPath.relativize(file).toString())
|
||||
Files.copy(file, dest, StandardCopyOption.REPLACE_EXISTING)
|
||||
// Setting the same time on file as the time set in script that generates VLC libs
|
||||
if (dest.toString().contains("." + desktopPlatform.libExtension)) {
|
||||
dest.setLastModifiedTime(FileTime.fromMillis(0))
|
||||
}
|
||||
return FileVisitResult.CONTINUE
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user