|
23 | 23 | import warnings |
24 | 24 | warnings.filterwarnings("ignore", message="resource_tracker:.*semaphore", category=UserWarning) |
25 | 25 |
|
26 | | -# Show spinner during slow imports |
| 26 | +# Show spinner during slow imports (with slow-load message after 2s) |
| 27 | +import threading |
27 | 28 | from rich.console import Console |
28 | 29 | from rich.status import Status |
| 30 | + |
29 | 31 | _console = Console() |
30 | | -with Status("[dim]Loading...[/dim]", console=_console, spinner="dots"): |
| 32 | +_status = Status("[dim]Loading...[/dim]", console=_console, spinner="dots") |
| 33 | +_status.start() |
| 34 | + |
| 35 | +def _slow_load_hint(): |
| 36 | + _status.update("[dim]Loading... first run may take ~30s[/dim]") |
| 37 | + |
| 38 | +_slow_timer = threading.Timer(2.0, _slow_load_hint) |
| 39 | +_slow_timer.start() |
| 40 | + |
| 41 | +try: |
31 | 42 | # Version for update checking |
32 | 43 | try: |
33 | 44 | from importlib.metadata import version as _get_version |
|
46 | 57 | from providers import get_provider |
47 | 58 | from menubar import STTMenuBar |
48 | 59 | from overlay import get_overlay |
49 | | -del _console |
| 60 | +finally: |
| 61 | + _slow_timer.cancel() |
| 62 | + _status.stop() |
| 63 | + del _console, _status, _slow_timer, _slow_load_hint |
50 | 64 |
|
51 | 65 |
|
52 | 66 | class AppState(Enum): |
@@ -1120,12 +1134,24 @@ def save_and_update(key, value): |
1120 | 1134 | provider = None |
1121 | 1135 | init_error = None |
1122 | 1136 | provider_available = False |
1123 | | - with Status("[dim]Initializing...[/dim]", console=console, spinner="dots"): |
1124 | | - try: |
1125 | | - provider = get_provider(PROVIDER) |
1126 | | - provider_available = provider.is_available() # This imports heavy modules |
1127 | | - except ValueError as e: |
1128 | | - init_error = e |
| 1137 | + |
| 1138 | + status = Status("[dim]Initializing...[/dim]", console=console, spinner="dots") |
| 1139 | + status.start() |
| 1140 | + |
| 1141 | + def slow_init_hint(): |
| 1142 | + status.update("[dim]Initializing... first run may take ~30s[/dim]") |
| 1143 | + |
| 1144 | + slow_timer = threading.Timer(2.0, slow_init_hint) |
| 1145 | + slow_timer.start() |
| 1146 | + |
| 1147 | + try: |
| 1148 | + provider = get_provider(PROVIDER) |
| 1149 | + provider_available = provider.is_available() # This imports heavy modules |
| 1150 | + except ValueError as e: |
| 1151 | + init_error = e |
| 1152 | + finally: |
| 1153 | + slow_timer.cancel() |
| 1154 | + status.stop() |
1129 | 1155 |
|
1130 | 1156 | if init_error: |
1131 | 1157 | console.print(f"[red]✗[/red] {init_error}") |
|
0 commit comments