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: show a bouncing progress bar during package installation #74

Merged
merged 2 commits into from
Apr 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions yafti/screen/package/screen/install.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
from gi.repository import Gtk

import yafti.share
Expand Down Expand Up @@ -67,6 +68,7 @@ class PackageInstallScreen(YaftiScreen, Gtk.Box):
btn_console = Gtk.Template.Child()
started = False
already_run = False
pulse = True

class Config(YaftiScreenConfig):
package_manager: str = "yafti.plugin.flatpak"
Expand Down Expand Up @@ -98,22 +100,28 @@ def toggle_console(self, btn):
btn.set_label("Show Console" if self.console.get_visible() else "Hide Console")
self.console.toggle_visible()

async def draw(self):
async def do_pulse(self):
self.pkg_progress.set_pulse_step(1.0)
while self.pulse:
self.pkg_progress.pulse()
await asyncio.sleep(0.5)

def draw(self):
self.console.hide()
self.append(self.console)
packages = [item.replace("pkg:", "") for item in STATE.get_on("pkg:")]
await self.install(packages)
asyncio.create_task(self.do_pulse())
return self.install(packages)

async def install(self, packages: list):
total = len(packages)
self.pkg_progress.set_fraction(0.01)
yafti.share.BTN_NEXT.set_label("Installing...")
yafti.share.BTN_BACK.set_visible(False)

for idx, pkg in enumerate(packages):
r = await self.package_manager.install(pkg)
self.console.stdout(r.stdout)
self.console.stderr(r.stderr)
self.pulse = False
self.pkg_progress.set_fraction((idx + 1) / total)

self.console.stdout(b"Installation Complete!")
Expand Down