Faster startup and fix bug removing plugins

This commit is contained in:
Blatzar 2022-08-14 18:09:19 +02:00
parent e45246f834
commit d91446c654
3 changed files with 39 additions and 34 deletions

View file

@ -424,15 +424,18 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
override fun onCreate(savedInstanceState: Bundle?) {
app.initClient(this)
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
// Parallelize to speed up startup
ioSafe {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this@MainActivity)
if (settingsManager.getBoolean(getString(R.string.auto_update_plugins_key), true)) {
PluginManager.updateAllOnlinePluginsAndLoadThem(this)
PluginManager.updateAllOnlinePluginsAndLoadThem(this@MainActivity)
} else {
PluginManager.loadAllOnlinePlugins(this)
PluginManager.loadAllOnlinePlugins(this@MainActivity)
}
PluginManager.loadAllLocalPlugins(this)
PluginManager.loadAllLocalPlugins(this@MainActivity)
}
// ioSafe {
// val plugins =
@ -445,9 +448,11 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
// }
// init accounts
ioSafe {
for (api in accountManagers) {
api.init()
}
}
ioSafe {
inAppAuths.apmap { api ->
@ -461,10 +466,9 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
SearchResultBuilder.updateCache(this)
ioSafe {
initAll()
apis = allProviders
try {
getKey<Array<SettingsGeneral.CustomSite>>(USER_PROVIDER_API)?.let { list ->
list.forEach { custom ->
@ -484,6 +488,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
} catch (e: Exception) {
logError(e)
}
}
loadThemes(this)
updateLocale()
@ -653,7 +658,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
handleAppIntent(intent)
thread {
ioSafe {
runAutoUpdate()
}

View file

@ -235,7 +235,7 @@ object PluginManager {
val sortedPlugins = dir.listFiles()
// 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 ->
maybeLoadPlugin(activity, file)
@ -376,7 +376,7 @@ object PluginManager {
* */
suspend fun deletePlugin(pluginIdentifier: String, isFilePath: Boolean): Boolean {
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
return try {

View file

@ -128,7 +128,7 @@ class PluginsViewModel : ViewModel() {
plugin: Plugin,
isLocal: Boolean
) = ioSafe {
Log.i(TAG, "handlePluginAction = $repositoryUrl, $plugin")
Log.i(TAG, "handlePluginAction = $repositoryUrl, $plugin, $isLocal")
if (activity == null) return@ioSafe
val (repo, metadata) = plugin