Skip to content
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
36 changes: 33 additions & 3 deletions src/startup/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
- Launches the correct UI
- Handles missing dependencies gracefully

NEW (DB-backed):
- Initializes SQLite
- Runs JSON → DB migration if needed
- Injects Repository into Scheduler

This file must not contain UI logic or storage logic.
"""

Expand Down Expand Up @@ -49,12 +54,37 @@ def _launch_mode(mode: StartupMode):
"""
Launch the appropriate UI based on the resolved mode.
Lazy imports ensure no heavy UI frameworks load unless needed.

NEW:
- DB initialization
- Migration
- Repository + Scheduler wiring
"""

# Create scheduler lazily (only if a UI is actually launching)
# ---------------------------------------------------------
# NEW: Initialize DB + Repository + Migration
# ---------------------------------------------------------
from storage.db import init_db
from storage.repository import Repository
from storage.migration import needs_migration, run_migration
from logic.scheduler import Scheduler
scheduler = Scheduler()
scheduler.load_tasks()

# 1. Ensure DB + schema exist
init_db()

# 2. Create repository
repo = Repository()

# 3. Run migration if needed
if needs_migration(repo):
run_migration(repo)

# 4. Create DB-backed scheduler
scheduler = Scheduler(repo)

# ---------------------------------------------------------
# OLD UI routing (unchanged)
# ---------------------------------------------------------

if mode == StartupMode.TK:
try:
Expand Down
Loading