Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add downloader plugin system #2041

Open
wants to merge 16 commits into
base: compose-dev
Choose a base branch
from

Conversation

Axelen123
Copy link
Member

@Axelen123 Axelen123 commented Jul 12, 2024

Implements a plugin system for downloaders.

@Axelen123 Axelen123 changed the base branch from main to compose-dev July 12, 2024 13:30
@optimatrix0
Copy link

Eu gostaria que você comentasse um pouco mais sobre como funcionaria esse sistema de plugin para leigos em um texto se fosse possível para eu já ficar sabendo como funciona, acompanhe o projeto de você

interface DownloaderPlugin<A : DownloaderPlugin.App> {
val pagingConfig: PagingConfig
fun createPagingSource(parameters: SearchParameters): PagingSource<*, A>
suspend fun download(app: A, parameters: DownloadParameters)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In DSL an API like this would be better:

downloader {
	download { it: A -> inputStream to total }
}

* @param packageName The package name to search for.
* @param versionHint The preferred version to search for. It is not mandatory to respect this parameter.
*/
class SearchParameters(val packageName: String, val versionHint: String?)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SearchParameters can be converted to direct parameters in createPagingSource function

* @param targetFile The location where the downloaded APK should be saved.
* @param onDownloadProgress A callback for reporting download progress.
*/
class DownloadParameters(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DownloadParameters can be converted to direct parameters in download function

* @param onDownloadProgress A callback for reporting download progress.
*/
class DownloadParameters(
val targetFile: File,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a stream is better for the API to write to.

Suggested change
val targetFile: File,
val output: OutputStream,

*/
class DownloadParameters(
val targetFile: File,
val onDownloadProgress: suspend (progress: Pair<BytesReceived, BytesTotal>?) -> Unit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two parameters instead of a Pair is simpler, BytesTotal must be nullable in case total can't be reported by downloader. A spinner with current downloaded bytes can be shown.

)
}

typealias BytesReceived = Int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Named parameters can be used instead of type alias


override fun createPagingSource(parameters: DownloaderPlugin.SearchParameters) =
singlePagePagingSource {
val impl = withContext(Dispatchers.IO) { getPackageInfo(parameters.packageName) }?.let {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The context can be set when calling the createPagingSource function. The implementation can still switch context. This behaviour should be documented in the inline docs of this function so the user knows that this function is called on IO.

override fun createPagingSource(parameters: DownloaderPlugin.SearchParameters) =
singlePagePagingSource {
val impl = withContext(Dispatchers.IO) { getPackageInfo(parameters.packageName) }?.let {
AppImpl(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably PMDownloader and PMApp would be a better name for purpose of an example instead of "AppImpl"

@Axelen123 Axelen123 force-pushed the compose/downloader-system branch 2 times, most recently from c064800 to 0637365 Compare July 13, 2024 21:05
@oSumAtrIX oSumAtrIX changed the title feat: implement downloader plugin system feat: Add downloader plugin system Jul 25, 2024
@oSumAtrIX oSumAtrIX added the ReVanced Manager Compose Regarding the Compose rewrite of ReVanced Manager label Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ReVanced Manager Compose Regarding the Compose rewrite of ReVanced Manager
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: downloader plugin system feat: Add APK Downloading System with Plugin Architecture
3 participants