hex/src/rune_ui.rs
2026-10-22 15:02:17 -04:00

1055 lines
34 KiB
Rust

//! The experimental Rune front end for Linux and Windows (`hex app --ui rune`).
//!
//! The window talks to a host in the same process: on Linux the dictation
//! host beside it (`linux_host`, the default window on `rune-ui` builds); on
//! Windows the runtime thread `windows_rune` starts (`windows_host`). Either
//! way it saves `settings.json` through the host, which adopts it, and sends
//! the same requests for listening, shortcuts, models, and updates. It has the panes GPUI shows
//! there (Settings, Modes, Voice Action, History), the transcription picker,
//! and first-run setup, drawn with `rune-kit`'s components in OpenCode's
//! design language (`rune-theme-opencode`), not Hex's GPUI design tokens.
mod commands;
mod controls;
mod history;
#[cfg_attr(target_os = "linux", path = "rune_ui/linux_host.rs")]
#[cfg_attr(target_os = "windows", path = "rune_ui/windows_host.rs")]
mod host;
mod lists;
mod meetings;
mod models;
mod modes;
mod onboarding;
mod picker;
mod platform;
mod platform_settings;
mod settings;
mod voice_action;
use std::sync::Arc;
use std::time::{Duration, Instant};
use rune::{AppSpec, Cx, El, Icon, ScrollSpec, TextEdit, Tx, Waker, col, el, icon, row, text};
use crate::app_settings::{AppSettings, HotkeyBinding, HotkeyKey, HotkeyModifiers};
use crate::desktop_host::{
DesktopAction, DesktopGrantedShortcut, DesktopListenerSnapshot, DesktopShortcuts,
DesktopTranscriptionSnapshot, DesktopUpdateStatus,
};
use crate::desktop_i18n::{tr, tr_fill};
use crate::transcription_models::TranscriptionModelId;
use controls::Paint;
use host::{Backend, Request, ShortcutTarget};
use settings::Capture;
/// How long typing pauses before a text field's edit is saved, as in GPUI.
const DRAFT_DELAY: Duration = Duration::from_millis(250);
static SETTINGS_ICON: Icon = Icon {
name: "hex-settings",
view: 16.0,
body: include_str!("../assets/icons/settings.svg"),
};
static MODES_ICON: Icon = Icon {
name: "hex-modes",
view: 16.0,
body: include_str!("../assets/icons/modes.svg"),
};
static VOICE_ACTION_ICON: Icon = Icon {
name: "hex-voice-action",
view: 16.0,
body: include_str!("../assets/icons/voice-action.svg"),
};
static HISTORY_ICON: Icon = Icon {
name: "hex-history",
view: 16.0,
body: include_str!("../assets/icons/history.svg"),
};
static COMMANDS_ICON: Icon = Icon {
name: "hex-commands",
view: 16.0,
body: include_str!("../assets/icons/commands.svg"),
};
static MEETINGS_ICON: Icon = Icon {
name: "hex-meetings",
view: 16.0,
body: include_str!("../assets/icons/meetings.svg"),
};
/// Runs the Linux window's app on the main thread until Hex quits: the
/// window side of `linux_app`'s seam. It starts without a window; each
/// `Activate` opens or focuses it with the launcher's activation token, and
/// closing it keeps the app, its state, and the host running.
#[cfg(target_os = "linux")]
pub(crate) fn run_app(
host: crate::linux_app::HostHandle,
requests: std::sync::mpsc::Receiver<crate::linux_service::Control>,
first: Option<crate::linux_service::Activation>,
) {
use crate::linux_service::{Activation, Control};
let _host = host::install(host.clone());
rune::set_app_id("hex");
let app = rune::App::new(spec())
.args(Vec::new())
.windowless()
.on_close(on_close);
let handle = app.handle();
let show = move |activation: Activation| {
host.set_window_open(true);
match activation.token.or(activation.startup_id) {
Some(token) => handle.activate(token),
None => handle.open(),
}
};
if let Some(activation) = first {
show(activation.clone());
}
let quit = app.handle();
std::thread::Builder::new()
.name("hex-window-requests".into())
.spawn(move || {
while let Ok(request) = requests.recv() {
match request {
Control::Activate(activation) => show(activation),
Control::Quit => {
quit.quit();
break;
}
}
}
})
.expect("could not start the window request thread");
app.run();
}
/// The window as a Rune app whose lifetime the caller chooses.
#[cfg(target_os = "windows")]
pub(crate) fn app() -> rune::App<Ui> {
rune::App::new(spec()).on_close(on_close)
}
/// Closing the window saves pending text edits and stops a shortcut
/// recording, as leaving a pane does. Hex keeps running.
fn on_close(ui: &mut Ui, _: &mut Tx) {
ui.flush_drafts();
settings::cancel_capture(ui);
ui.open = None;
picker::close(ui);
if let Service::Live(backend) = &mut ui.service {
backend.closed();
}
}
/// `hex app -- --snap out.png --scene …`: a headless render of a fixture
/// scene, or `live` for the running Hex's `hex status`.
#[cfg(target_os = "linux")]
pub(crate) fn render() {
rune::run(spec());
}
fn spec() -> AppSpec<Ui> {
AppSpec {
title: "Hex",
size: (980.0, 760.0),
init: Ui::load,
view,
scenes: SCENES,
fonts: rune_theme_opencode::FONTS,
families: rune_theme_opencode::FAMILIES,
setup: Some(setup),
poll: Some(poll),
on_key: Some(on_key),
}
}
/// Where the window sends its requests.
enum Service {
/// Not connected yet: `setup` connects unless a scene chose a fixture.
Pending,
Live(Box<Backend>),
/// Snapshots and tests: requests are recorded, never sent.
Fixture(Vec<Request>),
}
/// The host's latest state.
struct HostState {
view: ServiceView,
settings: AppSettings,
}
/// What the window shows of the service, from its latest snapshot.
#[derive(Clone, PartialEq)]
struct ServiceView {
listener: DesktopListenerSnapshot,
operation_error: Option<String>,
transcription: DesktopTranscriptionSnapshot,
update_status: DesktopUpdateStatus,
/// The service is recording or saving a shortcut.
editing: bool,
}
/// Every pane, in navigation order. Which ones show depends on the OS's
/// [`platform::Capabilities`] and opt-ins ([`Pane::shown`]).
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
enum Pane {
#[default]
Settings,
Modes,
/// The voice command catalog (macOS).
Commands,
VoiceAction,
History,
/// Recorded calls (macOS beta, behind the Meetings opt-in).
Meetings,
}
impl Pane {
const ALL: [Pane; 6] = [
Pane::Settings,
Pane::Modes,
Pane::Commands,
Pane::VoiceAction,
Pane::History,
Pane::Meetings,
];
fn shown(self, ui: &Ui) -> bool {
let caps = ui.platform.caps;
match self {
Pane::Commands => caps.commands,
Pane::Meetings => caps.meetings && ui.settings.meetings.available(),
_ => true,
}
}
fn title(self) -> &'static str {
match self {
Pane::Settings => tr("Settings"),
Pane::Modes => tr("Modes"),
Pane::Commands => tr("Commands"),
Pane::VoiceAction => tr("Voice Action"),
Pane::History => tr("History"),
Pane::Meetings => tr("Meetings"),
}
}
fn key(self) -> &'static str {
match self {
Pane::Settings => "nav-settings",
Pane::Modes => "nav-modes",
Pane::Commands => "nav-commands",
Pane::VoiceAction => "nav-voice-action",
Pane::History => "nav-history",
Pane::Meetings => "nav-meetings",
}
}
fn icon(self) -> &'static Icon {
match self {
Pane::Settings => &SETTINGS_ICON,
Pane::Modes => &MODES_ICON,
Pane::Commands => &COMMANDS_ICON,
Pane::VoiceAction => &VOICE_ACTION_ICON,
Pane::History => &HISTORY_ICON,
Pane::Meetings => &MEETINGS_ICON,
}
}
}
/// The one anchored menu or popover that is open.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
enum Menu {
Microphone,
Language,
HistoryRetention,
/// The OpenCode model search for Voice Action or the selected mode.
Model,
/// The OpenCode thinking variant.
Variant,
/// The selected meeting's overflow menu.
MeetingActions,
}
pub(crate) struct Ui {
settings: AppSettings,
service: Service,
view: Option<ServiceView>,
/// A save or policy change that failed here.
error: Option<String>,
/// Why the client cannot reach the service.
connection_error: Option<String>,
/// The settings the service last reported, to adopt only its changes.
service_settings: Option<AppSettings>,
pane: Pane,
open: Option<Menu>,
// Settings
microphones: Result<Vec<String>, String>,
confirm_release: bool,
capture: Capture,
hints: TextEdit,
/// The model the service was last seen preparing, and since when.
preparing: Option<(TranscriptionModelId, Instant)>,
/// When a text field last changed without being saved.
draft_since: Option<Instant>,
models: models::Models,
voice_action_error: Option<String>,
history: history::HistoryPane,
modes: modes::ModesPane,
picker: picker::Picker,
tour: Option<onboarding::Tour>,
/// The OS's capabilities and the OS-only state its panes show.
platform: platform::PlatformState,
host: platform::PlatformHost,
commands: commands::CommandsPane,
meetings: meetings::MeetingsPane,
/// Settings saves and Quit Hex a fixture recorded.
saved: usize,
quit_requested: bool,
}
impl Ui {
fn load() -> Self {
let (settings, error) = match AppSettings::load() {
Ok(settings) => (settings, None),
Err(error) => (AppSettings::default(), Some(format!("{error:#}"))),
};
crate::desktop_i18n::apply(settings.ui_language.as_deref());
let mut ui = Self::with(settings, Service::Pending, error);
ui.history = history::HistoryPane::shared(host::history(ui.settings.history_retention));
ui.models = models::Models::load();
ui.modes.load_personal_commands();
ui.tour = onboarding::Tour::start(&ui.settings, &ui.platform);
ui.platform.set_login_item(host::launch_at_login());
ui
}
fn with(settings: AppSettings, service: Service, error: Option<String>) -> Self {
let hints = TextEdit::new(settings.transcription.recognition_hints.clone());
let modes = modes::ModesPane::new(&settings);
Self {
settings,
service,
view: None,
error,
connection_error: None,
service_settings: None,
pane: Pane::Settings,
open: None,
microphones: Ok(Vec::new()),
confirm_release: false,
capture: Capture::Idle,
hints,
preparing: None,
draft_since: None,
models: models::Models::default(),
voice_action_error: None,
history: history::HistoryPane::default(),
modes,
picker: picker::Picker::default(),
tour: None,
platform: platform::PlatformState::new(platform::Capabilities::current()),
host: platform::PlatformHost::None,
commands: commands::CommandsPane::default(),
meetings: meetings::MeetingsPane::default(),
saved: 0,
quit_requested: false,
}
}
fn live(&self) -> bool {
matches!(self.service, Service::Live(_))
}
fn send(&mut self, request: Request) {
match &mut self.service {
Service::Live(client) => {
if let Err(error) = client.send(request) {
self.error = Some(format!("{error:#}"));
}
}
Service::Fixture(sent) => sent.push(request),
Service::Pending => {}
}
}
/// Saves `settings.json` through the host, which adopts the change. A
/// failed save leaves the shown settings alone.
fn update(&mut self, change: impl FnOnce(&mut AppSettings)) -> bool {
let mut candidate = self.drafted();
change(&mut candidate);
self.commit(candidate)
}
fn commit(&mut self, candidate: AppSettings) -> bool {
match &mut self.service {
Service::Live(backend) => {
if let Err(error) = backend.save(&candidate) {
self.error = Some(format!("{error:#}"));
return false;
}
}
Service::Fixture(_) => self.saved += 1,
Service::Pending => {}
}
self.error = None;
self.settings = candidate;
self.draft_since = None;
true
}
/// The settings with every text field's current text applied.
fn drafted(&self) -> AppSettings {
let mut candidate = self.settings.clone();
if crate::transcription_models::definition(candidate.transcription.model)
.supports_recognition_hints
{
candidate.transcription.recognition_hints = self.hints.text.clone();
}
self.modes.project(&mut candidate);
candidate
}
/// Saves text-field edits once typing pauses for [`DRAFT_DELAY`].
fn save_drafts(&mut self, now: Instant) -> bool {
let candidate = self.drafted();
if candidate == self.settings {
self.draft_since = None;
return false;
}
let since = *self.draft_since.get_or_insert(now);
if now.duration_since(since) < DRAFT_DELAY {
return false;
}
self.commit(candidate)
}
/// Saves pending text-field edits now (leaving a pane or a mode).
fn flush_drafts(&mut self) {
let candidate = self.drafted();
if candidate != self.settings {
self.commit(candidate);
}
}
/// Asks the OS host for something only it can do.
fn ask(&mut self, request: platform::PlatformRequest) {
// Windows writes its Run key from the window's own process.
if let (
platform::PlatformHost::None,
platform::PlatformRequest::SetLaunchAtLogin(enabled),
) = (&self.host, &request)
{
let result = host::set_launch_at_login(*enabled);
self.platform.set_login_item(Some(result));
return;
}
if let Err(error) = self.host.send(request) {
self.error = Some(error);
}
}
fn running(&self) -> bool {
self.view.as_ref().is_some_and(|view| view.listener.running)
}
fn shortcuts(&self) -> Option<&DesktopShortcuts> {
self.view.as_ref().map(|view| &view.listener.shortcuts)
}
/// Without a shortcuts portal the desktop's keybindings own every
/// shortcut, so the window has none to record.
fn records_shortcuts(&self) -> bool {
self.shortcuts() != Some(&DesktopShortcuts::Commands)
}
/// Adopts settings another client or the service saved, unless they are
/// the stale copy of an edit this window just made.
fn adopt(&mut self, service: AppSettings) {
if self.service_settings.as_ref() == Some(&service) {
return;
}
if service != self.settings && self.draft_since.is_none() {
if service.transcription.recognition_hints
!= self.settings.transcription.recognition_hints
{
self.hints = TextEdit::new(service.transcription.recognition_hints.clone());
}
if service.dictation_processing != self.settings.dictation_processing {
self.modes.reload(&service);
}
self.settings = service.clone();
}
self.service_settings = Some(service);
}
/// Saves pending edits, then lets the host finish its work and exit.
fn quit(&mut self) {
self.flush_drafts();
settings::cancel_capture(self);
match &mut self.service {
Service::Live(backend) => backend.quit(),
Service::Fixture(_) => self.quit_requested = true,
Service::Pending => {}
}
}
fn select_pane(&mut self, pane: Pane) {
if self.pane == pane {
return;
}
self.flush_drafts();
settings::cancel_capture(self);
self.open = None;
self.pane = pane;
if pane == Pane::History {
self.history.reload();
}
}
}
/// Shortcut recording takes every key; otherwise Escape closes the picker
/// or the open menu.
fn on_key(ui: &mut Ui, event: &rune::KeyEvent, tx: &mut Tx) -> bool {
if settings::on_key(ui, event, tx) {
return true;
}
if event.key != rune::Key::Escape {
return false;
}
if ui.picker.language.is_some() {
picker::close(ui);
true
} else if ui.open.is_some() {
ui.open = None;
true
} else if ui.meetings.renaming.is_some() || ui.meetings.delete_armed.is_some() {
ui.meetings.renaming = None;
ui.meetings.delete_armed = None;
true
} else {
false
}
}
fn setup(ui: &mut Ui, waker: Waker) {
ui.modes.waker = Some(waker.clone());
if matches!(ui.service, Service::Pending) {
let wake: Arc<dyn Fn() + Send + Sync> = Arc::new(move || waker());
ui.service = Service::Live(Box::new(Backend::connect(wake)));
}
}
/// Runs before every frame: adopts service updates, follows shortcut
/// capture, model preparation, the OpenCode catalog, history, and setup, and
/// saves paused text edits. True when anything shown changed.
fn poll(ui: &mut Ui, _clock: f64, _tx: &mut Tx) -> bool {
let now = Instant::now();
let mut changed = settings::advance_capture(ui);
changed |= ui.save_drafts(now);
changed |= ui.models.poll(ui.live());
changed |= ui.history.poll(ui.pane == Pane::History);
changed |= ui.modes.poll(ui.live());
changed |= modes::poll_chooser(ui);
changed |= ui.host.poll(&mut ui.platform);
if let Service::Live(backend) = &mut ui.service {
backend.refresh();
let error = backend.error();
let (view, settings) = match backend.state() {
Some(state) => (Some(state.view), Some(state.settings)),
None => (None, None),
};
if error != ui.connection_error {
ui.connection_error = error;
changed = true;
}
if view != ui.view {
ui.view = view;
changed = true;
}
if let Some(settings) = settings {
let before = ui.settings.clone();
ui.adopt(settings);
changed |= before != ui.settings;
}
}
let preparing = ui
.view
.as_ref()
.and_then(|view| view.transcription.preparing);
if preparing != ui.preparing.map(|(model, _)| model) {
ui.preparing = preparing.map(|model| (model, now));
changed = true;
}
changed |= onboarding::poll(ui);
changed | settings::advance_capture(ui)
}
// ---------------------------------------------------------------------------
// View
fn view(ui: &Ui, cx: &mut Cx<Ui>) -> El {
let p = Paint::new(cx.system_dark(), cx.env().scale);
// Menus and popovers mount above the page (rune-kit overlays).
let mut layer = Vec::new();
let (actions, body) = match ui.pane {
Pane::Settings => (Vec::new(), settings::pane(ui, p, &mut layer)),
Pane::Modes => modes::pane(ui, p, &mut layer),
Pane::Commands => commands::pane(ui, p),
Pane::VoiceAction => (Vec::new(), voice_action::pane(ui, p, &mut layer)),
Pane::History => history::pane(ui, p, &mut layer),
Pane::Meetings => meetings::pane(ui, p, &mut layer),
};
let panel = col()
.key("panel")
.grow(1.0)
.shrink()
.mt(8.0)
.mr(8.0)
.mb(8.0)
.radius(p.k.radius.lg)
.fill(p.k.c.bg_base)
.border(p.hair, p.k.c.border_weak)
.clip_soft(0.0)
.child(pane_header(p, ui.pane.title(), actions))
.child(body);
let window = row()
.key("window")
.role("window")
.fill(p.k.c.bg_deep)
.child(sidebar(ui, p))
.child(panel);
if let Some(modal) = picker::modal(ui, p) {
layer.push(modal);
}
if let Some(tour) = onboarding::overlay(ui, p) {
layer.push(tour);
}
rune_kit::root(window, layer)
}
fn sidebar(ui: &Ui, p: Paint) -> El {
let mut nav = col().key("nav").gap(1.0);
for pane in Pane::ALL.into_iter().filter(|pane| pane.shown(ui)) {
nav = nav.child(nav_item(p, pane, ui.pane == pane));
}
let action = match ui.view.as_ref().map(|view| view.update_status) {
Some(DesktopUpdateStatus::ReadyToRestart) => Some(DesktopAction::RestartIntoUpdate),
Some(DesktopUpdateStatus::Available) => Some(DesktopAction::OpenUpdate),
_ => None,
};
let update = action.map(|action| {
controls::button(
p,
"sidebar-update",
tr("Update"),
controls::ButtonKind::Secondary,
move |ui: &mut Ui, _| ui.send(Request::Desktop(action.clone())),
)
});
col()
.key("sidebar")
.role("navigation")
.w(220.0)
.h_full()
.pt(12.0)
.pb(12.0)
.pl(10.0)
.pr(6.0)
.child(nav)
.child(el().key("spacer").grow(1.0))
.children(update)
.children(host::QUIT_IN_WINDOW.then(|| quit_item(p)))
.child(
text(tr_fill("Version {}", env!("CARGO_PKG_VERSION")))
.key("version")
.font(p.k.ty.small)
.color(p.faint())
.pl(6.0)
.pt(8.0),
)
}
fn nav_item(p: Paint, pane: Pane, on: bool) -> El {
let c = &p.k.c;
let mut item = row()
.key(pane.key())
.role("button")
.label(pane.title())
.h(28.0)
.px(6.0)
.gap(8.0)
.center_y()
.radius(p.k.radius.md)
.hover(c.hover)
.press(c.pressed)
.on_press(move |ui: &mut Ui| ui.select_pane(pane))
.child(icon(pane.icon(), 16.0).key("icon").color(if on {
c.icon_base
} else {
c.icon_muted
}))
.child(
text(pane.title())
.key("label")
.font(p.k.ty.ui)
.color(if on { c.text_base } else { c.text_muted })
.truncate(),
);
if on {
item = item.fill(c.layer_02);
}
item
}
/// Linux has no tray: the window's way to stop Hex. Closing the window
/// keeps Hex dictating.
fn quit_item(p: Paint) -> El {
let c = &p.k.c;
row()
.key("quit")
.role("button")
.label(tr("Quit Hex"))
.h(28.0)
.px(6.0)
.mt(4.0)
.center_y()
.radius(p.k.radius.md)
.hover(c.hover)
.press(c.pressed)
.on_press(|ui: &mut Ui| ui.quit())
.child(
text(tr("Quit Hex"))
.key("label")
.font(p.k.ty.ui)
.color(c.text_muted)
.truncate(),
)
}
/// The title bar of the content panel, with the pane's actions on the right.
fn pane_header(p: Paint, title: &str, actions: Vec<El>) -> El {
row()
.key("pane-header")
.h(52.0)
.px(24.0)
.gap(8.0)
.center_y()
.child(
text(title)
.key("pane-title")
.font(p.k.ty.body_medium)
.color(p.text())
.grow(1.0)
.truncate(),
)
.children(actions)
}
/// A vertically scrolling pane body with Settings' column inset.
fn scroll_body(key: &str, content: El) -> El {
col()
.key(key)
.grow(1.0)
.shrink()
.clip_fade(0.0, 4.0, 0.0, 24.0)
.scroll(ScrollSpec {
stick_bottom: false,
})
.child(content)
}
// ---------------------------------------------------------------------------
// Fixtures for snapshots and tests
/// A named starting state for `--scene`.
type Scene = (&'static str, fn(&mut Ui));
const SCENES: &[Scene] = &[
// The running service's real state, for headless snapshots and scripts
// (`--snap`): waits for its first snapshot instead of drawing
// "Connecting…" at virtual time zero.
("live", |ui| {
*ui = Ui::load();
let mut backend = Backend::connect(Arc::new(|| {}));
let deadline = Instant::now() + Duration::from_secs(5);
while backend.state().is_none() && backend.error().is_none() && Instant::now() < deadline {
std::thread::sleep(Duration::from_millis(25));
backend.refresh();
}
ui.service = Service::Live(Box::new(backend));
poll(ui, 0.0, &mut Tx::default());
}),
("portal", |ui| *ui = fixture(portal_shortcuts())),
("commands", |ui| *ui = fixture(DesktopShortcuts::Commands)),
("disabled", |ui| {
*ui = fixture(portal_shortcuts());
if let Some(view) = &mut ui.view {
view.listener.running = false;
view.listener.status = "Disabled".into();
}
}),
("capturing", |ui| {
*ui = fixture(portal_shortcuts());
ui.capture = Capture::Listening {
target: ShortcutTarget::Dictation,
message: None,
};
}),
("chinese", |ui| {
*ui = fixture(portal_shortcuts());
ui.settings.ui_language = Some("zh".into());
crate::desktop_i18n::apply(Some("zh"));
}),
("menus", |ui| {
*ui = fixture(portal_shortcuts());
ui.open = Some(Menu::Microphone);
ui.microphones = Ok(vec![
"Built-in Audio Analog Stereo".into(),
"Shure MV7".into(),
]);
ui.confirm_release = true;
}),
("voice-action", |ui| {
*ui = fixture(portal_shortcuts());
ui.settings.voice_action.enabled = true;
ui.pane = Pane::VoiceAction;
}),
("voice-action-off", |ui| {
*ui = fixture(portal_shortcuts());
ui.pane = Pane::VoiceAction;
}),
("voice-action-unavailable", |ui| {
*ui = fixture(portal_shortcuts());
ui.settings.voice_action.enabled = true;
ui.models = models::Models::fixture_missing();
ui.pane = Pane::VoiceAction;
}),
("voice-action-models", |ui| {
*ui = fixture(portal_shortcuts());
ui.settings.voice_action.enabled = true;
ui.pane = Pane::VoiceAction;
ui.open = Some(Menu::Model);
}),
("history", |ui| {
*ui = fixture(portal_shortcuts());
ui.history = history::HistoryPane::fixture();
ui.pane = Pane::History;
}),
("history-empty", |ui| {
*ui = fixture(portal_shortcuts());
ui.history = history::HistoryPane::fixture_empty();
ui.pane = Pane::History;
}),
("modes", |ui| {
*ui = fixture(portal_shortcuts());
modes::fixture(ui);
ui.pane = Pane::Modes;
}),
("modes-global", |ui| {
*ui = fixture(portal_shortcuts());
modes::fixture(ui);
ui.modes.select(modes::Selection::Default);
ui.pane = Pane::Modes;
}),
("modes-picker", |ui| {
*ui = fixture(portal_shortcuts());
modes::fixture(ui);
ui.modes.transformation_picker_open = true;
ui.modes.application_picker_open = true;
ui.pane = Pane::Modes;
}),
("picker", |ui| {
*ui = fixture(portal_shortcuts());
picker::fixture(ui, None);
}),
("picker-downloading", |ui| {
*ui = fixture(portal_shortcuts());
picker::fixture(ui, Some(TranscriptionModelId::CohereTranscribe));
}),
("onboarding", |ui| {
*ui = fixture(portal_shortcuts());
onboarding::fixture(ui, crate::onboarding::Step::Welcome, false);
}),
("onboarding-setup", |ui| {
*ui = fixture(portal_shortcuts());
onboarding::fixture(ui, crate::onboarding::Step::Setup, true);
}),
// macOS and Windows surfaces, from preview data (see `platform`).
("mac-settings", |ui| *ui = mac_fixture()),
("mac-settings-permissions", |ui| {
*ui = mac_fixture();
use crate::onboarding::PermissionState;
ui.platform.permissions.input_monitoring = PermissionState::NeedsSettings;
ui.platform.permissions.accessibility = PermissionState::NeedsSettings;
ui.platform
.permissions_asked
.push(crate::onboarding::PermissionKind::Accessibility);
ui.settings.commands_enabled = true;
ui.platform.command_model = platform::CommandModel::Failed;
ui.platform.login_item = Some(crate::login_item::LoginItemStatus::RequiresApproval);
}),
("windows-settings", |ui| {
*ui = fixture(DesktopShortcuts::Registered);
ui.platform = platform::PlatformState::preview(platform::Capabilities::WINDOWS);
ui.host = platform::PlatformHost::Fixture(Vec::new());
ui.settings.paste_with_shift = false;
}),
("mac-commands", |ui| {
*ui = mac_fixture();
ui.settings.commands_enabled = true;
ui.pane = Pane::Commands;
}),
("mac-commands-confirm", |ui| {
*ui = mac_fixture();
ui.settings.release_microphone_while_idle = true;
ui.commands.confirm_enable = true;
ui.platform.workspace = platform::Workspace::Missing;
ui.commands.search = TextEdit::new("zzz");
ui.pane = Pane::Commands;
}),
("meetings", |ui| {
*ui = mac_fixture();
ui.pane = Pane::Meetings;
}),
("meetings-recording", |ui| {
*ui = mac_fixture();
ui.meetings.select("preview-live".into());
ui.pane = Pane::Meetings;
}),
("meetings-actions", |ui| {
*ui = mac_fixture();
ui.open = Some(Menu::MeetingActions);
ui.pane = Pane::Meetings;
}),
("meetings-delete", |ui| {
*ui = mac_fixture();
ui.meetings.delete_armed = Some("preview-notes".into());
ui.pane = Pane::Meetings;
}),
("meetings-rename", |ui| {
*ui = mac_fixture();
ui.meetings.renaming = Some("preview-notes".into());
ui.meetings.rename = TextEdit::new("Arcade launch plan");
ui.pane = Pane::Meetings;
}),
("meetings-failed", |ui| {
*ui = mac_fixture();
ui.meetings.select("preview-failed".into());
ui.pane = Pane::Meetings;
}),
("meetings-empty", |ui| {
*ui = mac_fixture();
ui.meetings = meetings::MeetingsPane::default();
ui.pane = Pane::Meetings;
}),
("mac-onboarding", |ui| {
mac_tour(ui, onboarding::MacStep::Welcome)
}),
("mac-onboarding-setup", |ui| {
mac_tour(ui, onboarding::MacStep::Setup)
}),
("mac-onboarding-progress", |ui| {
mac_tour(ui, onboarding::MacStep::SetupProgress)
}),
("mac-onboarding-denied", |ui| {
mac_tour(ui, onboarding::MacStep::SetupDenied)
}),
("mac-onboarding-download-failed", |ui| {
mac_tour(ui, onboarding::MacStep::SetupDownloadFailed)
}),
("mac-onboarding-try", |ui| {
mac_tour(ui, onboarding::MacStep::TryIt)
}),
("mac-onboarding-listening", |ui| {
mac_tour(ui, onboarding::MacStep::TryItListening)
}),
("mac-onboarding-landed", |ui| {
mac_tour(ui, onboarding::MacStep::TryItLanded)
}),
("mac-onboarding-reopen", |ui| {
mac_tour(ui, onboarding::MacStep::TryItReopen)
}),
("mac-onboarding-done", |ui| {
mac_tour(ui, onboarding::MacStep::Done)
}),
];
/// The macOS window with every permission granted, meetings on, the Hex
/// Microphone experiment on, and sample meetings and commands.
fn mac_fixture() -> Ui {
let mut ui = fixture(DesktopShortcuts::Registered);
ui.platform = platform::PlatformState::preview(platform::Capabilities::MACOS);
ui.host = platform::PlatformHost::Fixture(Vec::new());
ui.settings.dictation_hotkey = AppSettings::default().dictation_hotkey;
ui.settings.paste_with_shift = false;
ui.settings.meetings.enabled = true;
ui.settings.meetings.never_offer = vec![crate::app_settings::NeverOfferMeeting {
key: "meet.google.com".into(),
label: "meet.google.com".into(),
}];
ui.settings.experimental.hex_microphone = true;
ui.meetings = meetings::MeetingsPane::fixture();
ui
}
fn mac_tour(ui: &mut Ui, step: onboarding::MacStep) {
*ui = mac_fixture();
onboarding::mac_fixture(ui, step);
}
fn portal_shortcuts() -> DesktopShortcuts {
DesktopShortcuts::Portal(vec![
DesktopGrantedShortcut {
name: "Dictation".into(),
trigger: Some("F12".into()),
},
DesktopGrantedShortcut {
name: "Paste last dictation".into(),
trigger: Some("Ctrl+Alt+V".into()),
},
])
}
/// Deterministic settings and service state matching a typical Wayland
/// desktop with the shortcuts portal.
fn fixture(shortcuts: DesktopShortcuts) -> Ui {
crate::desktop_i18n::apply(Some("en"));
let settings = AppSettings {
dictation_hotkey: HotkeyBinding {
modifiers: HotkeyModifiers::default(),
key: Some(HotkeyKey::named("f12")),
},
transcription: crate::transcription_models::TranscriptionSelection {
model: TranscriptionModelId::ParakeetUnifiedEnglish,
language: "en".into(),
recognition_hints: String::new(),
},
paste_with_shift: true,
..AppSettings::default()
};
let mut ui = Ui::with(settings, Service::Fixture(Vec::new()), None);
ui.models = models::Models::fixture();
ui.picker.installed = Some(vec![TranscriptionModelId::ParakeetUnifiedEnglish]);
ui.view = Some(ServiceView {
listener: DesktopListenerSnapshot {
running: true,
status: "Enabled".into(),
warning: None,
shortcuts,
},
operation_error: None,
transcription: DesktopTranscriptionSnapshot {
downloaded_bytes: 0,
error: None,
preparation_stage: None,
selection: ui.settings.transcription.clone(),
preparing: None,
},
update_status: DesktopUpdateStatus::Current,
editing: false,
});
ui
}
#[cfg(all(test, target_os = "linux"))]
mod tests;