Skip to content

Commit

Permalink
feat: Copy scripts and script-opts from Aniyomi directory
Browse files Browse the repository at this point in the history
  • Loading branch information
jmir1 committed Jan 31, 2024
1 parent 4295669 commit 8979594
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
31 changes: 31 additions & 0 deletions app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,8 @@ class PlayerActivity : BaseActivity() {
val mpvInputFile = File("${applicationContext.filesDir.path}/input.conf")
playerPreferences.mpvInput().get().let { mpvInputFile.writeText(it) }

copyScripts()

val logLevel = if (viewModel.networkPreferences.verboseLogging().get()) "info" else "warn"
val vo = if (playerPreferences.gpuNext().get()) "gpu-next" else "gpu"
player.initialize(
Expand Down Expand Up @@ -675,6 +677,35 @@ class PlayerActivity : BaseActivity() {
}
}

private fun copyScripts() {
CoroutineScope(Dispatchers.IO).launchIO {
// First, delete all present scripts
val scriptsDir = {
UniFile.fromFile(applicationContext.filesDir)?.createDirectory("scripts")
}
val scriptOptsDir = {
UniFile.fromFile(applicationContext.filesDir)?.createDirectory("script-opts")
}
scriptsDir()?.delete()
scriptOptsDir()?.delete()

// Then, copy the scripts from the Aniyomi directory
val storageManager: StorageManager = Injekt.get()
storageManager.getScriptsDirectory()?.listFiles()?.forEach { file ->
val outFile = scriptsDir()?.createFile(file.name)
outFile?.let {
file.openInputStream().copyTo(it.openOutputStream())
}
}
storageManager.getScriptOptsDirectory()?.listFiles()?.forEach { file ->
val outFile = scriptOptsDir()?.createFile(file.name)
outFile?.let {
file.openInputStream().copyTo(it.openOutputStream())
}
}
}
}

private fun setupPlayerBrightness() {
val useDeviceBrightness =
playerPreferences.playerBrightnessValue().get() == -1.0F ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class PlayerObserver(val activity: PlayerActivity) :
MPVLib.mpvLogLevel.MPV_LOG_LEVEL_FATAL, MPVLib.mpvLogLevel.MPV_LOG_LEVEL_ERROR -> LogPriority.ERROR
MPVLib.mpvLogLevel.MPV_LOG_LEVEL_WARN -> LogPriority.WARN
MPVLib.mpvLogLevel.MPV_LOG_LEVEL_INFO -> LogPriority.INFO
else -> null
else -> LogPriority.VERBOSE
}
if (logPriority != null) {
if (text.contains("HTTP error")) httpError = text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,20 @@ class StorageManager(
fun getFontsDirectory(): UniFile? {
return baseDir?.createDirectory(FONTS_PATH)
}

fun getScriptsDirectory(): UniFile? {
return baseDir?.createDirectory(SCRIPTS_PATH)
}

fun getScriptOptsDirectory(): UniFile? {
return baseDir?.createDirectory(SCRIPT_OPTS_PATH)
}
}

private const val AUTOMATIC_BACKUPS_PATH = "autobackup"
private const val DOWNLOADS_PATH = "downloads"
private const val LOCAL_SOURCE_PATH = "local"
private const val LOCAL_ANIMESOURCE_PATH = "localanime"
private const val FONTS_PATH = "fonts"
private const val SCRIPTS_PATH = "scripts"
private const val SCRIPT_OPTS_PATH = "script-opts"

0 comments on commit 8979594

Please sign in to comment.