Normalize native dependency ownership and split config UI
Some checks failed
Some checks failed
Make distro packages the single source of truth for GTK/X11 Python bindings instead of advertising them as wheel-managed runtime dependencies. Update the uv, CI, and packaging workflows to use system site packages, regenerate uv.lock, and keep portable and Arch metadata aligned with that contract. Pull runtime policy, audio probing, and page builders out of config_ui.py so the settings window becomes a coordinator instead of a single large mixed-concern module. Rename the config serialization and logging helpers, and stop startup logging from exposing raw vocabulary entries or custom model paths. Remove stale helper aliases and add regression coverage for safe startup logging, packaging metadata and module drift, portable requirements, and the extracted audio helper behavior. Validated with uv lock, python3 -m compileall -q src tests, python3 -m unittest discover -s tests -p 'test_*.py', make build, and make package-arch.
This commit is contained in:
parent
f779b71e1b
commit
c6fc61c885
23 changed files with 617 additions and 437 deletions
322
src/config_ui.py
322
src/config_ui.py
|
|
@ -3,29 +3,34 @@ from __future__ import annotations
|
|||
import copy
|
||||
import importlib.metadata
|
||||
import logging
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
import gi
|
||||
|
||||
from config import (
|
||||
Config,
|
||||
DEFAULT_STT_PROVIDER,
|
||||
from config import Config, DEFAULT_STT_PROVIDER
|
||||
from config_ui_audio import AudioSettingsService
|
||||
from config_ui_pages import (
|
||||
build_about_page,
|
||||
build_advanced_page,
|
||||
build_audio_page,
|
||||
build_general_page,
|
||||
build_help_page,
|
||||
)
|
||||
from config_ui_runtime import (
|
||||
RUNTIME_MODE_EXPERT,
|
||||
RUNTIME_MODE_MANAGED,
|
||||
apply_canonical_runtime_defaults,
|
||||
infer_runtime_mode,
|
||||
)
|
||||
from constants import DEFAULT_CONFIG_PATH
|
||||
from languages import COMMON_STT_LANGUAGE_OPTIONS, stt_language_label
|
||||
from recorder import list_input_devices, resolve_input_device, start_recording, stop_recording
|
||||
from languages import stt_language_label
|
||||
|
||||
gi.require_version("Gdk", "3.0")
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gdk, Gtk # type: ignore[import-not-found]
|
||||
|
||||
|
||||
RUNTIME_MODE_MANAGED = "aman_managed"
|
||||
RUNTIME_MODE_EXPERT = "expert_custom"
|
||||
|
||||
|
||||
@dataclass
|
||||
class ConfigUiResult:
|
||||
saved: bool
|
||||
|
|
@ -33,21 +38,6 @@ class ConfigUiResult:
|
|||
closed_reason: str | None = None
|
||||
|
||||
|
||||
def infer_runtime_mode(cfg: Config) -> str:
|
||||
is_canonical = (
|
||||
cfg.stt.provider.strip().lower() == DEFAULT_STT_PROVIDER
|
||||
and not bool(cfg.models.allow_custom_models)
|
||||
and not cfg.models.whisper_model_path.strip()
|
||||
)
|
||||
return RUNTIME_MODE_MANAGED if is_canonical else RUNTIME_MODE_EXPERT
|
||||
|
||||
|
||||
def apply_canonical_runtime_defaults(cfg: Config) -> None:
|
||||
cfg.stt.provider = DEFAULT_STT_PROVIDER
|
||||
cfg.models.allow_custom_models = False
|
||||
cfg.models.whisper_model_path = ""
|
||||
|
||||
|
||||
class ConfigWindow:
|
||||
def __init__(
|
||||
self,
|
||||
|
|
@ -61,7 +51,8 @@ class ConfigWindow:
|
|||
self._config = copy.deepcopy(initial_cfg)
|
||||
self._required = required
|
||||
self._config_path = Path(config_path) if config_path else DEFAULT_CONFIG_PATH
|
||||
self._devices = list_input_devices()
|
||||
self._audio_settings = AudioSettingsService()
|
||||
self._devices = self._audio_settings.list_input_devices()
|
||||
self._device_by_id = {str(device["index"]): device for device in self._devices}
|
||||
self._row_to_section: dict[Gtk.ListBoxRow, str] = {}
|
||||
self._runtime_mode = infer_runtime_mode(self._config)
|
||||
|
|
@ -115,11 +106,11 @@ class ConfigWindow:
|
|||
self._stack.set_transition_duration(120)
|
||||
body.pack_start(self._stack, True, True, 0)
|
||||
|
||||
self._general_page = self._build_general_page()
|
||||
self._audio_page = self._build_audio_page()
|
||||
self._advanced_page = self._build_advanced_page()
|
||||
self._help_page = self._build_help_page()
|
||||
self._about_page = self._build_about_page()
|
||||
self._general_page = build_general_page(self)
|
||||
self._audio_page = build_audio_page(self)
|
||||
self._advanced_page = build_advanced_page(self)
|
||||
self._help_page = build_help_page(self, present_about_dialog=_present_about_dialog)
|
||||
self._about_page = build_about_page(self, present_about_dialog=_present_about_dialog)
|
||||
|
||||
self._add_section("general", "General", self._general_page)
|
||||
self._add_section("audio", "Audio", self._audio_page)
|
||||
|
|
@ -169,261 +160,6 @@ class ConfigWindow:
|
|||
if section:
|
||||
self._stack.set_visible_child_name(section)
|
||||
|
||||
def _build_general_page(self) -> Gtk.Widget:
|
||||
grid = Gtk.Grid(column_spacing=12, row_spacing=10)
|
||||
grid.set_margin_start(14)
|
||||
grid.set_margin_end(14)
|
||||
grid.set_margin_top(14)
|
||||
grid.set_margin_bottom(14)
|
||||
|
||||
hotkey_label = Gtk.Label(label="Trigger hotkey")
|
||||
hotkey_label.set_xalign(0.0)
|
||||
self._hotkey_entry = Gtk.Entry()
|
||||
self._hotkey_entry.set_placeholder_text("Super+m")
|
||||
self._hotkey_entry.connect("changed", lambda *_: self._validate_hotkey())
|
||||
grid.attach(hotkey_label, 0, 0, 1, 1)
|
||||
grid.attach(self._hotkey_entry, 1, 0, 1, 1)
|
||||
|
||||
self._hotkey_error = Gtk.Label(label="")
|
||||
self._hotkey_error.set_xalign(0.0)
|
||||
self._hotkey_error.set_line_wrap(True)
|
||||
grid.attach(self._hotkey_error, 1, 1, 1, 1)
|
||||
|
||||
backend_label = Gtk.Label(label="Text injection")
|
||||
backend_label.set_xalign(0.0)
|
||||
self._backend_combo = Gtk.ComboBoxText()
|
||||
self._backend_combo.append("clipboard", "Clipboard paste (recommended)")
|
||||
self._backend_combo.append("injection", "Simulated typing")
|
||||
grid.attach(backend_label, 0, 2, 1, 1)
|
||||
grid.attach(self._backend_combo, 1, 2, 1, 1)
|
||||
|
||||
self._remove_clipboard_check = Gtk.CheckButton(
|
||||
label="Remove transcription from clipboard after paste"
|
||||
)
|
||||
self._remove_clipboard_check.set_hexpand(True)
|
||||
grid.attach(self._remove_clipboard_check, 1, 3, 1, 1)
|
||||
|
||||
language_label = Gtk.Label(label="Transcription language")
|
||||
language_label.set_xalign(0.0)
|
||||
self._language_combo = Gtk.ComboBoxText()
|
||||
for code, label in COMMON_STT_LANGUAGE_OPTIONS:
|
||||
self._language_combo.append(code, label)
|
||||
grid.attach(language_label, 0, 4, 1, 1)
|
||||
grid.attach(self._language_combo, 1, 4, 1, 1)
|
||||
|
||||
profile_label = Gtk.Label(label="Profile")
|
||||
profile_label.set_xalign(0.0)
|
||||
self._profile_combo = Gtk.ComboBoxText()
|
||||
self._profile_combo.append("default", "Default")
|
||||
self._profile_combo.append("fast", "Fast (lower latency)")
|
||||
self._profile_combo.append("polished", "Polished")
|
||||
grid.attach(profile_label, 0, 5, 1, 1)
|
||||
grid.attach(self._profile_combo, 1, 5, 1, 1)
|
||||
|
||||
return grid
|
||||
|
||||
def _build_audio_page(self) -> Gtk.Widget:
|
||||
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
|
||||
box.set_margin_start(14)
|
||||
box.set_margin_end(14)
|
||||
box.set_margin_top(14)
|
||||
box.set_margin_bottom(14)
|
||||
|
||||
input_label = Gtk.Label(label="Input device")
|
||||
input_label.set_xalign(0.0)
|
||||
box.pack_start(input_label, False, False, 0)
|
||||
|
||||
self._mic_combo = Gtk.ComboBoxText()
|
||||
self._mic_combo.append("", "System default")
|
||||
for device in self._devices:
|
||||
self._mic_combo.append(str(device["index"]), f"{device['index']}: {device['name']}")
|
||||
box.pack_start(self._mic_combo, False, False, 0)
|
||||
|
||||
test_button = Gtk.Button(label="Test microphone")
|
||||
test_button.connect("clicked", lambda *_: self._on_test_microphone())
|
||||
box.pack_start(test_button, False, False, 0)
|
||||
|
||||
self._mic_status = Gtk.Label(label="")
|
||||
self._mic_status.set_xalign(0.0)
|
||||
self._mic_status.set_line_wrap(True)
|
||||
box.pack_start(self._mic_status, False, False, 0)
|
||||
return box
|
||||
|
||||
def _build_advanced_page(self) -> Gtk.Widget:
|
||||
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
|
||||
box.set_margin_start(14)
|
||||
box.set_margin_end(14)
|
||||
box.set_margin_top(14)
|
||||
box.set_margin_bottom(14)
|
||||
|
||||
self._strict_startup_check = Gtk.CheckButton(label="Fail fast on startup validation errors")
|
||||
box.pack_start(self._strict_startup_check, False, False, 0)
|
||||
|
||||
safety_title = Gtk.Label()
|
||||
safety_title.set_markup("<span weight='bold'>Output safety</span>")
|
||||
safety_title.set_xalign(0.0)
|
||||
box.pack_start(safety_title, False, False, 0)
|
||||
|
||||
self._safety_enabled_check = Gtk.CheckButton(
|
||||
label="Enable fact-preservation guard (recommended)"
|
||||
)
|
||||
self._safety_enabled_check.connect("toggled", lambda *_: self._on_safety_guard_toggled())
|
||||
box.pack_start(self._safety_enabled_check, False, False, 0)
|
||||
|
||||
self._safety_strict_check = Gtk.CheckButton(
|
||||
label="Strict mode: reject output when facts are changed"
|
||||
)
|
||||
box.pack_start(self._safety_strict_check, False, False, 0)
|
||||
|
||||
runtime_title = Gtk.Label()
|
||||
runtime_title.set_markup("<span weight='bold'>Runtime management</span>")
|
||||
runtime_title.set_xalign(0.0)
|
||||
box.pack_start(runtime_title, False, False, 0)
|
||||
|
||||
runtime_copy = Gtk.Label(
|
||||
label=(
|
||||
"Aman-managed mode handles the canonical editor model lifecycle for you. "
|
||||
"Expert mode keeps Aman open-source friendly by letting you use custom Whisper paths."
|
||||
)
|
||||
)
|
||||
runtime_copy.set_xalign(0.0)
|
||||
runtime_copy.set_line_wrap(True)
|
||||
box.pack_start(runtime_copy, False, False, 0)
|
||||
|
||||
mode_label = Gtk.Label(label="Runtime mode")
|
||||
mode_label.set_xalign(0.0)
|
||||
box.pack_start(mode_label, False, False, 0)
|
||||
|
||||
self._runtime_mode_combo = Gtk.ComboBoxText()
|
||||
self._runtime_mode_combo.append(RUNTIME_MODE_MANAGED, "Aman-managed (recommended)")
|
||||
self._runtime_mode_combo.append(RUNTIME_MODE_EXPERT, "Expert mode (custom Whisper path)")
|
||||
self._runtime_mode_combo.connect("changed", lambda *_: self._on_runtime_mode_changed(user_initiated=True))
|
||||
box.pack_start(self._runtime_mode_combo, False, False, 0)
|
||||
|
||||
self._runtime_status_label = Gtk.Label(label="")
|
||||
self._runtime_status_label.set_xalign(0.0)
|
||||
self._runtime_status_label.set_line_wrap(True)
|
||||
box.pack_start(self._runtime_status_label, False, False, 0)
|
||||
|
||||
self._expert_expander = Gtk.Expander(label="Expert options")
|
||||
self._expert_expander.set_expanded(False)
|
||||
box.pack_start(self._expert_expander, False, False, 0)
|
||||
|
||||
expert_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8)
|
||||
expert_box.set_margin_start(10)
|
||||
expert_box.set_margin_end(10)
|
||||
expert_box.set_margin_top(8)
|
||||
expert_box.set_margin_bottom(8)
|
||||
self._expert_expander.add(expert_box)
|
||||
|
||||
expert_warning = Gtk.InfoBar()
|
||||
expert_warning.set_show_close_button(False)
|
||||
expert_warning.set_message_type(Gtk.MessageType.WARNING)
|
||||
warning_label = Gtk.Label(
|
||||
label=(
|
||||
"Expert mode is best-effort and may require manual troubleshooting. "
|
||||
"Aman-managed mode is the canonical supported path."
|
||||
)
|
||||
)
|
||||
warning_label.set_xalign(0.0)
|
||||
warning_label.set_line_wrap(True)
|
||||
expert_warning.get_content_area().pack_start(warning_label, True, True, 0)
|
||||
expert_box.pack_start(expert_warning, False, False, 0)
|
||||
|
||||
self._allow_custom_models_check = Gtk.CheckButton(
|
||||
label="Allow custom local model paths"
|
||||
)
|
||||
self._allow_custom_models_check.connect("toggled", lambda *_: self._on_runtime_widgets_changed())
|
||||
expert_box.pack_start(self._allow_custom_models_check, False, False, 0)
|
||||
|
||||
whisper_model_path_label = Gtk.Label(label="Custom Whisper model path")
|
||||
whisper_model_path_label.set_xalign(0.0)
|
||||
expert_box.pack_start(whisper_model_path_label, False, False, 0)
|
||||
self._whisper_model_path_entry = Gtk.Entry()
|
||||
self._whisper_model_path_entry.connect("changed", lambda *_: self._on_runtime_widgets_changed())
|
||||
expert_box.pack_start(self._whisper_model_path_entry, False, False, 0)
|
||||
|
||||
self._runtime_error = Gtk.Label(label="")
|
||||
self._runtime_error.set_xalign(0.0)
|
||||
self._runtime_error.set_line_wrap(True)
|
||||
expert_box.pack_start(self._runtime_error, False, False, 0)
|
||||
|
||||
path_label = Gtk.Label(label="Config path")
|
||||
path_label.set_xalign(0.0)
|
||||
box.pack_start(path_label, False, False, 0)
|
||||
|
||||
path_entry = Gtk.Entry()
|
||||
path_entry.set_editable(False)
|
||||
path_entry.set_text(str(self._config_path))
|
||||
box.pack_start(path_entry, False, False, 0)
|
||||
|
||||
note = Gtk.Label(
|
||||
label=(
|
||||
"Tip: after editing the file directly, use Reload Config from the tray to apply changes."
|
||||
)
|
||||
)
|
||||
note.set_xalign(0.0)
|
||||
note.set_line_wrap(True)
|
||||
box.pack_start(note, False, False, 0)
|
||||
return box
|
||||
|
||||
def _build_help_page(self) -> Gtk.Widget:
|
||||
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
|
||||
box.set_margin_start(14)
|
||||
box.set_margin_end(14)
|
||||
box.set_margin_top(14)
|
||||
box.set_margin_bottom(14)
|
||||
|
||||
help_text = Gtk.Label(
|
||||
label=(
|
||||
"Usage:\n"
|
||||
"- Press your hotkey to start recording.\n"
|
||||
"- Press the hotkey again to stop and process.\n"
|
||||
"- Press Esc while recording to cancel.\n\n"
|
||||
"Supported path:\n"
|
||||
"- Daily use runs through the tray and user service.\n"
|
||||
"- Aman-managed mode (recommended) handles model lifecycle for you.\n"
|
||||
"- Expert mode keeps custom Whisper paths available for advanced users.\n\n"
|
||||
"Recovery:\n"
|
||||
"- Use Run Diagnostics from the tray for a deeper self-check.\n"
|
||||
"- If that is not enough, run aman doctor, then aman self-check.\n"
|
||||
"- Next escalations are journalctl --user -u aman and aman run --verbose.\n\n"
|
||||
"Safety tips:\n"
|
||||
"- Keep fact guard enabled to prevent accidental name/number changes.\n"
|
||||
"- Strict safety blocks output on fact violations."
|
||||
)
|
||||
)
|
||||
help_text.set_xalign(0.0)
|
||||
help_text.set_line_wrap(True)
|
||||
box.pack_start(help_text, False, False, 0)
|
||||
|
||||
about_button = Gtk.Button(label="Open About Dialog")
|
||||
about_button.connect("clicked", lambda *_: _present_about_dialog(self._dialog))
|
||||
box.pack_start(about_button, False, False, 0)
|
||||
return box
|
||||
|
||||
def _build_about_page(self) -> Gtk.Widget:
|
||||
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
|
||||
box.set_margin_start(14)
|
||||
box.set_margin_end(14)
|
||||
box.set_margin_top(14)
|
||||
box.set_margin_bottom(14)
|
||||
|
||||
title = Gtk.Label()
|
||||
title.set_markup("<span size='x-large' weight='bold'>Aman</span>")
|
||||
title.set_xalign(0.0)
|
||||
box.pack_start(title, False, False, 0)
|
||||
|
||||
subtitle = Gtk.Label(label="Local amanuensis for X11 desktop dictation and rewriting.")
|
||||
subtitle.set_xalign(0.0)
|
||||
subtitle.set_line_wrap(True)
|
||||
box.pack_start(subtitle, False, False, 0)
|
||||
|
||||
about_button = Gtk.Button(label="About Aman")
|
||||
about_button.connect("clicked", lambda *_: _present_about_dialog(self._dialog))
|
||||
box.pack_start(about_button, False, False, 0)
|
||||
return box
|
||||
|
||||
def _initialize_widget_values(self) -> None:
|
||||
hotkey = self._config.daemon.hotkey.strip() or "Super+m"
|
||||
self._hotkey_entry.set_text(hotkey)
|
||||
|
|
@ -457,7 +193,7 @@ class ConfigWindow:
|
|||
self._sync_runtime_mode_ui(user_initiated=False)
|
||||
self._validate_runtime_settings()
|
||||
|
||||
resolved = resolve_input_device(self._config.recording.input)
|
||||
resolved = self._audio_settings.resolve_input_device(self._config.recording.input)
|
||||
if resolved is None:
|
||||
self._mic_combo.set_active_id("")
|
||||
return
|
||||
|
|
@ -536,16 +272,8 @@ class ConfigWindow:
|
|||
self._mic_status.set_text("Testing microphone...")
|
||||
while Gtk.events_pending():
|
||||
Gtk.main_iteration()
|
||||
try:
|
||||
stream, record = start_recording(input_spec)
|
||||
time.sleep(0.35)
|
||||
audio = stop_recording(stream, record)
|
||||
if getattr(audio, "size", 0) > 0:
|
||||
self._mic_status.set_text("Microphone test successful.")
|
||||
return
|
||||
self._mic_status.set_text("No audio captured. Try another device.")
|
||||
except Exception as exc:
|
||||
self._mic_status.set_text(f"Microphone test failed: {exc}")
|
||||
result = self._audio_settings.test_microphone(input_spec)
|
||||
self._mic_status.set_text(result.message)
|
||||
|
||||
def _validate_hotkey(self) -> bool:
|
||||
hotkey = self._hotkey_entry.get_text().strip()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue