forked from recloudstream/cloudstream
Faster startup and fix bug removing plugins
This commit is contained in:
parent
e45246f834
commit
d91446c654
3 changed files with 39 additions and 34 deletions
|
@ -424,16 +424,19 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
app.initClient(this)
|
app.initClient(this)
|
||||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
|
|
||||||
|
|
||||||
if (settingsManager.getBoolean(getString(R.string.auto_update_plugins_key), true)) {
|
// Parallelize to speed up startup
|
||||||
PluginManager.updateAllOnlinePluginsAndLoadThem(this)
|
ioSafe {
|
||||||
} else {
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this@MainActivity)
|
||||||
PluginManager.loadAllOnlinePlugins(this)
|
if (settingsManager.getBoolean(getString(R.string.auto_update_plugins_key), true)) {
|
||||||
|
PluginManager.updateAllOnlinePluginsAndLoadThem(this@MainActivity)
|
||||||
|
} else {
|
||||||
|
PluginManager.loadAllOnlinePlugins(this@MainActivity)
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginManager.loadAllLocalPlugins(this@MainActivity)
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginManager.loadAllLocalPlugins(this)
|
|
||||||
|
|
||||||
// ioSafe {
|
// ioSafe {
|
||||||
// val plugins =
|
// val plugins =
|
||||||
// RepositoryParser.getRepoPlugins("https://raw.githubusercontent.com/recloudstream/TestPlugin/master/repo.json")
|
// RepositoryParser.getRepoPlugins("https://raw.githubusercontent.com/recloudstream/TestPlugin/master/repo.json")
|
||||||
|
@ -445,8 +448,10 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// init accounts
|
// init accounts
|
||||||
for (api in accountManagers) {
|
ioSafe {
|
||||||
api.init()
|
for (api in accountManagers) {
|
||||||
|
api.init()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ioSafe {
|
ioSafe {
|
||||||
|
@ -461,28 +466,28 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
|
|
||||||
SearchResultBuilder.updateCache(this)
|
SearchResultBuilder.updateCache(this)
|
||||||
|
|
||||||
|
ioSafe {
|
||||||
initAll()
|
initAll()
|
||||||
apis = allProviders
|
|
||||||
|
|
||||||
try {
|
|
||||||
getKey<Array<SettingsGeneral.CustomSite>>(USER_PROVIDER_API)?.let { list ->
|
|
||||||
list.forEach { custom ->
|
|
||||||
allProviders.firstOrNull { it.javaClass.simpleName == custom.parentJavaClass }
|
|
||||||
?.let {
|
|
||||||
allProviders.add(it.javaClass.newInstance().apply {
|
|
||||||
name = custom.name
|
|
||||||
lang = custom.lang
|
|
||||||
mainUrl = custom.url.trimEnd('/')
|
|
||||||
canBeOverridden = false
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
apis = allProviders
|
apis = allProviders
|
||||||
APIHolder.apiMap = null
|
try {
|
||||||
} catch (e: Exception) {
|
getKey<Array<SettingsGeneral.CustomSite>>(USER_PROVIDER_API)?.let { list ->
|
||||||
logError(e)
|
list.forEach { custom ->
|
||||||
|
allProviders.firstOrNull { it.javaClass.simpleName == custom.parentJavaClass }
|
||||||
|
?.let {
|
||||||
|
allProviders.add(it.javaClass.newInstance().apply {
|
||||||
|
name = custom.name
|
||||||
|
lang = custom.lang
|
||||||
|
mainUrl = custom.url.trimEnd('/')
|
||||||
|
canBeOverridden = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
apis = allProviders
|
||||||
|
APIHolder.apiMap = null
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logError(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadThemes(this)
|
loadThemes(this)
|
||||||
|
@ -653,7 +658,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
|
|
||||||
handleAppIntent(intent)
|
handleAppIntent(intent)
|
||||||
|
|
||||||
thread {
|
ioSafe {
|
||||||
runAutoUpdate()
|
runAutoUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -235,7 +235,7 @@ object PluginManager {
|
||||||
val sortedPlugins = dir.listFiles()
|
val sortedPlugins = dir.listFiles()
|
||||||
// Always sort plugins alphabetically for reproducible results
|
// Always sort plugins alphabetically for reproducible results
|
||||||
|
|
||||||
Log.d(TAG, "Files in '${LOCAL_PLUGINS_PATH}' folder: ${sortedPlugins}")
|
Log.d(TAG, "Files in '${LOCAL_PLUGINS_PATH}' folder: $sortedPlugins")
|
||||||
|
|
||||||
sortedPlugins?.sortedBy { it.name }?.apmap { file ->
|
sortedPlugins?.sortedBy { it.name }?.apmap { file ->
|
||||||
maybeLoadPlugin(activity, file)
|
maybeLoadPlugin(activity, file)
|
||||||
|
@ -376,7 +376,7 @@ object PluginManager {
|
||||||
* */
|
* */
|
||||||
suspend fun deletePlugin(pluginIdentifier: String, isFilePath: Boolean): Boolean {
|
suspend fun deletePlugin(pluginIdentifier: String, isFilePath: Boolean): Boolean {
|
||||||
val data =
|
val data =
|
||||||
(if (isFilePath) getPluginsLocal().firstOrNull { it.filePath == pluginIdentifier }
|
(if (isFilePath) (getPluginsLocal() + getPluginsOnline()).firstOrNull { it.filePath == pluginIdentifier }
|
||||||
else getPluginsOnline().firstOrNull { it.url == pluginIdentifier }) ?: return false
|
else getPluginsOnline().firstOrNull { it.url == pluginIdentifier }) ?: return false
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
|
|
|
@ -128,7 +128,7 @@ class PluginsViewModel : ViewModel() {
|
||||||
plugin: Plugin,
|
plugin: Plugin,
|
||||||
isLocal: Boolean
|
isLocal: Boolean
|
||||||
) = ioSafe {
|
) = ioSafe {
|
||||||
Log.i(TAG, "handlePluginAction = $repositoryUrl, $plugin")
|
Log.i(TAG, "handlePluginAction = $repositoryUrl, $plugin, $isLocal")
|
||||||
|
|
||||||
if (activity == null) return@ioSafe
|
if (activity == null) return@ioSafe
|
||||||
val (repo, metadata) = plugin
|
val (repo, metadata) = plugin
|
||||||
|
|
Loading…
Reference in a new issue