mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Fixed internal plugin manager to fix name conflicts
This commit is contained in:
parent
fbbcdb4889
commit
fb248b6192
3 changed files with 42 additions and 27 deletions
|
@ -174,8 +174,12 @@ object PluginManager {
|
||||||
val onlineData: Pair<String, SitePlugin>,
|
val onlineData: Pair<String, SitePlugin>,
|
||||||
) {
|
) {
|
||||||
val isOutdated =
|
val isOutdated =
|
||||||
onlineData.second.version != savedData.version || onlineData.second.version == PLUGIN_VERSION_ALWAYS_UPDATE
|
onlineData.second.version > savedData.version || onlineData.second.version == PLUGIN_VERSION_ALWAYS_UPDATE
|
||||||
val isDisabled = onlineData.second.status == PROVIDER_STATUS_DOWN
|
val isDisabled = onlineData.second.status == PROVIDER_STATUS_DOWN
|
||||||
|
|
||||||
|
fun validOnlineData(context: Context): Boolean {
|
||||||
|
return getPluginPath(context, savedData.internalName, onlineData.first).absolutePath == savedData.filePath
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// var allCurrentOutDatedPlugins: Set<OnlinePluginData> = emptySet()
|
// var allCurrentOutDatedPlugins: Set<OnlinePluginData> = emptySet()
|
||||||
|
@ -225,6 +229,8 @@ object PluginManager {
|
||||||
.filter { onlineData -> savedData.internalName == onlineData.second.internalName }
|
.filter { onlineData -> savedData.internalName == onlineData.second.internalName }
|
||||||
.map { onlineData ->
|
.map { onlineData ->
|
||||||
OnlinePluginData(savedData, onlineData)
|
OnlinePluginData(savedData, onlineData)
|
||||||
|
}.filter {
|
||||||
|
it.validOnlineData(activity)
|
||||||
}
|
}
|
||||||
}.flatten().distinctBy { it.onlineData.second.url }
|
}.flatten().distinctBy { it.onlineData.second.url }
|
||||||
|
|
||||||
|
@ -416,6 +422,18 @@ object PluginManager {
|
||||||
) + "." + name.hashCode()
|
) + "." + name.hashCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This should not be changed as it is used to also detect if a plugin is installed!
|
||||||
|
**/
|
||||||
|
fun getPluginPath(
|
||||||
|
context: Context,
|
||||||
|
internalName: String,
|
||||||
|
repositoryUrl: String
|
||||||
|
): File {
|
||||||
|
val folderName = getPluginSanitizedFileName(repositoryUrl) // Guaranteed unique
|
||||||
|
val fileName = getPluginSanitizedFileName(internalName)
|
||||||
|
return File("${context.filesDir}/${ONLINE_PLUGINS_FOLDER}/${folderName}/$fileName.cs3")
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used for fresh installs
|
* Used for fresh installs
|
||||||
|
@ -426,9 +444,7 @@ object PluginManager {
|
||||||
internalName: String,
|
internalName: String,
|
||||||
repositoryUrl: String
|
repositoryUrl: String
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val folderName = getPluginSanitizedFileName(repositoryUrl) // Guaranteed unique
|
val file = getPluginPath(activity, internalName, repositoryUrl)
|
||||||
val fileName = getPluginSanitizedFileName(internalName)
|
|
||||||
val file = File("${activity.filesDir}/${ONLINE_PLUGINS_FOLDER}/${folderName}/$fileName.cs3")
|
|
||||||
downloadAndLoadPlugin(activity, pluginUrl, internalName, file)
|
downloadAndLoadPlugin(activity, pluginUrl, internalName, file)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -454,7 +470,13 @@ object PluginManager {
|
||||||
return loadPlugin(
|
return loadPlugin(
|
||||||
activity,
|
activity,
|
||||||
newFile ?: return false,
|
newFile ?: return false,
|
||||||
PluginData(internalName, pluginUrl, true, newFile.absolutePath, PLUGIN_VERSION_NOT_SET)
|
PluginData(
|
||||||
|
internalName,
|
||||||
|
pluginUrl,
|
||||||
|
true,
|
||||||
|
newFile.absolutePath,
|
||||||
|
PLUGIN_VERSION_NOT_SET
|
||||||
|
)
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logError(e)
|
logError(e)
|
||||||
|
|
|
@ -147,7 +147,7 @@ class PluginsFragment : Fragment() {
|
||||||
pluginViewModel.updatePluginListLocal()
|
pluginViewModel.updatePluginListLocal()
|
||||||
tv_types_scroll_view?.isVisible = false
|
tv_types_scroll_view?.isVisible = false
|
||||||
} else {
|
} else {
|
||||||
pluginViewModel.updatePluginList(url)
|
pluginViewModel.updatePluginList(context, url)
|
||||||
tv_types_scroll_view?.isVisible = true
|
tv_types_scroll_view?.isVisible = true
|
||||||
|
|
||||||
// 💀💀💀💀💀💀💀 Recyclerview when
|
// 💀💀💀💀💀💀💀 Recyclerview when
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.lagradost.cloudstream3.ui.settings.extensions
|
package com.lagradost.cloudstream3.ui.settings.extensions
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import android.content.Context
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
|
@ -13,6 +14,7 @@ import com.lagradost.cloudstream3.apmap
|
||||||
import com.lagradost.cloudstream3.mvvm.launchSafe
|
import com.lagradost.cloudstream3.mvvm.launchSafe
|
||||||
import com.lagradost.cloudstream3.plugins.PluginData
|
import com.lagradost.cloudstream3.plugins.PluginData
|
||||||
import com.lagradost.cloudstream3.plugins.PluginManager
|
import com.lagradost.cloudstream3.plugins.PluginManager
|
||||||
|
import com.lagradost.cloudstream3.plugins.PluginManager.getPluginPath
|
||||||
import com.lagradost.cloudstream3.plugins.RepositoryManager
|
import com.lagradost.cloudstream3.plugins.RepositoryManager
|
||||||
import com.lagradost.cloudstream3.plugins.SitePlugin
|
import com.lagradost.cloudstream3.plugins.SitePlugin
|
||||||
import com.lagradost.cloudstream3.ui.result.txt
|
import com.lagradost.cloudstream3.ui.result.txt
|
||||||
|
@ -45,8 +47,8 @@ class PluginsViewModel : ViewModel() {
|
||||||
private val repositoryCache: MutableMap<String, List<Plugin>> = mutableMapOf()
|
private val repositoryCache: MutableMap<String, List<Plugin>> = mutableMapOf()
|
||||||
const val TAG = "PLG"
|
const val TAG = "PLG"
|
||||||
|
|
||||||
private fun isDownloaded(plugin: Plugin, data: Set<String>? = null): Boolean {
|
private fun isDownloaded(context: Context, pluginName: String, repositoryUrl: String): Boolean {
|
||||||
return (data ?: getDownloads()).contains(plugin.second.internalName)
|
return getPluginPath(context, pluginName, repositoryUrl).exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun getPlugins(
|
private suspend fun getPlugins(
|
||||||
|
@ -63,24 +65,15 @@ class PluginsViewModel : ViewModel() {
|
||||||
?.also { repositoryCache[repositoryUrl] = it } ?: emptyList()
|
?.also { repositoryCache[repositoryUrl] = it } ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getStoredPlugins(): Array<PluginData> {
|
|
||||||
return PluginManager.getPluginsOnline()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getDownloads(): Set<String> {
|
|
||||||
return getStoredPlugins().map { it.internalName }.toSet()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param viewModel optional, updates the plugins livedata for that viewModel if included
|
* @param viewModel optional, updates the plugins livedata for that viewModel if included
|
||||||
* */
|
* */
|
||||||
fun downloadAll(activity: Activity?, repositoryUrl: String, viewModel: PluginsViewModel?) =
|
fun downloadAll(activity: Activity?, repositoryUrl: String, viewModel: PluginsViewModel?) =
|
||||||
ioSafe {
|
ioSafe {
|
||||||
if (activity == null) return@ioSafe
|
if (activity == null) return@ioSafe
|
||||||
val stored = getDownloads()
|
|
||||||
val plugins = getPlugins(repositoryUrl)
|
val plugins = getPlugins(repositoryUrl)
|
||||||
|
|
||||||
plugins.filter { plugin -> !isDownloaded(plugin, stored) }.also { list ->
|
plugins.filter { plugin -> !isDownloaded(activity, plugin.second.internalName, repositoryUrl) }.also { list ->
|
||||||
main {
|
main {
|
||||||
showToast(
|
showToast(
|
||||||
activity,
|
activity,
|
||||||
|
@ -103,7 +96,7 @@ class PluginsViewModel : ViewModel() {
|
||||||
PluginManager.downloadAndLoadPlugin(
|
PluginManager.downloadAndLoadPlugin(
|
||||||
activity,
|
activity,
|
||||||
metadata.url,
|
metadata.url,
|
||||||
metadata.name,
|
metadata.internalName,
|
||||||
repo
|
repo
|
||||||
)
|
)
|
||||||
}.main { list ->
|
}.main { list ->
|
||||||
|
@ -117,7 +110,7 @@ class PluginsViewModel : ViewModel() {
|
||||||
),
|
),
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
)
|
)
|
||||||
viewModel?.updatePluginListPrivate(repositoryUrl)
|
viewModel?.updatePluginListPrivate(activity, repositoryUrl)
|
||||||
} else if (list.isNotEmpty()) {
|
} else if (list.isNotEmpty()) {
|
||||||
showToast(activity, R.string.download_failed, Toast.LENGTH_SHORT)
|
showToast(activity, R.string.download_failed, Toast.LENGTH_SHORT)
|
||||||
}
|
}
|
||||||
|
@ -140,7 +133,7 @@ class PluginsViewModel : ViewModel() {
|
||||||
if (activity == null) return@ioSafe
|
if (activity == null) return@ioSafe
|
||||||
val (repo, metadata) = plugin
|
val (repo, metadata) = plugin
|
||||||
|
|
||||||
val (success, message) = if (isDownloaded(plugin) || isLocal) {
|
val (success, message) = if (isDownloaded(activity, plugin.second.internalName, plugin.first) || isLocal) {
|
||||||
PluginManager.deletePlugin(
|
PluginManager.deletePlugin(
|
||||||
metadata.url,
|
metadata.url,
|
||||||
isLocal
|
isLocal
|
||||||
|
@ -165,14 +158,13 @@ class PluginsViewModel : ViewModel() {
|
||||||
if (isLocal)
|
if (isLocal)
|
||||||
updatePluginListLocal()
|
updatePluginListLocal()
|
||||||
else
|
else
|
||||||
updatePluginListPrivate(repositoryUrl)
|
updatePluginListPrivate(activity, repositoryUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun updatePluginListPrivate(repositoryUrl: String) {
|
private suspend fun updatePluginListPrivate(context: Context, repositoryUrl: String) {
|
||||||
val stored = getDownloads()
|
|
||||||
val plugins = getPlugins(repositoryUrl)
|
val plugins = getPlugins(repositoryUrl)
|
||||||
val list = plugins.map { plugin ->
|
val list = plugins.map { plugin ->
|
||||||
PluginViewData(plugin, isDownloaded(plugin, stored))
|
PluginViewData(plugin, isDownloaded(context, plugin.second.internalName, plugin.first))
|
||||||
}
|
}
|
||||||
|
|
||||||
this.plugins = list
|
this.plugins = list
|
||||||
|
@ -211,9 +203,10 @@ class PluginsViewModel : ViewModel() {
|
||||||
_filteredPlugins.postValue(false to plugins.filterTvTypes().filterLang().sortByQuery(currentQuery))
|
_filteredPlugins.postValue(false to plugins.filterTvTypes().filterLang().sortByQuery(currentQuery))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updatePluginList(repositoryUrl: String) = viewModelScope.launchSafe {
|
fun updatePluginList(context: Context?, repositoryUrl: String) = viewModelScope.launchSafe {
|
||||||
|
if (context == null) return@launchSafe
|
||||||
Log.i(TAG, "updatePluginList = $repositoryUrl")
|
Log.i(TAG, "updatePluginList = $repositoryUrl")
|
||||||
updatePluginListPrivate(repositoryUrl)
|
updatePluginListPrivate(context, repositoryUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun search(query: String?) {
|
fun search(query: String?) {
|
||||||
|
|
Loading…
Reference in a new issue