Skip to content

Commit d85e13a

Browse files
committed
More user friendly progress bar
1 parent 954ce7d commit d85e13a

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

modules/api.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,19 +410,19 @@ async def import_browser_bookmarks(file: str | pathlib.Path):
410410

411411

412412
async def import_f95_bookmarks():
413-
globals.refresh_total = 2
413+
globals.refresh_total = 1
414414
if not await assert_login():
415415
return
416416
globals.refresh_progress = 1
417417
offset = 0
418418
threads = []
419419
while True:
420420
globals.refresh_total += 1
421-
globals.refresh_progress += 1
422421
res = await fetch("GET", bookmarks_page.format(offset=offset))
423422
raise_f95zone_error(res)
424423
html = parser.html(res)
425424
bookmarks = html.find(parser.is_class("p-body-pageContent")).find(parser.is_class("listPlain"))
425+
globals.refresh_progress += 1
426426
if not bookmarks:
427427
break
428428
for title in bookmarks.find_all(parser.is_class("contentRow-title")):
@@ -439,19 +439,19 @@ async def import_f95_bookmarks():
439439

440440

441441
async def import_f95_watched_threads():
442-
globals.refresh_total = 2
442+
globals.refresh_total = 1
443443
if not await assert_login():
444444
return
445445
globals.refresh_progress = 1
446446
page = 1
447447
threads = []
448448
while True:
449449
globals.refresh_total += 1
450-
globals.refresh_progress += 1
451450
res = await fetch("GET", watched_page.format(page=page))
452451
raise_f95zone_error(res)
453452
html = parser.html(res)
454453
watched = html.find(parser.is_class("p-body-pageContent")).find(parser.is_class("structItemContainer"))
454+
globals.refresh_progress += 1
455455
if not watched:
456456
break
457457
page += 1
@@ -722,6 +722,7 @@ async def check_notifs(login=False):
722722
MsgBox.error,
723723
more=error.traceback()
724724
)
725+
globals.refresh_progress += 1
725726
if alerts != 0 and inbox != 0:
726727
msg = (
727728
f"You have {alerts + inbox} unread notifications.\n"

modules/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ def start_refresh_task(coro: typing.Coroutine, reset_bg_timers=True):
7373
globals.refresh_progress = 0
7474
globals.refresh_total = 1
7575
globals.gui.refresh_ratio_smooth = 0.0
76-
globals.refresh_task = async_thread.run(coro)
76+
async def coro_wrapper():
77+
await coro
78+
await asyncio.sleep(0.5)
79+
globals.refresh_task = async_thread.run(coro_wrapper())
7780
globals.gui.tray.update_status()
7881
def done_callback(future: asyncio.Future):
7982
globals.refresh_task = None

0 commit comments

Comments
 (0)