mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-10 06:42:05 +01:00
Copy Tachidesk Server to user folder from resources to run from
This commit is contained in:
@@ -42,6 +42,9 @@ dependencies {
|
||||
//implementation("org.fusesource.jansi:jansi:1.18")
|
||||
implementation("io.github.microutils:kotlin-logging:2.0.5")
|
||||
|
||||
// User storage
|
||||
implementation("net.harawata:appdirs:1.2.1")
|
||||
|
||||
// Preferences
|
||||
val multiplatformSettingsVersion = "0.7.4"
|
||||
implementation("com.russhwolf:multiplatform-settings-jvm:$multiplatformSettingsVersion")
|
||||
|
||||
@@ -22,18 +22,31 @@ import ca.gosyer.ui.extensions.openExtensionsMenu
|
||||
import ca.gosyer.ui.library.openLibraryMenu
|
||||
import ca.gosyer.ui.sources.openSourcesMenu
|
||||
import ca.gosyer.util.compose.ThemedWindow
|
||||
import ca.gosyer.util.system.userDataDir
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import mu.KotlinLogging
|
||||
import org.koin.core.context.startKoin
|
||||
import kotlin.concurrent.thread
|
||||
import java.io.File
|
||||
|
||||
fun main() {
|
||||
GlobalScope.launch {
|
||||
val logger = KotlinLogging.logger("Server")
|
||||
val runtime = Runtime.getRuntime()
|
||||
|
||||
val process = runtime.exec("java -jar resources/Tachidesk.jar")
|
||||
val jarFile = File(userDataDir,"Tachidesk.jar")
|
||||
if (!jarFile.exists()) {
|
||||
logger.info { "Copying server to resources" }
|
||||
javaClass.getResourceAsStream("/Tachidesk.jar").buffered().use { input ->
|
||||
jarFile.outputStream().use { output ->
|
||||
input.copyTo(output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.info { "Starting server" }
|
||||
val process = runtime.exec("""java -jar "${jarFile.absolutePath}"""")
|
||||
runtime.addShutdownHook(thread(start = false) {
|
||||
process?.destroy()
|
||||
})
|
||||
|
||||
21
src/main/kotlin/ca/gosyer/util/system/File.kt
Normal file
21
src/main/kotlin/ca/gosyer/util/system/File.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package ca.gosyer.util.system
|
||||
|
||||
import net.harawata.appdirs.AppDirs
|
||||
import net.harawata.appdirs.AppDirsFactory
|
||||
import java.io.File
|
||||
|
||||
val appDirs: AppDirs by lazy {
|
||||
AppDirsFactory.getInstance()
|
||||
}
|
||||
|
||||
val userDataDir: File by lazy {
|
||||
File(appDirs.getUserDataDir("TachideskJUI", null, null)).also {
|
||||
if (!it.exists()) it.mkdirs()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user