Add onboarding wizard framework and startup hook
This commit is contained in:
parent
ba9cb97720
commit
992d22a138
7 changed files with 520 additions and 10 deletions
|
|
@ -12,7 +12,70 @@ if str(SRC) not in sys.path:
|
|||
sys.path.insert(0, str(SRC))
|
||||
|
||||
import aman
|
||||
from config import Config
|
||||
from diagnostics import DiagnosticCheck, DiagnosticReport
|
||||
from onboarding_ui import OnboardingResult
|
||||
|
||||
|
||||
class _FakeDesktop:
|
||||
def __init__(self):
|
||||
self.hotkey = None
|
||||
self.hotkey_callback = None
|
||||
|
||||
def start_hotkey_listener(self, hotkey, callback):
|
||||
self.hotkey = hotkey
|
||||
self.hotkey_callback = callback
|
||||
|
||||
def stop_hotkey_listener(self):
|
||||
return
|
||||
|
||||
def start_cancel_listener(self, callback):
|
||||
_ = callback
|
||||
return
|
||||
|
||||
def stop_cancel_listener(self):
|
||||
return
|
||||
|
||||
def validate_hotkey(self, hotkey):
|
||||
_ = hotkey
|
||||
return
|
||||
|
||||
def inject_text(self, text, backend, *, remove_transcription_from_clipboard=False):
|
||||
_ = (text, backend, remove_transcription_from_clipboard)
|
||||
return
|
||||
|
||||
def run_tray(self, _state_getter, on_quit, **_kwargs):
|
||||
on_quit()
|
||||
|
||||
def request_quit(self):
|
||||
return
|
||||
|
||||
|
||||
class _FakeDaemon:
|
||||
def __init__(self, cfg, _desktop, *, verbose=False):
|
||||
self.cfg = cfg
|
||||
self.verbose = verbose
|
||||
self._paused = False
|
||||
|
||||
def get_state(self):
|
||||
return "idle"
|
||||
|
||||
def is_paused(self):
|
||||
return self._paused
|
||||
|
||||
def toggle_paused(self):
|
||||
self._paused = not self._paused
|
||||
return self._paused
|
||||
|
||||
def apply_config(self, cfg):
|
||||
self.cfg = cfg
|
||||
|
||||
def toggle(self):
|
||||
return
|
||||
|
||||
def shutdown(self, timeout=1.0):
|
||||
_ = timeout
|
||||
return True
|
||||
|
||||
|
||||
class AmanCliTests(unittest.TestCase):
|
||||
|
|
@ -86,6 +149,43 @@ class AmanCliTests(unittest.TestCase):
|
|||
payload = json.loads(path.read_text(encoding="utf-8"))
|
||||
self.assertEqual(payload["daemon"]["hotkey"], "Cmd+m")
|
||||
|
||||
def test_run_command_missing_config_uses_onboarding_and_writes_file(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = Path(td) / "config.json"
|
||||
args = aman._parse_cli_args(["run", "--config", str(path)])
|
||||
desktop = _FakeDesktop()
|
||||
onboard_cfg = Config()
|
||||
onboard_cfg.daemon.hotkey = "Super+m"
|
||||
with patch("aman._lock_single_instance", return_value=object()), patch(
|
||||
"aman.get_desktop_adapter", return_value=desktop
|
||||
), patch(
|
||||
"aman.run_onboarding_wizard",
|
||||
return_value=OnboardingResult(completed=True, config=onboard_cfg, aborted_reason=None),
|
||||
) as onboarding_mock, patch("aman.Daemon", _FakeDaemon):
|
||||
exit_code = aman._run_command(args)
|
||||
|
||||
self.assertEqual(exit_code, 0)
|
||||
self.assertTrue(path.exists())
|
||||
self.assertEqual(desktop.hotkey, "Super+m")
|
||||
onboarding_mock.assert_called_once()
|
||||
|
||||
def test_run_command_missing_config_cancel_returns_without_starting_daemon(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = Path(td) / "config.json"
|
||||
args = aman._parse_cli_args(["run", "--config", str(path)])
|
||||
desktop = _FakeDesktop()
|
||||
with patch("aman._lock_single_instance", return_value=object()), patch(
|
||||
"aman.get_desktop_adapter", return_value=desktop
|
||||
), patch(
|
||||
"aman.run_onboarding_wizard",
|
||||
return_value=OnboardingResult(completed=False, config=None, aborted_reason="cancelled"),
|
||||
), patch("aman.Daemon") as daemon_cls:
|
||||
exit_code = aman._run_command(args)
|
||||
|
||||
self.assertEqual(exit_code, 0)
|
||||
self.assertFalse(path.exists())
|
||||
daemon_cls.assert_not_called()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue