From 730152379886f1a7dd7c36d68918706c82ad718d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 2 Apr 2026 22:03:06 +0300 Subject: task 00e: inject phonetic.Fetcher and translation.Translator into gui.New() Add PhoneticFetcher and Translator fields to gui.Config so callers can inject ready-to-use instances. gui.New() uses the injected values when non-nil and falls back to constructing from provider/key fields otherwise. The processor composition root now builds both dependencies and sets them on gui.Config, keeping construction logic out of gui.New(). Co-Authored-By: Claude Sonnet 4.6 --- internal/gui/app.go | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'internal/gui') diff --git a/internal/gui/app.go b/internal/gui/app.go index f9d941d..666c763 100644 --- a/internal/gui/app.go +++ b/internal/gui/app.go @@ -127,6 +127,11 @@ type Config struct { TranslationProvider translation.Provider PhoneticProvider phonetic.Provider AutoPlay bool // Whether to automatically play audio when generated or navigated to + + // Injectable dependencies — when non-nil, New() uses them directly instead of + // constructing new instances from the provider/key fields above. + PhoneticFetcher *phonetic.Fetcher + Translator *translation.Translator } const ( @@ -221,12 +226,24 @@ func New(config *Config) *Application { // Set up audio configuration app.audioConfig = audioConfigForApp(config) - app.phoneticFetcher = phonetic.NewFetcher(&phonetic.Config{ - Provider: config.PhoneticProvider, - OpenAIKey: config.OpenAIKey, - GoogleAPIKey: config.GoogleAPIKey, - }) - app.translator = translation.NewTranslator(translationConfigForApp(config)) + + // Use injected phonetic fetcher when provided; otherwise construct from config fields. + if config.PhoneticFetcher != nil { + app.phoneticFetcher = config.PhoneticFetcher + } else { + app.phoneticFetcher = phonetic.NewFetcher(&phonetic.Config{ + Provider: config.PhoneticProvider, + OpenAIKey: config.OpenAIKey, + GoogleAPIKey: config.GoogleAPIKey, + }) + } + + // Use injected translator when provided; otherwise construct from config fields. + if config.Translator != nil { + app.translator = config.Translator + } else { + app.translator = translation.NewTranslator(translationConfigForApp(config)) + } app.setupUI() -- cgit v1.2.3