Skip to content

Commit a976f24

Browse files
committed
Show helpful hint after 2s if loading is slow
1 parent 3184684 commit a976f24

1 file changed

Lines changed: 35 additions & 9 deletions

File tree

stt.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,22 @@
2323
import warnings
2424
warnings.filterwarnings("ignore", message="resource_tracker:.*semaphore", category=UserWarning)
2525

26-
# Show spinner during slow imports
26+
# Show spinner during slow imports (with slow-load message after 2s)
27+
import threading
2728
from rich.console import Console
2829
from rich.status import Status
30+
2931
_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:
3142
# Version for update checking
3243
try:
3344
from importlib.metadata import version as _get_version
@@ -46,7 +57,10 @@
4657
from providers import get_provider
4758
from menubar import STTMenuBar
4859
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
5064

5165

5266
class AppState(Enum):
@@ -1120,12 +1134,24 @@ def save_and_update(key, value):
11201134
provider = None
11211135
init_error = None
11221136
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()
11291155

11301156
if init_error:
11311157
console.print(f"[red]✗[/red] {init_error}")

0 commit comments

Comments
 (0)