Add file plugin settings screens
This commit is contained in:
@@ -361,7 +361,7 @@ internal class PluginFileDeserializer(
|
||||
val id = obj.getString("id")
|
||||
val plugin = pluginRepository.get(authority).firstOrNull() ?: return null
|
||||
if (!plugin.enabled) return null
|
||||
val provider = PluginFileProvider(context, plugin)
|
||||
val provider = PluginFileProvider(context, authority)
|
||||
return provider.getFile(id)
|
||||
} catch (e: Exception) {
|
||||
CrashReporter.logException(e)
|
||||
|
||||
@@ -53,9 +53,7 @@ internal class FileRepository(
|
||||
enabled = true,
|
||||
)
|
||||
|
||||
settings.data.combine(filePlugins) { settings, plugins ->
|
||||
settings to plugins
|
||||
}.collectLatest { (settings, plugins) ->
|
||||
settings.data.collectLatest { settings ->
|
||||
val providers = mutableListOf<FileProvider>()
|
||||
|
||||
if (settings.localFiles) providers.add(
|
||||
@@ -68,7 +66,7 @@ internal class FileRepository(
|
||||
if (settings.nextcloudFiles) providers.add(NextcloudFileProvider(nextcloudClient))
|
||||
if (settings.owncloudFiles) providers.add(OwncloudFileProvider(owncloudClient))
|
||||
|
||||
for (plugin in plugins) {
|
||||
for (plugin in settings.plugins) {
|
||||
providers.add(PluginFileProvider(context, plugin))
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,12 @@ import kotlin.coroutines.resume
|
||||
|
||||
class PluginFileProvider(
|
||||
private val context: Context,
|
||||
private val plugin: Plugin,
|
||||
private val pluginAuthority: String,
|
||||
) : FileProvider {
|
||||
override suspend fun search(query: String): List<File> {
|
||||
val uri = Uri.Builder()
|
||||
.scheme("content")
|
||||
.authority(plugin.authority)
|
||||
.authority(pluginAuthority)
|
||||
.path(SearchPluginContract.Paths.Search)
|
||||
.appendQueryParameter(SearchPluginContract.Paths.QueryParam, query)
|
||||
.build()
|
||||
@@ -43,14 +43,14 @@ class PluginFileProvider(
|
||||
cancellationSignal
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
Log.e("MM20", "Plugin ${plugin.authority} threw exception")
|
||||
Log.e("MM20", "Plugin ${pluginAuthority} threw exception")
|
||||
CrashReporter.logException(e)
|
||||
it.resume(emptyList())
|
||||
return@suspendCancellableCoroutine
|
||||
}
|
||||
|
||||
if (cursor == null) {
|
||||
Log.e("MM20", "Plugin ${plugin.authority} returned null cursor")
|
||||
Log.e("MM20", "Plugin ${pluginAuthority} returned null cursor")
|
||||
it.resume(emptyList())
|
||||
return@suspendCancellableCoroutine
|
||||
}
|
||||
@@ -65,14 +65,14 @@ class PluginFileProvider(
|
||||
context.contentResolver.call(
|
||||
Uri.Builder()
|
||||
.scheme("content")
|
||||
.authority(plugin.authority)
|
||||
.authority(pluginAuthority)
|
||||
.build(),
|
||||
PluginContract.Methods.GetConfig,
|
||||
null,
|
||||
null
|
||||
) ?: return null
|
||||
} catch (e: Exception) {
|
||||
Log.e("MM20", "Plugin ${plugin.authority} threw exception")
|
||||
Log.e("MM20", "Plugin ${pluginAuthority} threw exception")
|
||||
CrashReporter.logException(e)
|
||||
return null
|
||||
}
|
||||
@@ -83,7 +83,7 @@ class PluginFileProvider(
|
||||
suspend fun getFile(id: String): File? {
|
||||
val uri = Uri.Builder()
|
||||
.scheme("content")
|
||||
.authority(plugin.authority)
|
||||
.authority(pluginAuthority)
|
||||
.path(SearchPluginContract.Paths.Root)
|
||||
.appendPath(id)
|
||||
.build()
|
||||
@@ -109,7 +109,7 @@ class PluginFileProvider(
|
||||
val config = getPluginConfig()
|
||||
|
||||
if (config == null) {
|
||||
Log.e("MM20", "Plugin ${plugin.authority} returned null config")
|
||||
Log.e("MM20", "Plugin ${pluginAuthority} returned null config")
|
||||
cursor.close()
|
||||
return null
|
||||
}
|
||||
@@ -153,7 +153,7 @@ class PluginFileProvider(
|
||||
}?.let { Uri.parse(it) },
|
||||
storageStrategy = config.storageStrategy,
|
||||
isDirectory = directoryIndex?.let { cursor.getInt(it) } == 1,
|
||||
authority = plugin.authority,
|
||||
authority = pluginAuthority,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -87,6 +87,17 @@ class FileSearchSettings(
|
||||
}
|
||||
}
|
||||
|
||||
val enabledPlugins: Flow<Set<String>>
|
||||
get(): Flow<Set<String>> {
|
||||
return context.dataStore.data.map { it.plugins }
|
||||
}
|
||||
|
||||
fun setEnabledPlugins(enabledPlugins: Set<String>) {
|
||||
updateData {
|
||||
it.copy(plugins = enabledPlugins)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun backup(toDir: File) {
|
||||
val data = context.dataStore.data.first()
|
||||
val file = File(toDir, "file_search.json")
|
||||
@@ -109,4 +120,14 @@ class FileSearchSettings(
|
||||
CrashReporter.logException(e)
|
||||
}
|
||||
}
|
||||
|
||||
fun setPluginEnabled(authority: String, enabled: Boolean) {
|
||||
updateData {
|
||||
if (enabled) {
|
||||
it.copy(plugins = it.plugins + authority)
|
||||
} else {
|
||||
it.copy(plugins = it.plugins - authority)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user