mindstorm38/portablemc

Obtain the progress of the download.

creeper-0910 opened this issue · 2 comments

I am trying to create a simple GUI launcher using portablemc, but I would like to display a progress bar to make sure it is working properly while downloading files.
Is there a way to do this?

My native language is not English, so sorry if there are any oddities.

To follow the download progress, you have to use a watcher on the installation process. Like in the following example:

from portablemc.standard import SimpleWatcher, DownloadStartEvent, DownloadProgressEvent, DownloadCompleteEvent

class FooWatcher(SimpleWatcher):
    def __init__(self):
        super().__init__({
            DownloadStartEvent: lambda e: print("start", e.entries_count, e.size, e.threads_count),
            DownloadProgressEvent: lambda e: print("progress", e.thread_id, e.speed, e.size, e.count, e.done),
            DownloadCompleteEvent: lambda e: print("completed")
        )}

version = ... # your version instance
version.install(watcher=FooWatcher())

Note that progress event/speed/size are individual for each threads, so if you want a global progress you have to sum/average them. You can see an more complete example of watcher in the CLI's implementation: https://github.com/mindstorm38/portablemc/blob/master/portablemc/cli/__init__.py#L678

My native language is not English, so sorry if there are any oddities.

Me neither, no problem :)

Thanks!