hex/src/rune_ui/onboarding_kit/permissions.rs
Kit Langton c84998da53
feat(onboarding): the first run is one story, from a bad conversation to your first words (#1501)
* Onboarding: slower Without Hex comedy with a start button, a real conversation, and one focus at a time

* Onboarding comedy v2: Launch Room, visible slip, rewind into Hex

Jay's question is up before the click and the first reply comes 0.35 s after
it. The deady/dead slip holds long enough to read, then Return flashes red
with a heavy clunk. The scene is one iMessage group: the removal is a red pill
that wipes a frantic draft mid-word and locks the field. With Hex rewinds the
disaster, melts the keys down to the lit shortcut, and raises the HUD before
the key goes down. The caret no longer sits under a word as it lands. Adds
original chat sounds, a score counted in whole seconds with a chime, and a
live first run that waits for Continue.

* Onboarding comedy v3: one-way melt, clean act breaks, upward rewind, Skip

* Test that Skip appears two seconds in and leaves the comedy

* Fill the keyboard's pocket back in once the HUD has gone

* Onboarding comedy v4 engine: presenting pill, tapbacks, heartbeat, slow motion and the autocorrect slam

* Onboarding: scenes as plain-text files, with a celebration in With Hex

Each scene sets its own room, people, pill, ending and With Hex payoff
(replies, tapbacks, status pills, confetti and fireworks with their own
sounds). The validator reports line-numbered mistakes and the limits a
scene can hold.

* Scenes: document the limits and the folder check

* Onboarding: tapbacks stay on the line above, the pill keeps its own row, and With Hex can change it

* Polish the practice game: themed messages, transcript and high score, real Dot scope, logo build, Replay onboarding

* Scene folder check prints every scene's length

* Flush the ready soundtrack once the logo is built

* Scenes: only the theme's colours, and a clear error for any other

* Check the whole Advanced fold, down to Replay onboarding

* C-plus: v3's scene with the over-the-top With Hex

* Drop the whole-pixel bob now that Rune glides text with its box

* Onboarding chat: the real Messages sounds from macOS, pill in the header

Received, sent and each tapback's sound load at run time from macOS's own files, peak-matched to Hex's stand-ins, which still play where a file is missing and off macOS. The presenting pill moves into the conversation header, level with the title.

* Follow the dictation/ move, and keep a resized golden's render for CI

* Onboarding: keep Reply::Lines' shape so the game's card is untouched

The autocorrect mark goes to chat() as its own argument, and notice() draws sent_bubbles again as dev does.

* Golden: the whole Advanced fold, down to Replay onboarding

* Onboarding comedy: Model M typing, a real heartbeat, three triumph takes

The Without Hex keys are now cut from a CC0 recording of an IBM Model M
(scripts/sounds/comedy/SOURCE.md): eight presses at three pitches, a
deeper space bar and a heavier delete, each at a slightly different level,
whatever key sound the reader picked. The heartbeat is a synthesized
lub-dub under the clicks (HEX_ONBOARDING_HEARTBEAT=off drops it), and
HEX_ONBOARDING_TRIUMPH=1..3 picks brass, a chime run, or a cheer and pop.
scripts/sounds/comedy.py rebuilds them all.

* Follow dev: audio::input_level, and drop Labs' last icon_row import

* Onboarding comedy: tapbacks drawn like Messages

Round badges on the bubble's top corner with a ring in the card's colour
and two tail dots, grey for other people and blue for the reader's own,
every glyph a vector shape including the two-line HA HA. Stacks put the
newest on top. Prototypes/Onboarding/Tapbacks shows them all.

* Move the game's pieces into game/ and its share card into game/share.rs for the code-shape gate

* Labs: hold Paste last dictation to pick recent dictations (macOS)

* Unify the first run: Without Hex, microphone, the practice game, Accessibility

* Let the first run story play itself, game included

* Count the sound cues' third field in the logo-build tests

* Sound the comedy's triumph on the game's first score; Hex Test.app opens the new first run

* Move the stories' side panel into stories/side.rs for the code-shape gate

* First run: play the scripted With Hex payoff after Without Hex; start the heartbeat at the first typo

* Onboarding round 2: Launch Room inbox row, Messages-style senders, ending hold, float-off grants, idle HUD pill, Launch at login on Ready, Settings guide reopen

* Start the heartbeat at the first sent typo, much quieter

* Open the Launch Room like an island: a pointer clicks the row and it grows into the chat

Every first run autoplays: the row arrives with two even rings, a scripted
pointer glides in and presses it, and the row grows into the conversation
(width first, then height, on one straight path) while the group's faces,
the title and Jay's question fly over as themselves. The rest fades in once
the flights clear. Reduce Motion fades instead.

* Add a replay strip to the first run in test and debug builds

Restart, Back one beat, Joke (cycles the bundled scenes) and a fake
download speed (real, 100 Mbps, 25 Mbps; Restart downloads again at it).
Every build logs how long the download showed for. The swearing scenes A
and B are only in builds with hex_dev_onboarding (debug or HEX_TEST_BUILD=1).

* First run: Watch another one while the model downloads

Almost ready shows the download as a quiet bar with its size and time
left, and a button that plays one of three short Without Hex sketches.
The bar moves to the top pill while one plays; a finished download goes
on to the game at the sketch's next stop, after a reply has gone out.
The button goes once all three have played.

* First run: a whole-run story with a slow download and a sketch

* Onboarding: sound for the whole first run, the Launch Room opens itself, and a motion gate

- SfxTrack::clear keeps cues already fired, so the offline track keeps its first 73 s; the scripted game, the words and the cards burning get cues.
- The download pill no longer flies over the words it passes; the Launch Room opens itself 5 s after it parks.
- A motion gate over the first run in dark, light and Reduce Motion, plus a pixel check of the conversation opening: fixes its surface blinking as the plate hands over, Jay's doubled typing dots, the badge's one-frame pop and the preview's text swap.

* Onboarding: the Launch Room's click taps, whether a person or the pointer clicks

* Rune e6371c48: the motion gate checks what the first run paints

- Bump rune, rune-kit, rune-theme-opencode and rune-motion to e6371c48 (rune#71); nix outputHash follows.
- Mark the first run's deliberate motion where it's written (tapback bounces, the badge pop, keys, the game's shake) and narrow the allowlist to scoped, capped rows.
- The empty avatar slot keeps its border while its fill fades, so the ring no longer vanishes a frame early.

* Onboarding: the first run's clock runs on drawn frames, and its later pipelines warm on a thread (t1328)

* Onboarding: call out keyboard and voice-first modes, punch in on autocorrect, prototype first-screen backdrops

* Onboarding: drop the first-screen backdrop prototypes (t1328)

* Onboarding: prototype a bigger HUD and an up-next row on Setting up Hex (t1328)

* Onboarding: the Linux tests' page helper knows the two permission steps (t1328)

* Onboarding goldens: the voice-first chip beside the heading (t1328)

* Onboarding: first-screen prototype shows download size and an on-device note (t1328)

* Onboarding: the first screen shows download size and that your voice stays on this Mac (t1328)

* Onboarding: a failed download drops the size and privacy line; goldens for the first screen (t1328)

* Onboarding: drop the render scratch the branch carried

673 frames and one-off scripts under .render/ were the scratch of the
session that built this, not part of the change.

* Keep render scratch and scene stills out of the tree

* Onboarding: the scene tests that need a dev-only scene skip release builds

A and B swear, so release builds leave them out of the bundle; two tests
still asked for A by name and panicked where it was missing (the Nix
package's test run).

* Onboarding: goldens from the Linux run after the merge

Seventeen onboarding renders moved: the first screen's download size and
privacy line, the mic line from #1420, and dark text that sits a few pixels
lower with dev's Rune pin.

* Onboarding: a tighter opening and fireworks that light the page

The first run's Setting up Hex holds a second, then the Launch Room's
conversation is there as the download flies up: Jay's messages land in
it with their sounds instead of on an inbox row a pointer clicks open.
The Keyboard mode stamp goes (the heading's chip says it), Without Hex's
heading is one line, and the privacy line also shows on the microphone
step.

With Hex's fireworks move to the GPU: three shells rise on trails and
burst beside the conversation into a few hundred sparks each, white-hot
to hue to crackling embers under drag and gravity. Each burst lights
the page under it for a moment, multiplying what's drawn so surfaces
brighten by their own colour and the dark page barely does. Reduce
Motion gets one soft flash. The shipping scene drops its confetti.

* Onboarding: sketches keep their own opening; the motion gate follows the shorter intro

Sketches built their scenes from the first run's timing, so its shorter
opening reached them. The slow-download fixture lands the model 6.8 s
sooner, as much as the intro shrank, so the gate's windows see the same
story; the practice game's shake can still be moving as the handoff
window ends.

* Fireworks: stars light as they leave the break, the shell's glitter is quieter, and the page light fades with no edge

* Onboarding: fireworks in depth, and three compositions to compare

Fireworks burst in two layers. Far shells sit behind the conversation,
smaller, dimmer and softer, lighting it a little; near shells draw in
front, bigger and brighter, their sparks falling across the card's
edges for a moment and their light hitting it hard, with their cores
kept beside it. A break opens as a bloom: packed stars share its light
until the shell has spread, since sRGB-encoded blending adds a hundred
faint stars up to a white disc.

The demo's composition is now a layout the run picks, as it picks its
scene, with three playground variants beside today's: A, a tighter
centre (one two-line heading for both scenes, a larger conversation,
the keyboard tucked under it, Skip in the corner); B, a split (the
mode, a big title and one line in a left column, the conversation and
its keyboard on the right, the fireworks in the open page); and C, a
laptop (the conversation as its screen, the keyboard on its deck).
Today's layout is unchanged.

* Onboarding: the score pill hugs its count, and a near burst's break stays compact

The practice game's score pill was a fixed 112 pt with its content left
aligned, so "1 destroyed" sat 12 pt from its left edge and about 40 pt
from its right. It's now as wide as its number and label need, with
12 pt either side in every language, and the share card folds back to
that width. A near burst's bloom no longer spreads into a wide, faint,
whitish disc that read as smoke. Headless renders take
HEX_RENDER_LANGUAGE to check copy in another language.

* feedback: the onboarding's cues in their own file, under the size limit

* Onboarding: the card's landing nudge is a kick, and the motion gate gets the time it needs

* Onboarding: goldens after dev's language-switch change and the microphone step's privacy line; the playground's two-line heading stays English

* Onboarding motion: the game's idle pill fades on its clock, sent bubbles leave the field whole, and the Accessibility helper line fades out

From per-frame traces of the whole scripted run:

- The practice game's stage lands every change at once, so the idle
  pill's springs never ran: it vanished and reappeared in one frame at
  every take, and when the score card came and went. Its fade and
  settle are now worked out on the game's clock, from when the scope
  last came or went, and it steps aside with the chrome.
- A sent line is launched out of the field, but its bubble faded in on
  its own, so each send started as a ghost of the text it left (five
  sends in Without Hex, the spoken answer in With Hex). The bubble now
  enters with its line.
- The escaping Accessibility panel dropped its "Accessibility helper"
  line in one frame; it fades as the panel starts to move.

* Onboarding motion: the idle pill's spring is settled before the first take, not NaN

* Onboarding motion: a sent bubble's words leave the field at full strength too

* Onboarding fireworks: a burst opens on a point of light, not a grey disc

The bang was a wide glow at a quarter of white, which sRGB-encoded
blending flattens into a grey-beige disc for three frames before the
stars show. It is now small and brighter than white, gone as they open.
On light pages the bursts' tint has a soft shoulder instead of a flat
plateau of colour, and sparks paint a deeper hue so gold shows on white.

* Onboarding copy: the certificate's sentence, the game's full stop, Accessibility's row on one line

- "I hereby certify that I have completed Hex onboarding."
- The game's lead ends its sentence, as every other lead does.
- Accessibility's row drops "in any app", which the line above it
  says: allowed, it wrapped and left "app" alone on a second line.
- The permission pages' headings are translated like their titles.

* Onboarding: alignment and one main action

- Skip steps aside while autocorrect's camera is pushed in: the
  keyboard swelled down over it.
- The score card's two lines sit on the middle of the number.
- The score pill is as tall as Done beside it.
- Hex is ready keeps one contrast button: beside Start using Hex,
  Launch at login is a neutral one.

* Onboarding pacing: Setting up Hex holds long enough to read, the removal holds once

Setting up Hex held 1.0 s before the download flew up; 1.6 s reads.
The first run held the removal for the scene's own 2.0 s and 1.6 s
more, 3.6 s of silence; now 2.8 s.

The game's screen shake is marked where it's written, a kick and
steps, rather than allowed by where a gate window happens to end.

* Onboarding: the certificate in its own file, and no unused import

The motion fixes took game.rs past its size ceiling and left Spring
imported with no use; the certificate moves out to game/certificate.rs.

* Onboarding goldens: the game's full stop, and Launch at login beside Start using Hex
2026-11-09 17:29:51 -08:00

1142 lines
36 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! The permission steps of `"Prototypes/Onboarding/First run"`: the
//! microphone before the practice and Accessibility after it, featuring:
//!
//! - One `440 pt` column shared by Hex's setup card, System Settings, and the
//! floating drag guide, with every app icon aligned on one vertical spine
//! (`x = 26 pt`).
//! - Calm, zero-bounce permission state pills (`Allow` -> `Asking…` ->
//! `✓ Allowed`) with no harsh blinking or glow.
//! - Escaping Accessibility panel: when Accessibility is requested, the helper
//! panel inside Hex's card detaches, leaving a recessed outline socket
//! behind, and floats down across the screen to dock underneath System
//! Settings. Then the Hex row lifts cleanly out of that guide into an
//! expanding slot in System Settings' Accessibility list.
use rune::{
Anim, Color, El, MotionIntent, Spring, TextStyle, Transition, col, el, icon, row, text,
};
use rune_kit::{Button, ButtonVariant, glyphs};
use super::super::controls::{Paint, PushSize};
use super::super::paste_access::PasteAccess;
use super::flows::continue_button;
use super::hex_meter::hex_meter;
use super::landing::{LEAD, Motion, arrives, title_font};
use super::live::Live;
use super::stories::{Onboard, Step};
use crate::desktop::i18n::tr;
use crate::desktop::onboarding::{ItemStatus, SetupItem};
/// Total duration of the automated permissions step.
pub(crate) const PERMISSIONS_SECS: f64 = 7.2;
/// The automated microphone step.
pub(crate) const MIC_SECS: f64 = MIC_FLOAT + FLOAT_OFF + 0.05;
/// An allowed permission's check holds this long; then its card lets go
/// and floats off upward for this long before the next page comes in.
pub(crate) const GRANTED_BEAT: f64 = 0.6;
pub(crate) const FLOAT_OFF: f64 = 0.7;
const MIC_FLOAT: f64 = MIC_GRANT + GRANTED_BEAT;
const AX_FLOAT: f64 = SETTINGS_CLOSE + 0.2;
/// Where the Accessibility step starts on the shared timeline, and how
/// long it then runs.
pub(crate) const AX_SHIFT: f64 = AX_TRAY_OPEN - 0.6;
pub(crate) const AX_SECS: f64 = PERMISSIONS_SECS - AX_SHIFT;
const COL_W: f32 = 440.0;
const STAGE_H: f32 = 424.0;
const ACTION_H: f32 = 32.0;
// Timeline beats (seconds since `permissions_from`).
const MIC_ASK: f64 = 0.85;
const MIC_PRESS: f64 = 1.75;
pub(crate) const MIC_GRANT: f64 = 2.10;
const AX_TRAY_OPEN: f64 = 2.25;
pub(crate) const AX_ESCAPE: f64 = 2.85;
const AX_DOCKED: f64 = 3.55;
const DRAG: (f64, f64) = (3.85, 4.75);
const SWITCH_ON: f64 = 4.90;
pub(crate) const AX_GRANT: f64 = 5.15;
const SETTINGS_CLOSE: f64 = 5.80;
const CONTINUE_AT: f64 = 6.00;
const MIC_CONTINUE: f64 = 2.45;
// Unified geometry inside the `440 pt` stage.
const ROW_H: f32 = 58.0;
const SOCKET_TRAY_H: f32 = 52.0;
const SOCKET_RECT: [f32; 4] = [12.0, 2.0 * ROW_H + 6.0, COL_W - 24.0, 38.0];
const SETTINGS_Y: f32 = 2.0 * ROW_H + SOCKET_TRAY_H + 14.0; // 182.0
const SETTINGS_H: f32 = 152.0;
const LIST_INSET: f32 = 16.0;
const LIST_Y: f32 = 54.0;
const LIST_W: f32 = COL_W - 2.0 * LIST_INSET; // 408.0
const LIST_ROW_H: f32 = 28.0;
const ROW_PX: f32 = 10.0; // App icons sit at `16.0 + 10.0 = 26.0` everywhere!
const GUIDE_Y: f32 = SETTINGS_Y + SETTINGS_H + 10.0; // 344.0
const GUIDE_H: f32 = 70.0;
const PROMPT_W: f32 = 276.0;
const MIC_STAGE_H: f32 = ROW_H + 18.0 + 214.0;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum PermState {
Allow { primary: bool },
Asking,
Allowed,
}
pub(crate) fn state_at(e: f64, ask: f64, grant: f64, primary: bool) -> PermState {
if e < ask {
PermState::Allow { primary }
} else if e < grant {
PermState::Asking
} else {
PermState::Allowed
}
}
/// How far an allowed card has floated off, `e` seconds into its page.
fn float_u(e: f64, from: f64) -> f32 {
((e - from) / FLOAT_OFF).clamp(0.0, 1.0) as f32
}
/// An allowed card letting go: a small dip as it detaches, then up and
/// away, faster as it goes, shrinking and fading into the void.
fn float_off(card: El, u: f32, reduced: bool) -> El {
if u <= 0.0 {
return card;
}
if reduced {
return card.opacity(1.0 - u).opacity_motion(Anim::INSTANT);
}
const DIP: f32 = 0.16;
let (y, scale) = if u < DIP {
let d = (std::f32::consts::PI * u / DIP).sin();
(5.0 * d, 1.0 + 0.025 * d)
} else {
let v = (u - DIP) / (1.0 - DIP);
(-460.0 * v * v - 40.0 * v, 1.0 - 0.14 * v)
};
let v = ((u - DIP) / (1.0 - DIP)).max(0.0);
card.offset(0.0, y)
.offset_motion(Anim::INSTANT)
.scale(scale)
.scale_motion(Anim::INSTANT)
.rotate(-0.05 * v * v)
.rotate_motion(Anim::INSTANT)
.blur(6.0 * v * v)
.blur_motion(Anim::INSTANT)
.opacity(1.0 - smoothstep((v - 0.25) / 0.75))
.opacity_motion(Anim::INSTANT)
}
fn smoothstep(t: f32) -> f32 {
let t = t.clamp(0.0, 1.0);
t * t * (3.0 - 2.0 * t)
}
fn lerp(a: f32, b: f32, t: f32) -> f32 {
a + (b - a) * t
}
pub(super) fn page(p: Paint, s: &Onboard) -> El {
let which = if s.step == Step::Accessibility {
Perm::Accessibility
} else {
Perm::Microphone
};
if let Some(live) = &s.live {
return live_page(p, live, s, which);
}
let e = s.permissions_from.map_or(0.0, |from| s.now - from);
let reduced = s.reduced.get();
let (stage, continue_at) = match which {
Perm::Microphone => (
microphone_stage(p, e, state_at(e, MIC_ASK, MIC_GRANT, true), reduced),
MIC_CONTINUE,
),
// Accessibility joins the shared timeline where its tray opens.
Perm::Accessibility => {
let e = e + AX_SHIFT;
let ax = state_at(e, AX_ESCAPE, AX_GRANT, true);
(
stage(p, e, PermState::Allowed, ax, reduced),
CONTINUE_AT - AX_SHIFT,
)
}
};
col()
.key("permissions")
.gap(22.0)
.items_center()
.child(heading(p, s.motion, which))
.child(s.motion.staggered(stage, 1.0, 8.0))
.child(
row()
.key("action")
.h(ACTION_H)
.center()
.child(if e >= continue_at {
continue_button(p, s)
} else {
el().key("none")
}),
)
}
/// Which permission a page asks for: the microphone before the practice,
/// Accessibility after it.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum Perm {
Microphone,
Accessibility,
}
fn heading(p: Paint, motion: Motion, which: Perm) -> El {
let (title, lead) = match which {
Perm::Microphone => (
tr("Let Hex hear you"),
tr("Hex listens only while you hold your shortcut."),
),
Perm::Accessibility => (
tr("Make it work everywhere"),
tr("Let Hex notice your shortcut and type your words in any app."),
),
};
heading_with(p, motion, which, title, lead)
}
fn heading_with(p: Paint, motion: Motion, which: Perm, title: &str, lead: &str) -> El {
let key = match which {
Perm::Microphone => "microphone-head",
Perm::Accessibility => "accessibility-head",
};
motion.heading(
col()
.key(key)
.gap(8.0)
.items_center()
.child(text(title).key("title").font(title_font(p)).color(p.text()))
.child(
text(lead)
.key("lead")
.font(LEAD)
.color(p.muted())
.align(rune::Align::Center),
),
)
}
/// The microphone alone: Hex's row, then macOS's prompt under it.
fn microphone_stage(p: Paint, e: f64, mic: PermState, reduced: bool) -> El {
let k = p.k;
let card = col()
.key("setup-card")
.motion_intent(MotionIntent::BOUNCE)
.absolute(0.0, 0.0)
.w(COL_W)
.radius(k.radius.lg)
.fill(k.c.bg_base)
.border(p.hair, k.c.border_weak)
.child(perm_row(
p,
"mic-row",
&glyphs::MIC,
"Microphone",
"Hears you while you hold the shortcut",
perm_pill(p, "mic-pill", mic),
));
let mut stage = el()
.key("microphone-stage")
.size(COL_W, MIC_STAGE_H)
.child(float_off(
k.elevate(card, &k.elevation.raised),
float_u(e, MIC_FLOAT),
reduced,
));
if (MIC_ASK..MIC_GRANT).contains(&e) {
stage = stage.child(
microphone_prompt(p, e >= MIC_PRESS)
.absolute((COL_W - PROMPT_W) * 0.5, ROW_H + 18.0)
.transition(arrives()),
);
}
stage
}
/// The real first run's permissions: macOS's own prompt and System Settings
/// with Hex's guide, and the rows follow what macOS reports.
fn live_page(p: Paint, live: &Live, s: &Onboard, which: Perm) -> El {
let motion = s.motion;
if let Some(paste) = live.paste {
return paste_page(p, paste, motion);
}
let k = p.k;
let mic_ready = live.microphone == ItemStatus::Ready;
let windows = !live.accessibility_row;
let mic_desc = match live.microphone {
ItemStatus::Denied | ItemStatus::Waiting if windows => {
tr("Turn on “Let desktop apps access your microphone” in Windows Settings.")
}
ItemStatus::Denied => tr("Switch on Hex in System Settings"),
_ if live.release_microphone => tr("Opens only while you dictate"),
_ if windows => tr("Ready the moment you press the shortcut"),
_ => tr(
"Ready the moment you press the shortcut. macOS shows the mic in use while Hex runs; you can change that in Settings",
),
};
let mic_row = perm_row(
p,
"mic-row",
&glyphs::MIC,
tr("Microphone"),
mic_desc,
live_pill(
p,
"mic-pill",
live,
live.microphone,
true,
SetupItem::Microphone,
),
);
let card = card(p);
// An allowed microphone has already floated off by Accessibility.
let card = match which {
Perm::Accessibility if mic_ready => card,
_ => card.child(mic_row),
};
let card = match which {
Perm::Accessibility if live.accessibility_row => {
let ax_desc = match live.accessibility {
ItemStatus::Stale => tr("An older Hex entry can keep this off"),
ItemStatus::Waiting => tr("Switch on Hex in System Settings"),
ItemStatus::Restart => tr("Turns on when Hex restarts"),
_ => tr("Notices the shortcut and pastes your words"),
};
card.children((!mic_ready).then(|| separator(p, "sep0")))
.child(perm_row(
p,
"ax-row",
&glyphs::CURSOR_TEXT,
super::super::platform_settings::accessibility_name(live.accessibility_renamed),
ax_desc,
live_pill(
p,
"ax-pill",
live,
live.accessibility,
mic_ready,
SetupItem::Accessibility,
),
))
}
_ => card,
};
let action = if live.restart {
Button::new(tr("Restart Hex"))
.variant(ButtonVariant::Contrast)
.on_press(super::live::restart_hex)
.build_push(k)
.key("restart")
.default_button()
.transition(arrives())
} else {
el().key("none")
};
let head = if windows {
heading_with(
p,
motion,
which,
tr("Let Hex hear you"),
tr("Windows has the microphone turned off for desktop apps."),
)
} else {
heading(p, motion, which)
};
let relaunch = live.relaunch_failed.then(|| {
text(tr(
"Quit and reopen Hex to finish setup. macOS applies some permissions only after a restart.",
))
.key("relaunch-notice")
.font(LEAD)
.color(p.muted())
.align(rune::Align::Center)
.wrap()
.w(COL_W)
.transition(arrives())
});
col()
.key("permissions")
.gap(22.0)
.items_center()
.child(head)
.child(float_off(
motion.staggered(k.elevate(card, &k.elevation.raised), 1.0, 8.0),
live.floated(which == Perm::Accessibility, s.now),
s.reduced.get(),
))
.children(relaunch)
.child(row().key("action").h(ACTION_H).center().child(action))
}
/// GNOME and KDE on Wayland: Hex pastes through the desktop's
/// RemoteDesktop portal, whose dialog asks once (#932). This page says what
/// it is for before Allow opens it.
fn paste_page(p: Paint, paste: PasteAccess, motion: Motion) -> El {
let k = p.k;
let desc = if paste == PasteAccess::Declined {
tr("Without it, Hex copies your words and you press Ctrl+V.")
} else {
tr("Hex only sends the paste keystroke. It never sees your screen.")
};
let allow = |label: &str, primary: bool| {
Button::new(label)
.variant(if primary {
ButtonVariant::Contrast
} else {
ButtonVariant::Neutral
})
.on_press(super::live::allow_paste)
.build_push(k)
.key("paste-pill-allow")
.transition(arrives())
};
let control = match paste {
PasteAccess::Ask | PasteAccess::Later => allow(tr("Allow"), true),
PasteAccess::Asking => perm_pill(p, "paste-pill", PermState::Asking),
PasteAccess::Allowed => perm_pill(p, "paste-pill", PermState::Allowed),
PasteAccess::Declined => allow(tr("Try again"), false),
};
let card = card(p).child(perm_row(
p,
"paste-row",
&glyphs::CURSOR_TEXT,
tr("Paste into apps"),
desc,
control,
));
let action = if paste == PasteAccess::Declined {
Button::new(tr("Continue"))
.variant(ButtonVariant::Contrast)
.on_press(super::live::paste_later)
.build_push(k)
.key("paste-later")
.transition(arrives())
} else {
el().key("none")
};
col()
.key("permissions")
.gap(22.0)
.items_center()
.child(motion.heading(
col()
.key("permissions-head")
.gap(8.0)
.items_center()
.child(
text(tr("Let Hex paste for you"))
.key("title")
.font(title_font(p))
.color(p.text()),
)
.child(
text(tr("Hex needs this to type your words into your apps. Your desktop asks once, and may call it remote desktop."))
.key("lead")
.font(LEAD)
.color(p.muted())
.align(rune::Align::Center)
.wrap()
.w(COL_W),
),
))
.child(motion.staggered(k.elevate(card, &k.elevation.raised), 1.0, 8.0))
.child(row().key("action").h(ACTION_H).center().child(action))
}
fn live_pill(
p: Paint,
key: &str,
live: &Live,
status: ItemStatus,
primary: bool,
item: SetupItem,
) -> El {
let k = p.k;
let allow = |label: &str, primary: bool| {
Button::new(label)
.variant(if primary {
ButtonVariant::Contrast
} else {
ButtonVariant::Neutral
})
.on_press(super::live::allow(item))
.build_push(k)
.key(format!("{key}-allow"))
.transition(arrives())
};
let settings = if live.accessibility_row {
tr("Open System Settings")
} else {
tr("Open Settings")
};
match status {
ItemStatus::Ready => perm_pill(p, key, PermState::Allowed),
ItemStatus::Todo => allow(tr("Allow"), primary),
ItemStatus::Denied => allow(settings, primary),
// Pressing again reopens the prompt or Settings.
ItemStatus::Waiting => allow(tr("Open"), false),
ItemStatus::Stale => allow(tr("Still grey? Fix it"), false),
ItemStatus::Restart => row()
.key(format!("{key}-restart"))
.h(28.0)
.px(6.0)
.center_y()
.transition(arrives())
.child(
text(tr("Needs a restart"))
.key("lbl")
.font(k.ty.small_medium)
.color(p.muted()),
),
ItemStatus::Downloading(_) | ItemStatus::Failed => el().key(format!("{key}-none")),
}
}
fn stage(p: Paint, e: f64, mic: PermState, ax: PermState, reduced: bool) -> El {
let tray_open = (AX_TRAY_OPEN..SETTINGS_CLOSE).contains(&e);
let escaped = e >= AX_ESCAPE;
let settings_open = (AX_ESCAPE..SETTINGS_CLOSE).contains(&e);
let mut stage = el().key("permissions-stage").size(COL_W, STAGE_H);
// 1. Hex's own permissions card at the top of the `440 pt` column.
stage = stage.child(float_off(
setup_card(p, mic, ax, tray_open, escaped),
float_u(e, AX_FLOAT),
reduced,
));
// 2. System Settings (`Privacy & Security › Accessibility`).
if settings_open {
stage = stage.child(
settings_window(p, e, reduced)
.absolute(0.0, SETTINGS_Y)
.transition(arrives()),
);
}
// 3. The Accessibility helper panel: sits inside Hex's card at `AX_TRAY_OPEN`,
// then escapes out of the card at `AX_ESCAPE` and floats down to dock
// underneath System Settings (`GUIDE_Y`), then launches the drag row!
if tray_open {
stage = stage.child(escaping_guide_and_drag(p, e, reduced));
}
stage
}
fn setup_card(p: Paint, mic: PermState, ax: PermState, tray_open: bool, escaped: bool) -> El {
let k = p.k;
let ax_desc = if ax == PermState::Asking {
"Drag Hex into System Settings below"
} else {
"Notices the shortcut and pastes your words"
};
let mut card = col()
.key("setup-card")
.absolute(0.0, 0.0)
.w(COL_W)
.radius(k.radius.lg)
.fill(k.c.bg_base)
.border(p.hair, k.c.border_weak)
.motion(Spring::new(0.30, 0.0))
.child(perm_row(
p,
"mic-row",
&glyphs::MIC,
"Microphone",
"Hears you while you hold the shortcut",
perm_pill(p, "mic-pill", mic),
))
.child(separator(p, "sep0"))
.child(perm_row(
p,
"ax-row",
&glyphs::CURSOR_TEXT,
"Accessibility",
ax_desc,
perm_pill(p, "ax-pill", ax),
));
if tray_open {
card = card.child(
el().key("escape-socket-tray")
.w(COL_W)
.h(SOCKET_TRAY_H)
.transition(Transition::opacity())
.child(socket_outline(p, escaped)),
);
}
k.elevate(card, &k.elevation.raised)
}
/// Recessed outline left behind inside Hex's card once the helper panel escapes.
fn socket_outline(p: Paint, escaped: bool) -> El {
let k = p.k;
row()
.key("socket-outline")
.absolute(12.0, 5.0)
.size(COL_W - 24.0, 38.0)
.px(12.0)
.center_y()
.justify_between()
.radius(8.0)
.fill(k.c.bg_deep.mix(k.c.bg_base, 0.45))
.border(p.hair, k.c.border_base)
.children(escaped.then(|| {
text("Floating beside System Settings")
.key("escaped-note")
.font(k.ty.small)
.color(p.faint())
.transition(Transition::opacity())
}))
}
/// Hex's setup card in the first run's column: the permissions, and the
/// model step's found models.
pub(super) fn card(p: Paint) -> El {
let k = p.k;
col()
.key("setup-card")
.w(COL_W)
.radius(k.radius.lg)
.fill(k.c.bg_base)
.border(p.hair, k.c.border_weak)
}
pub(super) fn separator(p: Paint, key: &str) -> El {
el().key(key).h(p.hair).mx(16.0).fill(p.k.c.border_muted)
}
fn perm_row(
p: Paint,
key: &str,
glyph: &'static rune::Icon,
title: &str,
desc: &str,
control: El,
) -> El {
let k = p.k;
// Longer copy (Windows' switch, other languages) wraps in the row.
row()
.key(key)
.min_h(ROW_H)
.py(8.0)
.px(16.0)
.gap(12.0)
.center_y()
.child(icon(glyph, 16.0).key("icon").color(k.c.icon_base))
.child(
col()
.key("copy")
.grow(1.0)
.w(0.0)
.gap(2.0)
.child(
text(title)
.key("title")
.font(k.ty.ui_medium)
.color(p.text()),
)
.child(
text(desc)
.key("desc")
.font(k.ty.small)
.color(p.muted())
.wrap(),
),
)
.child(control)
}
/// Calm, zero-bounce permission control: no frantic blinking dot or spring bounce.
fn perm_pill(p: Paint, key: &str, state: PermState) -> El {
let k = p.k;
match state {
PermState::Allow { primary } => Button::new("Allow")
.variant(if primary {
ButtonVariant::Contrast
} else {
ButtonVariant::Neutral
})
.on_press(|_: &mut Onboard| {})
.build_push(k)
.key(format!("{key}-allow"))
.transition(arrives()),
PermState::Asking => row()
.key(format!("{key}-asking"))
.h(28.0)
.px(10.0)
.gap(6.0)
.center_y()
.radius(k.radius.md)
.fill(k.c.surface_raised)
.border(p.hair, k.c.border_weak)
.transition(arrives())
.child(
el().key("dot")
.size(6.0, 6.0)
.radius(3.0)
.fill(p.k.c.icon_muted),
)
.child(
text("Open")
.key("lbl")
.font(k.ty.small_medium)
.color(p.muted()),
),
PermState::Allowed => row()
.key(format!("{key}-allowed"))
.h(28.0)
.px(6.0)
.gap(5.0)
.center_y()
.transition(arrives())
.child(
icon(k.glyph.check_small, 16.0)
.key("check")
.color(p.success()),
)
.child(
text("Allowed")
.key("lbl")
.font(k.ty.ui_medium)
.color(p.success()),
),
}
}
fn microphone_prompt(p: Paint, pressed: bool) -> El {
let k = p.k;
let button = |key: &str, label: &str, variant: ButtonVariant| {
Button::new(label)
.variant(variant)
.on_press(|_: &mut Onboard| {})
.build_push(k)
.key(key.to_string())
.grow(1.0)
};
let badge = el()
.key("app-badge")
.size(40.0, 40.0)
.radius(10.0)
.continuous_corners()
.center()
.fill(k.c.surface_raised)
.border(p.hair, k.c.border_weak)
.child(hex_meter(p, "icon", 22.0, 1.0, 1.0));
let alert = col()
.key("mic-prompt")
.w(PROMPT_W)
.padding(18.0)
.gap(10.0)
.items_center()
.radius(18.0)
.continuous_corners()
.fill(k.c.bg_base)
.border(p.hair, k.c.border_weak)
.child(badge)
.child(
text("“Hex” would like to access the microphone.")
.key("title")
.font(TextStyle {
weight: if k.dark { 560.0 } else { 600.0 },
..k.ty.ui_medium
})
.color(p.text())
.align(rune::Align::Center)
.wrap()
.w(PROMPT_W - 36.0),
)
.child(
text("Hex listens only while you hold your shortcut.")
.key("body")
.font(k.ty.small)
.color(p.muted())
.align(rune::Align::Center)
.wrap()
.w(PROMPT_W - 36.0),
)
.child(
row()
.key("buttons")
.w_full()
.gap(8.0)
.pt(4.0)
.child(button("deny", "Don't Allow", ButtonVariant::Neutral))
.child(
button("allow", "Allow", ButtonVariant::Contrast)
.scale(if pressed { 0.96 } else { 1.0 })
.opacity(if pressed { 0.84 } else { 1.0 })
.motion(Spring::new(0.12, 0.0)),
),
);
k.elevate(alert, &k.elevation.floating)
}
/// System Settings' Accessibility pane (`w = 440 pt`), with its app icons at
/// `x = 26 pt` (`LIST_INSET + ROW_PX`).
fn settings_window(p: Paint, e: f64, reduced: bool) -> El {
let k = p.k;
let dark = k.dark;
let drag_u = drag_progress(e, reduced);
let slot_open = drag_u.is_some_and(|u| u >= 0.42) || e >= DRAG.1;
let landed = e >= DRAG.1;
let dot = |key: &str, color: Color| {
el().key(key.to_string())
.size(9.0, 9.0)
.radius(4.5)
.fill(color)
};
let bar = row()
.key("title-bar")
.absolute(0.0, 0.0)
.w(COL_W)
.h(28.0)
.px(14.0)
.gap(6.0)
.center_y()
.child(dot("close", rune_theme_opencode::ember(dark, 9)))
.child(dot(
"minimize",
rune_theme_opencode::scale("amber", dark, 9),
))
.child(dot("zoom", rune_theme_opencode::scale("apple", dark, 9)))
.child(
text("Privacy & Security › Accessibility")
.key("title")
.font(k.ty.small_medium)
.color(p.muted())
.pl(10.0),
);
let mut list = col()
.key("list")
.absolute(LIST_INSET, LIST_Y)
.w(LIST_W)
.radius(8.0)
.clip_rounded(8.0)
.fill(k.c.surface_raised)
.border(p.hair, k.c.border_weak)
.motion(Spring::new(0.26, 0.0))
.child(settings_app_row(
p,
"raycast",
"Raycast",
squircle_icon(rune_theme_opencode::ember(dark, 9)),
true,
))
.child(
el().key("lsep0")
.h(p.hair)
.mx(ROW_PX)
.fill(k.c.border_muted),
)
.child(settings_app_row(
p,
"rectangle",
"Rectangle",
squircle_icon(rune_theme_opencode::scale("cobalt", dark, 9)),
true,
));
if slot_open {
list = list.child(
el().key("lsep1")
.h(p.hair)
.mx(ROW_PX)
.fill(k.c.border_muted),
);
if landed {
list = list.child(
settings_app_row(p, "hex-landed", "Hex", hex_app_icon(p), e >= SWITCH_ON)
.transition(Transition::opacity()),
);
} else {
// Subtle drop-target highlight waiting to catch the dragged Hex row.
list = list.child(
row()
.key("drop-slot")
.h(LIST_ROW_H)
.px(ROW_PX)
.center_y()
.fill(k.c.bg_deep.mix(k.c.surface_raised, 0.5))
.border(p.hair, k.c.border_focus),
);
}
}
let win = el()
.key("settings-window")
.size(COL_W, SETTINGS_H)
.radius(12.0)
.continuous_corners()
.fill(k.c.bg_base)
.border(p.hair, k.c.border_weak)
.child(bar)
.child(
text("Allow the applications below to control your computer.")
.key("explain")
.font(k.ty.small)
.color(p.muted())
.absolute(LIST_INSET, 31.0),
)
.child(list);
k.elevate(win, &k.elevation.floating)
}
/// The panel that sits inside Hex's card, detaches at `AX_ESCAPE` leaving an
/// outline behind, floats down underneath System Settings, and then launches
/// the `Hex` drag row straight up the `x = 26 pt` spine into the list.
fn escaping_guide_and_drag(p: Paint, e: f64, reduced: bool) -> El {
let k = p.k;
let esc_u = if e < AX_ESCAPE {
0.0
} else if reduced {
1.0
} else {
smoothstep(((e - AX_ESCAPE) / (AX_DOCKED - AX_ESCAPE)) as f32)
};
let x = lerp(SOCKET_RECT[0], 0.0, esc_u);
let y = lerp(SOCKET_RECT[1], GUIDE_Y, esc_u) - 8.0 * (esc_u * std::f32::consts::PI).sin();
let w = lerp(SOCKET_RECT[2], COL_W, esc_u);
let h = lerp(SOCKET_RECT[3], GUIDE_H, esc_u);
let lift_scale = 1.0 + 0.025 * (esc_u * std::f32::consts::PI).sin();
let tilt = -0.018 * (esc_u * std::f32::consts::PI).sin();
let drag_u = drag_progress(e, reduced);
let tile_taken = drag_u.is_some() || e >= DRAG.1;
// Inside the panel: `tile_x` moves from `4` (at `x = 12`, putting the icon
// at `12 + 4 + 10 = 26`) to `16` (at `x = 0`, putting the icon at `0 + 16 + 10 = 26`)!
let tile_x = lerp(4.0, LIST_INSET, esc_u);
let tile_y = lerp(4.0, 30.0, esc_u);
let tile_w = LIST_W;
let instruction = (esc_u > 0.35).then(|| {
text("↑ Drag Hex into the Accessibility list above")
.key("guide-instruction")
.font(k.ty.small_medium)
.color(p.text())
.absolute(LIST_INSET, 8.0)
.opacity(((esc_u - 0.35) / 0.45).clamp(0.0, 1.0))
.opacity_motion(Anim::INSTANT)
});
// When `tile_taken`, ONLY the empty recessed slot remains — zero duplicate
// ghost `"Hex"` text underneath the lifted chip!
let inner_slot = if tile_taken {
el().key("guide-tile-empty")
.absolute(tile_x, tile_y)
.size(tile_w, 30.0)
.radius(7.0)
.fill(k.c.bg_deep.mix(k.c.bg_base, 0.5))
.border(p.hair, k.c.border_weak)
} else {
row()
.key("guide-tile")
.absolute(tile_x, tile_y)
.size(tile_w, 30.0)
.px(ROW_PX)
.gap(8.0)
.center_y()
.radius(7.0)
.fill(k.c.surface_raised)
.border(p.hair, k.c.border_base)
.offset_motion(Anim::INSTANT)
.child(hex_app_icon(p))
.child(
text("Hex")
.key("name")
.font(k.ty.small_medium)
.color(p.text()),
)
.child(el().key("sp").grow(1.0))
// It fades as the panel starts to escape rather than dropping
// out in one frame; it sits last, so nothing moves into its place.
.children((esc_u < 0.25).then(|| {
text("Accessibility helper")
.key("sub")
.font(k.ty.small)
.color(p.faint())
.opacity(1.0 - smoothstep(esc_u / 0.25))
.opacity_motion(Anim::INSTANT)
}))
};
let mut panel = el()
.key("escaping-panel")
.absolute(x, y)
.size(w, h)
.radius(lerp(8.0, 12.0, esc_u))
.continuous_corners()
.fill(if esc_u < 0.05 {
k.c.surface_raised
} else {
k.c.bg_base
})
.border(
p.hair,
if esc_u > 0.05 && esc_u < 0.98 {
k.c.border_focus
} else {
k.c.border_weak
},
)
.scale(lift_scale)
.rotate(tilt)
.offset_motion(Anim::INSTANT)
.rotate_motion(Anim::INSTANT)
.children(instruction)
.child(inner_slot);
if esc_u > 0.02 {
panel = k.elevate(panel, &k.elevation.floating);
}
let mut layer = el()
.key("escape-layer")
.absolute(0.0, 0.0)
.size(COL_W, STAGE_H)
.instant_changes()
.transition(Transition::opacity())
.child(panel);
if let Some(u) = drag_u {
layer = layer.child(dragged_row(p, u));
}
layer
}
fn drag_progress(e: f64, reduced: bool) -> Option<f32> {
if reduced || !(DRAG.0..DRAG.1).contains(&e) {
return None;
}
Some(smoothstep(((e - DRAG.0) / (DRAG.1 - DRAG.0)) as f32))
}
/// The lifted `Hex` row travelling up the `x = 26 pt` icon spine from the
/// docked guide into Row 3 of System Settings' Accessibility list.
fn dragged_row(p: Paint, u: f32) -> El {
let k = p.k;
let from_y = GUIDE_Y + 30.0;
let to_y = SETTINGS_Y + LIST_Y + 2.0 * LIST_ROW_H + 2.0 * p.hair;
let y = lerp(from_y, to_y, u) - 8.0 * (u * std::f32::consts::PI).sin();
let lift = 1.0 + 0.03 * (u * std::f32::consts::PI).sin();
let chip = row()
.key("drag-chip")
.absolute(LIST_INSET, y)
.size(LIST_W, LIST_ROW_H)
.px(ROW_PX)
.gap(8.0)
.center_y()
.radius(7.0)
.fill(k.c.surface_raised)
.border(p.hair, k.c.border_focus)
.scale(lift)
.offset_motion(Anim::INSTANT)
.child(hex_app_icon(p))
.child(
text("Hex")
.key("name")
.font(k.ty.small_medium)
.color(p.text()),
);
k.elevate(chip, &k.elevation.floating)
}
fn squircle_icon(color: Color) -> El {
el().key("icon")
.size(18.0, 18.0)
.radius(4.5)
.continuous_corners()
.fill(color)
}
fn hex_app_icon(p: Paint) -> El {
el().key("hex-app-icon")
.size(18.0, 18.0)
.radius(4.5)
.continuous_corners()
.center()
.fill(p.k.c.bg_deep)
.border(p.hair, p.k.c.border_base)
.child(hex_meter(p, "hex", 12.0, 1.0, 1.0))
}
fn settings_app_row(p: Paint, key: &str, name: &str, icon: El, on: bool) -> El {
let k = p.k;
row()
.key(key.to_string())
.h(LIST_ROW_H)
.px(ROW_PX)
.gap(8.0)
.center_y()
.child(icon)
.child(
text(name)
.key("name")
.font(k.ty.small)
.color(p.text())
.grow(1.0),
)
.child(macos_switch(p, on))
}
fn macos_switch(p: Paint, on: bool) -> El {
let k = p.k;
let knob = el()
.key("knob")
.absolute(if on { 12.5 } else { 1.5 }, 1.5)
.size(12.0, 12.0)
.radius(6.0)
.fill(k.c.white)
.motion(Spring::new(0.22, 0.0));
el().key("switch")
.size(26.0, 15.0)
.radius(7.5)
.fill(if on { p.accent() } else { k.c.border_base })
.child(knob)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn each_permission_asks_then_is_granted_in_order() {
assert_eq!(
state_at(0.0, MIC_ASK, MIC_GRANT, true),
PermState::Allow { primary: true }
);
assert_eq!(state_at(1.2, MIC_ASK, MIC_GRANT, true), PermState::Asking);
assert_eq!(state_at(2.5, MIC_ASK, MIC_GRANT, true), PermState::Allowed);
const { assert!(MIC_GRANT < AX_ESCAPE && AX_DOCKED < DRAG.0 && DRAG.1 < AX_GRANT) };
const { assert!(AX_GRANT < CONTINUE_AT && CONTINUE_AT < PERMISSIONS_SECS) };
}
#[test]
fn settings_list_and_docked_guide_share_one_icon_spine() {
let settings_icon_x = LIST_INSET + ROW_PX;
let docked_guide_icon_x = 0.0 + LIST_INSET + ROW_PX;
assert_eq!(settings_icon_x, 26.0);
assert_eq!(settings_icon_x, docked_guide_icon_x);
const { assert!(GUIDE_Y + GUIDE_H <= STAGE_H) };
}
}