mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* windows: default the dictation shortcut to the left alt key Alt sits under the thumb where Option does on a Mac, so holding it to dictate stops straining the pinky for Ctrl+Space (#2278). The left Alt only: Windows sends AltGr as a synthesized Left Ctrl plus the Right Alt, so an either-side Alt would press on every AltGr character, start a capture, and cancel it when the character joined. A saved shortcut stays as saved; there is no migration. The site's hero key and its "Hold …" line follow the selected install tab (Option, Alt, Alt+Space), and its keycap names that key. * docs: say the alt chord discards before the hold threshold * hotkeys: only Linux still builds a Control modifier helper * tests: pass the windows suite with its new default and CRLF checkout The playground list test compared the first story to the second through the dictation shortcut, which is now the left Alt on Windows, the same binding the Left Option shortcut story sets; it steps to the third story (Toggle cancel) instead. The bundled skill and the Swift instructions tests normalize CRLF, which a Windows checkout writes into include_str!. * windows: a modifier outside the shortcut joins as a chord A modifier-only hold (Left Alt by default) treated Shift, Ctrl, Win, or the other Alt going down as its release: Hold finished and pasted, Toggle locked a recording, and Left Alt+Shift injected the 0xE8 mask key before Alt's release, breaking Windows' input-language switch. It is a chord like any key now: the press cancels (Labs › Hold through other keys keeps a hold a second or more old), Toggle locks nothing, and Alt's release is the app's, so Ctrl+Alt+V still fires Paste Last. A modifier the chord names is part of it, whichever order the keys go down in. The modifier-event policy moved to input/modifier_chord.rs, and the new tests to input/tests/chords.rs, so input.rs stays under its cap. * site: the show's keycap names the selected OS's shortcut The animation's shattering keycap was always the Mac's option key. It takes the same lowercase legend the hero keycap shows now: option with the glyph, alt, or alt + space. * tests: import the right shift key the chords hold * docs: a joined hold leaves alt release to the app * docs: a swallowed key re-arms alt's release mask A modifier joining a Left Alt hold leaves Alt's release to the app, but only when Hex swallowed nothing. Paste Last's V is Hex's key, so the mask comes back and the app never reads a lone Alt tap. Say so in windows.md and the feature map, and name the test that holds it. * site: keep the keycap legend on the dish's bottom row With the Mac's glyph omitted on Windows and Linux, the label was the dish's only child and space-between put it at the top, while the canvas shatter draws the legend at the bottom. An auto top margin keeps both in the same place; the Mac's glyph and label are unchanged. * docs: qualify alt's release after a joined hold Alt's release is the app's after a joining modifier cancels the hold, but not after Hex swallows a key of the chord: Paste Last's V re-arms the mask. Say so in the hook and test comments, and stop claiming every Hold-mode dictation finishes when a tap or chord discards. * tests: one test at a time drives the windows hook's global state Paste Last's Ctrl+Alt+V does not leave Alt's release unmasked: its V is Hex's key, so that chord masks (#1254). Only a hold a joining modifier cancelled leaves the release to the app. The docs say so now. Under plain `cargo test` the hook tests share one process, so a static test lock serializes everything that installs, drives, or clears CALLBACK_STATE. --------- Co-authored-by: opencode <opencode@anoma.ly>
747 lines
26 KiB
Rust
747 lines
26 KiB
Rust
//! The playground (Labs › Playground): Rune's playground in Hex's window,
|
||
//! opened from its sidebar item or ⇧⌘D (Ctrl+Shift+D off macOS). It swaps
|
||
//! the window for a folded list of
|
||
//! prototypes (the onboarding options, live meeting notes, and on macOS
|
||
//! the HUD and the capture capsule), then every fixture
|
||
//! scene in [`SCENES`] under a readable name, by pane. Each opens on a fresh
|
||
//! fixture state; the real window's state keeps running underneath,
|
||
//! untouched. The window always attaches it, so the toggle applies at once;
|
||
//! off, no shortcut, menu item, sidebar item, or link opens it.
|
||
|
||
use std::sync::OnceLock;
|
||
|
||
use rune::{App, AppSpec, Playground};
|
||
|
||
use super::{DesktopShortcuts, SCENES, Scene, Ui, WINDOW_SIZE, fixture};
|
||
|
||
/// The list's top-level groups, in order. Each starts folded.
|
||
const GROUPS: &[&str] = &[PROTOTYPES, WINDOW, LINUX_WINDOWS];
|
||
pub(super) const PROTOTYPES: &str = "Prototypes";
|
||
const WINDOW: &str = "Window";
|
||
const LINUX_WINDOWS: &str = "Linux & Windows";
|
||
|
||
/// Where each fixture scene lists: its playground path, by its `--scene`
|
||
/// name. The list follows this order. Every scene but `live` has one.
|
||
const PATHS: &[(&str, &str)] = &[
|
||
("mac-settings", "Window/General/Settings"),
|
||
("mac-settings-sides", "Window/General/Left Option shortcut"),
|
||
("toggle-cancel", "Window/General/Toggle cancel shortcut"),
|
||
(
|
||
"portal-toggle-cancel",
|
||
"Window/General/Toggle cancel on Wayland",
|
||
),
|
||
("mac-settings-advanced", "Window/General/Advanced"),
|
||
("mac-settings-mic-level", "Window/General/Microphone level"),
|
||
(
|
||
"mac-settings-mic-released",
|
||
"Window/General/Microphone released while idle",
|
||
),
|
||
(
|
||
"mac-settings-ducking",
|
||
"Window/General/Duck while dictating",
|
||
),
|
||
(
|
||
"mac-settings-pause-browser",
|
||
"Window/General/Pause the browser too",
|
||
),
|
||
(
|
||
"mac-settings-permissions",
|
||
"Window/General/Permissions missing",
|
||
),
|
||
(
|
||
"mac-settings-permissions-stale",
|
||
"Window/General/Permissions · stale entry",
|
||
),
|
||
(
|
||
"mac-microphone-missing",
|
||
"Window/General/Microphone missing",
|
||
),
|
||
("mac-microphone-lid-closed", "Window/General/Lid closed"),
|
||
(
|
||
"mac-microphone-bluetooth",
|
||
"Window/General/Bluetooth default passed over",
|
||
),
|
||
("mac-settings-vocabulary", "Window/General/Vocabulary"),
|
||
(
|
||
"mac-settings-vocabulary-empty",
|
||
"Window/General/Vocabulary · empty",
|
||
),
|
||
(
|
||
"vocabulary-unused",
|
||
"Window/General/Vocabulary · not used by the model",
|
||
),
|
||
(
|
||
"vocabulary-budget",
|
||
"Window/General/Vocabulary · more terms than the model reads",
|
||
),
|
||
("shortcut-row", "Window/General/Shortcut/Left Option"),
|
||
("shortcut-row-right", "Window/General/Shortcut/Right Option"),
|
||
(
|
||
"shortcut-row-sided-chord",
|
||
"Window/General/Shortcut/Sided chord",
|
||
),
|
||
(
|
||
"shortcut-row-recording",
|
||
"Window/General/Shortcut/Recording",
|
||
),
|
||
(
|
||
"mac-settings-recording",
|
||
"Window/General/Shortcut/Recording · held",
|
||
),
|
||
("shortcut-row-held", "Window/General/Shortcut/Held"),
|
||
("shortcut-row-rejected", "Window/General/Shortcut/Rejected"),
|
||
("shortcut-row-saved", "Window/General/Shortcut/Saved"),
|
||
(
|
||
"mac-settings-reset",
|
||
"Window/General/Shortcut/Paste last changed · Reset",
|
||
),
|
||
(
|
||
"mac-settings-reset-off",
|
||
"Window/General/Shortcut/Paste last off · Reset",
|
||
),
|
||
(
|
||
"mac-settings-recording-optional",
|
||
"Window/General/Shortcut/Recording Paste last · ⌫ turns off",
|
||
),
|
||
("mac-update-checking", "Window/General/Updates/Checking"),
|
||
(
|
||
"mac-update-downloading",
|
||
"Window/General/Updates/Downloading",
|
||
),
|
||
(
|
||
"mac-update-ready",
|
||
"Window/General/Updates/Ready to restart",
|
||
),
|
||
(
|
||
"mac-settings-dev-channel",
|
||
"Window/General/Updates/Dev channel",
|
||
),
|
||
("mac-local-build", "Window/General/Updates/Local build"),
|
||
("mac-test-build", "Window/General/Updates/Test build"),
|
||
("picker", "Window/Transcription model/Picker"),
|
||
(
|
||
"picker-downloading",
|
||
"Window/Transcription model/Downloading",
|
||
),
|
||
(
|
||
"picker-parakeet-ultra",
|
||
"Window/Transcription model/Parakeet Ultra details (Labs)",
|
||
),
|
||
(
|
||
"picker-custom-models",
|
||
"Window/Transcription model/Add your own model",
|
||
),
|
||
(
|
||
"picker-found",
|
||
"Window/Transcription model/Found on this computer",
|
||
),
|
||
(
|
||
"picker-japanese",
|
||
"Window/Transcription model/Japanese saved",
|
||
),
|
||
(
|
||
"picker-japanese-all",
|
||
"Window/Transcription model/Japanese, every model",
|
||
),
|
||
("language-menu", "Window/Transcription model/Language menu"),
|
||
(
|
||
"language-fallback",
|
||
"Window/Transcription model/Language fallback",
|
||
),
|
||
("shortcut-mode", "Window/Shortcut mode/Modifier"),
|
||
("shortcut-mode-key", "Window/Shortcut mode/Key"),
|
||
("shortcut-mode-chord", "Window/Shortcut mode/Chord"),
|
||
("shortcut-mode-motion", "Window/Shortcut mode/Looping"),
|
||
("sound-sets", "Window/Sounds/Sheet"),
|
||
("sound-sets-playing", "Window/Sounds/Playing"),
|
||
("output", "Window/Output/Steps"),
|
||
("output-open", "Window/Output/App rule open"),
|
||
("output-trust", "Window/Output/Trust prompt"),
|
||
("output-empty", "Window/Output/Empty"),
|
||
("modes", "Window/Modes/Modes"),
|
||
("modes-global", "Window/Modes/Global mode"),
|
||
("modes-picker", "Window/Modes/App picker"),
|
||
(
|
||
"modes-transformation-menu",
|
||
"Window/Modes/Transformation menu",
|
||
),
|
||
(
|
||
"modes-opencode-not-running",
|
||
"Window/Modes/OpenCode not running",
|
||
),
|
||
(
|
||
"mac-input-source-models",
|
||
"Window/General/Input source models",
|
||
),
|
||
("meetings", "Window/Meetings/Meetings"),
|
||
("meetings-recording", "Window/Meetings/Recording"),
|
||
("meetings-chapters", "Window/Meetings/Chapters"),
|
||
("meetings-actions", "Window/Meetings/Actions menu"),
|
||
("meetings-rename", "Window/Meetings/Rename"),
|
||
("meetings-delete", "Window/Meetings/Delete"),
|
||
("meetings-failed", "Window/Meetings/Failed"),
|
||
("meetings-empty", "Window/Meetings/Empty"),
|
||
("meetings-off", "Window/Meetings/Off"),
|
||
("meetings-settings", "Window/Meetings/Settings"),
|
||
("meetings-summaries", "Window/Meetings/Summaries"),
|
||
(
|
||
"meetings-summaries-unavailable",
|
||
"Window/Meetings/Summaries without Apple Intelligence",
|
||
),
|
||
("meetings-summary-model", "Window/Meetings/Summary model"),
|
||
(
|
||
"meetings-summary-model-not-running",
|
||
"Window/Meetings/Summary model without OpenCode",
|
||
),
|
||
("meetings-allow", "Window/Meetings/Allow system audio"),
|
||
("meetings-calendar", "Window/Meetings/Calendar"),
|
||
(
|
||
"meetings-calendar-denied",
|
||
"Window/Meetings/Calendar denied",
|
||
),
|
||
("history", "Window/History/History"),
|
||
("history-menu", "Window/History/Retention menu"),
|
||
("history-clear", "Window/History/Clear all asks first"),
|
||
("history-stats", "Window/History/Stats dialog"),
|
||
(
|
||
"history-selection",
|
||
"Window/History/Select multiple dictations",
|
||
),
|
||
("history-empty", "Window/History/Empty"),
|
||
#[cfg(all(target_os = "macos", hex_capture))]
|
||
("mac-history", "Window/History/History with captures"),
|
||
#[cfg(all(target_os = "macos", hex_capture))]
|
||
("mac-history-capture", "Window/History/A capture's detail"),
|
||
#[cfg(all(target_os = "macos", hex_capture))]
|
||
("mac-history-filtered", "Window/History/Only annotations"),
|
||
#[cfg(all(target_os = "macos", hex_capture))]
|
||
("mac-history-types", "Window/History/Type menu"),
|
||
#[cfg(all(target_os = "macos", hex_capture))]
|
||
("mac-history-search", "Window/History/Search with matches"),
|
||
#[cfg(all(target_os = "macos", hex_capture))]
|
||
(
|
||
"mac-history-search-empty",
|
||
"Window/History/Search with nothing",
|
||
),
|
||
#[cfg(all(target_os = "macos", hex_capture))]
|
||
("mac-history-empty", "Window/History/Nothing yet"),
|
||
#[cfg(hex_capture)]
|
||
("captures", "Window/Captures/Captures"),
|
||
#[cfg(hex_capture)]
|
||
("captures-empty", "Window/Captures/Empty"),
|
||
#[cfg(hex_capture)]
|
||
("mac-scrawl", "Window/Annotate/On"),
|
||
#[cfg(hex_capture)]
|
||
("mac-scrawl-off", "Window/Annotate/Off"),
|
||
#[cfg(hex_capture)]
|
||
("mac-scrawl-running", "Window/Annotate/Scrawl.app running"),
|
||
#[cfg(hex_capture)]
|
||
(
|
||
"mac-scrawl-permission",
|
||
"Window/Annotate/Screen Recording missing",
|
||
),
|
||
#[cfg(hex_capture)]
|
||
(
|
||
"mac-scrawl-restart",
|
||
"Window/Annotate/Screen Recording needs restart",
|
||
),
|
||
#[cfg(hex_capture)]
|
||
("mac-scrawl-agents", "Window/Annotate/Agents"),
|
||
("mac-voice-filter", "Window/Voice Filter/Voice Filter"),
|
||
("mac-voice-filter-muted", "Window/Voice Filter/Muted"),
|
||
(
|
||
"mac-voice-filter-driver-missing",
|
||
"Window/Voice Filter/Driver missing",
|
||
),
|
||
("mac-hud-lab", "Window/HUD Lab/HUD Lab"),
|
||
("mac-labs", "Window/General/Labs"),
|
||
("mac-labs-link", "Window/General/Labs link"),
|
||
("mac-labs-on", "Window/General/Labs turned on"),
|
||
("mac-labs-screenshots", "Window/General/Labs screenshots"),
|
||
("mac-labs-category", "Window/General/Labs category"),
|
||
("mac-labs-search", "Window/General/Labs search"),
|
||
("mac-labs-settings", "Window/General/Labs settings"),
|
||
("mac-labs-yolo-mode", "Window/General/Labs YOLO mode"),
|
||
(
|
||
"mac-labs-yolo-mode-picker",
|
||
"Window/General/Labs YOLO mode picker",
|
||
),
|
||
("drop-hover", "Window/General/Labs dropped file hover"),
|
||
(
|
||
"drop-running",
|
||
"Window/General/Labs dropped file transcribing",
|
||
),
|
||
(
|
||
"mac-labs-drop-transcribe",
|
||
"Window/General/Labs transcribe audio",
|
||
),
|
||
("mac-production", "Window/General/Production build"),
|
||
("mac-activity", "Window/Activity/Activity"),
|
||
("mac-onboarding", "Window/Onboarding/Setting up Hex"),
|
||
(
|
||
"mac-onboarding-permissions",
|
||
"Window/Onboarding/Permissions",
|
||
),
|
||
(
|
||
"mac-onboarding-denied",
|
||
"Window/Onboarding/Permissions · denied",
|
||
),
|
||
(
|
||
"mac-onboarding-stale",
|
||
"Window/Onboarding/Permissions · stale entry",
|
||
),
|
||
(
|
||
"mac-onboarding-restart",
|
||
"Window/Onboarding/Permissions · restart",
|
||
),
|
||
("mac-onboarding-waiting", "Window/Onboarding/Almost ready"),
|
||
(
|
||
"mac-onboarding-sketch",
|
||
"Window/Onboarding/Almost ready · watch another one",
|
||
),
|
||
("mac-onboarding-try", "Window/Onboarding/Your turn"),
|
||
(
|
||
"mac-onboarding-reopen",
|
||
"Window/Onboarding/Your turn · reopen",
|
||
),
|
||
("mac-onboarding-ready", "Window/Onboarding/Hex is ready"),
|
||
(
|
||
"mac-onboarding-ready-tap",
|
||
"Window/Onboarding/Hex is ready · tap to start",
|
||
),
|
||
("portal", "Linux & Windows/Settings · portal shortcuts"),
|
||
("commands", "Linux & Windows/Settings · hex commands"),
|
||
("portal-mouse", "Linux & Windows/Settings · mouse button"),
|
||
("windows-settings", "Linux & Windows/Settings · Windows"),
|
||
("windows-labs", "Linux & Windows/Labs · Windows"),
|
||
("linux-labs", "Linux & Windows/Labs · Linux"),
|
||
("disabled", "Linux & Windows/Disabled"),
|
||
("capturing", "Linux & Windows/Recording a shortcut"),
|
||
("menus", "Linux & Windows/Microphone menu"),
|
||
("chinese", "Linux & Windows/Chinese"),
|
||
("voice-filter", "Linux & Windows/Voice Filter"),
|
||
(
|
||
"voice-filter-unavailable",
|
||
"Linux & Windows/Voice Filter unavailable",
|
||
),
|
||
("onboarding", "Linux & Windows/Onboarding"),
|
||
(
|
||
"onboarding-download-failed",
|
||
"Linux & Windows/Onboarding · download failed",
|
||
),
|
||
(
|
||
"onboarding-no-model",
|
||
"Linux & Windows/Onboarding · continued without a model",
|
||
),
|
||
(
|
||
"onboarding-model-found",
|
||
"Linux & Windows/Onboarding · models on this computer",
|
||
),
|
||
(
|
||
"onboarding-model-found-downloading",
|
||
"Linux & Windows/Onboarding · recommended model downloading",
|
||
),
|
||
(
|
||
"onboarding-model-found-recommended",
|
||
"Linux & Windows/Onboarding · recommended model on this computer",
|
||
),
|
||
(
|
||
"onboarding-model-found-back",
|
||
"Linux & Windows/Onboarding · back to the models",
|
||
),
|
||
("onboarding-demo", "Linux & Windows/Onboarding · demo"),
|
||
(
|
||
"onboarding-waiting",
|
||
"Linux & Windows/Onboarding · almost ready",
|
||
),
|
||
(
|
||
"onboarding-sketch",
|
||
"Linux & Windows/Onboarding · watch another one",
|
||
),
|
||
(
|
||
"onboarding-paste",
|
||
"Linux & Windows/Onboarding · paste permission",
|
||
),
|
||
("onboarding-try", "Linux & Windows/Onboarding · your turn"),
|
||
("onboarding-ready", "Linux & Windows/Onboarding · ready"),
|
||
(
|
||
"windows-onboarding-microphone",
|
||
"Linux & Windows/Onboarding · Windows microphone",
|
||
),
|
||
];
|
||
|
||
/// Labs › Playground is on.
|
||
pub(crate) fn enabled() -> bool {
|
||
crate::labs::playground()
|
||
}
|
||
|
||
/// `spec` with the playground's scenes: every fixture scene but `live`, at
|
||
/// its path in [`PATHS`], each starting from a plain fixture. Only the
|
||
/// window's app uses it: headless renders keep the plain scene names that
|
||
/// `--scene` takes, unless they ask for `--playground`.
|
||
pub(super) fn spec(spec: AppSpec<Ui>) -> AppSpec<Ui> {
|
||
AppSpec {
|
||
init: blank,
|
||
scenes: scenes(),
|
||
..spec
|
||
}
|
||
}
|
||
|
||
pub(super) fn attach(app: App<Ui>) -> App<Ui> {
|
||
app.playground(playground())
|
||
}
|
||
|
||
/// The window's playground: always attached, so Labs › Playground applies at
|
||
/// once. Rune's own ⇧⌘D is off; the window's `on_key`, its sidebar item, and
|
||
/// the macOS View menu open it only while the toggle is on.
|
||
pub(super) fn attach_gated(app: App<Ui>) -> App<Ui> {
|
||
app.playground(playground().shortcut(None))
|
||
}
|
||
|
||
fn playground() -> Playground<Ui> {
|
||
let playground = Playground::new()
|
||
.enabled(true)
|
||
.bar(false)
|
||
.sizes(&[("Hex window", WINDOW_SIZE)])
|
||
.group_order(GROUPS)
|
||
.start_folded(true);
|
||
let playground = super::onboarding_kit::stories(playground);
|
||
let playground = super::onboarding_kit::game(playground);
|
||
let playground = super::live_notes::add(playground);
|
||
#[cfg(target_os = "macos")]
|
||
let playground = super::hud_stories::add(playground);
|
||
#[cfg(all(hex_capture, target_os = "macos"))]
|
||
let playground = super::capture_capsule::playground::stories(playground);
|
||
playground
|
||
}
|
||
|
||
fn blank() -> Ui {
|
||
fixture(DesktopShortcuts::Registered)
|
||
}
|
||
|
||
fn scenes() -> &'static [Scene] {
|
||
static NAMED: OnceLock<Vec<Scene>> = OnceLock::new();
|
||
NAMED.get_or_init(|| {
|
||
// In `PATHS`' order; a scene without a path lists last, by name.
|
||
let mut listed: Vec<Scene> = SCENES
|
||
.iter()
|
||
.filter(|(name, _)| *name != "live")
|
||
.copied()
|
||
.collect();
|
||
listed.sort_by_key(|(name, _)| {
|
||
PATHS
|
||
.iter()
|
||
.position(|(scene, _)| scene == name)
|
||
.unwrap_or(PATHS.len())
|
||
});
|
||
listed
|
||
.into_iter()
|
||
.map(|(name, apply)| (path(name).unwrap_or(name), apply))
|
||
.collect()
|
||
})
|
||
}
|
||
|
||
fn path(scene: &str) -> Option<&'static str> {
|
||
PATHS
|
||
.iter()
|
||
.find(|(name, _)| *name == scene)
|
||
.map(|(_, path)| *path)
|
||
}
|
||
|
||
#[cfg(any(target_os = "macos", test))]
|
||
/// The groups a story or scene listed under before they nested, for links
|
||
/// made then.
|
||
const OLD_GROUPS: &[&str] = &[
|
||
"General",
|
||
"Transcription picker",
|
||
"Shortcut explainer",
|
||
"Modes",
|
||
"Commands",
|
||
"Meetings",
|
||
"History",
|
||
"Scrawl",
|
||
"Voice Filter",
|
||
"HUD Lab",
|
||
"Activity",
|
||
"Onboarding",
|
||
];
|
||
|
||
#[cfg(any(target_os = "macos", test))]
|
||
/// The groups of prototypes that listed at the top before they moved under
|
||
/// [`PROTOTYPES`].
|
||
const OLD_PROTOTYPES: &[&str] = &["Onboarding", "HUD", "Capture capsule"];
|
||
|
||
#[cfg(any(target_os = "macos", test))]
|
||
/// Today's name for a story link made before the list nested: a scene's
|
||
/// `--scene` name, its old `Group/scene` path or that path's slug, or a
|
||
/// prototype's path or slug without `Prototypes/`. `None` when `story`
|
||
/// needs no change.
|
||
pub(super) fn alias(story: &str) -> Option<String> {
|
||
let scene = |name: &str| path(name).map(str::to_owned);
|
||
if let Some(path) = scene(story) {
|
||
return Some(path);
|
||
}
|
||
for group in OLD_GROUPS {
|
||
for prefix in [
|
||
format!("{group}/"),
|
||
format!("{}-", rune::playground::slug(group)),
|
||
] {
|
||
if let Some(name) = strip_prefix_ignore_case(story, &prefix)
|
||
&& let Some(path) = scene(name)
|
||
{
|
||
return Some(path);
|
||
}
|
||
}
|
||
}
|
||
for group in OLD_PROTOTYPES {
|
||
if strip_prefix_ignore_case(story, &format!("{group}/")).is_some() {
|
||
return Some(format!("{PROTOTYPES}/{story}"));
|
||
}
|
||
if strip_prefix_ignore_case(story, &format!("{}-", rune::playground::slug(group))).is_some()
|
||
{
|
||
return Some(format!("{}-{story}", rune::playground::slug(PROTOTYPES)));
|
||
}
|
||
}
|
||
None
|
||
}
|
||
|
||
#[cfg(any(target_os = "macos", test))]
|
||
fn strip_prefix_ignore_case<'a>(text: &'a str, prefix: &str) -> Option<&'a str> {
|
||
let head = text.get(..prefix.len())?;
|
||
head.eq_ignore_ascii_case(prefix)
|
||
.then(|| &text[prefix.len()..])
|
||
}
|
||
|
||
#[cfg(test)]
|
||
mod tests {
|
||
use super::*;
|
||
use crate::rune_ui::Pane;
|
||
|
||
#[test]
|
||
fn every_scene_but_live_has_a_path_under_a_group() {
|
||
for (name, _) in SCENES.iter().filter(|(name, _)| *name != "live") {
|
||
let path = path(name).unwrap_or_else(|| panic!("{name} has no path in PATHS"));
|
||
let top = path.split('/').next().unwrap_or_default();
|
||
assert!(GROUPS.contains(&top), "{path} isn't under a group");
|
||
assert!(path.matches('/').count() >= 1, "{path} names no group");
|
||
}
|
||
for (name, path) in PATHS {
|
||
assert!(
|
||
SCENES.iter().any(|(scene, _)| scene == name),
|
||
"{path} names no scene {name}"
|
||
);
|
||
let paths = PATHS.iter().filter(|(_, other)| other == path).count();
|
||
assert_eq!(paths, 1, "{path} lists twice");
|
||
}
|
||
let names: Vec<&str> = scenes().iter().map(|(name, _)| *name).collect();
|
||
assert_eq!(names.len(), SCENES.len() - 1);
|
||
assert_eq!(names.first(), Some(&"Window/General/Settings"));
|
||
assert!(
|
||
names
|
||
.last()
|
||
.is_some_and(|name| name.starts_with("Linux & Windows/"))
|
||
);
|
||
}
|
||
|
||
/// A scene hears the window's ⌘-digit pane shortcuts as soon as it opens
|
||
/// from the list, without the stage taking the keyboard first, and the
|
||
/// real window's state stays where it was.
|
||
#[test]
|
||
fn a_scene_opened_from_the_list_hears_command_digits() {
|
||
let app = attach(App::new(spec(super::super::spec())));
|
||
let mut rt = app.headless_runtime(WINDOW_SIZE, rune::Env::new(false, 1.0));
|
||
rt.frame(0.0);
|
||
rt.open_playground("Window/General/Settings", None);
|
||
let stage = rt.playground_state::<Ui>().expect("the scene's state");
|
||
assert_eq!(stage.pane, Pane::General);
|
||
let second = *super::super::labs::order(stage)
|
||
.get(1)
|
||
.expect("a second pane");
|
||
rt.key(rune::KeyEvent {
|
||
key: rune::Key::Command('2'),
|
||
mods: rune::Mods {
|
||
cmd: true,
|
||
..rune::Mods::default()
|
||
},
|
||
});
|
||
rt.frame(1.0 / 60.0);
|
||
assert_eq!(rt.playground_state::<Ui>().map(|ui| ui.pane), Some(second));
|
||
assert_eq!(rt.state.pane, Pane::General);
|
||
}
|
||
|
||
/// The playground's own keys still win while a story that takes keys
|
||
/// is open: ↓ moves down the list and ⇧⌘D closes it.
|
||
///
|
||
/// Two steps, to the third story, so the list's move shows in state no
|
||
/// fixture shares: Settings, Left Option shortcut, then Toggle cancel.
|
||
#[test]
|
||
fn the_playgrounds_keys_work_with_a_story_open() {
|
||
let app = attach(App::new(spec(super::super::spec())));
|
||
let mut rt = app.headless_runtime(WINDOW_SIZE, rune::Env::new(false, 1.0));
|
||
rt.frame(0.0);
|
||
rt.open_playground("Window/General/Settings", None);
|
||
for _ in 0..2 {
|
||
rt.key(rune::KeyEvent {
|
||
key: rune::Key::Down,
|
||
mods: rune::Mods::default(),
|
||
});
|
||
rt.frame(1.0 / 60.0);
|
||
}
|
||
assert_eq!(
|
||
rt.playground_state::<Ui>()
|
||
.map(|ui| ui.settings.shortcut_mode),
|
||
Some(crate::dictation::ShortcutMode::Toggle),
|
||
"↓↓ reached Toggle cancel shortcut"
|
||
);
|
||
rt.key(rune::KeyEvent {
|
||
key: rune::Key::Command('d'),
|
||
mods: rune::Mods {
|
||
cmd: true,
|
||
ctrl: cfg!(not(target_os = "macos")),
|
||
shift: true,
|
||
..rune::Mods::default()
|
||
},
|
||
});
|
||
rt.frame(2.0 / 60.0);
|
||
assert!(rt.playground_state::<Ui>().is_none(), "⇧⌘D closed it");
|
||
}
|
||
|
||
/// Every HUD story, on every variant, opens from its `hex://story` link.
|
||
#[cfg(target_os = "macos")]
|
||
#[test]
|
||
fn every_hud_story_and_variant_opens_from_its_link() {
|
||
crate::rune_hud::dot_scope::set_lab(crate::rune_hud::dot_scope::Tuning::default());
|
||
let app = attach(App::new(spec(super::super::spec())));
|
||
let mut rt = app.headless_runtime(WINDOW_SIZE, rune::Env::new(false, 1.0));
|
||
rt.frame(0.0);
|
||
let looks = ["flow", "pulse", "sweep"];
|
||
let endings = ["done", "cancel", "fail"];
|
||
for story in ["notch", "pretend-notch", "menu-bar", "below-the-menu-bar"] {
|
||
for look in looks {
|
||
for ending in endings {
|
||
open_link(
|
||
&mut rt,
|
||
&format!("hex://story/prototypes/hud/{story}?variant={look}-{ending}"),
|
||
);
|
||
}
|
||
}
|
||
}
|
||
for story in ["processing", "your-voice"] {
|
||
for variant in ["hud-lab", "notch", "pretend-notch", "menu-bar", "below"] {
|
||
open_link(
|
||
&mut rt,
|
||
&format!("hex://story/prototypes/hud/{story}?variant={variant}"),
|
||
);
|
||
}
|
||
}
|
||
open_link(&mut rt, "hex://story/hud/processing?variant=menu-bar");
|
||
for control in [
|
||
"dot-scope-reset",
|
||
"dot-scope-copy",
|
||
"dot-scope-save",
|
||
"dot-processing",
|
||
"dot-placement",
|
||
"dot-auto-level",
|
||
"dot-spacing",
|
||
] {
|
||
assert!(
|
||
rt.find(control).is_some(),
|
||
"HUD story side panel lacked {control}"
|
||
);
|
||
}
|
||
}
|
||
|
||
/// Every capture-capsule story, on every flow after a capture, opens
|
||
/// from its `hex://story` link.
|
||
#[cfg(all(hex_capture, target_os = "macos"))]
|
||
#[test]
|
||
fn every_capsule_story_and_flow_opens_from_its_link() {
|
||
let app = attach(App::new(spec(super::super::spec())));
|
||
let mut rt = app.headless_runtime(WINDOW_SIZE, rune::Env::new(false, 1.0));
|
||
rt.frame(0.0);
|
||
for story in [
|
||
"whole-flow",
|
||
"rule",
|
||
"suggestions",
|
||
"shift",
|
||
"sent-rule",
|
||
"search",
|
||
"picked",
|
||
"taken-back",
|
||
"recording",
|
||
"discard",
|
||
"permission",
|
||
] {
|
||
for flow in ["tuned", "list", "toast", "menu-bar", "cursor", "notch"] {
|
||
open_link(
|
||
&mut rt,
|
||
&format!("hex://story/prototypes/capture-capsule/{story}?variant={flow}"),
|
||
);
|
||
}
|
||
}
|
||
for variant in ["Side%20by%20side", "1", "2", "3"] {
|
||
open_link(
|
||
&mut rt,
|
||
&format!("hex://story/prototypes/capture-capsule/notch?variant={variant}"),
|
||
);
|
||
}
|
||
for variant in ["braid", "bars", "line"] {
|
||
open_link(
|
||
&mut rt,
|
||
&format!("hex://story/prototypes/capture-capsule/family?variant={variant}"),
|
||
);
|
||
}
|
||
}
|
||
|
||
/// Opens `link` as the URL handler does; panics when its story or
|
||
/// variant isn't there.
|
||
#[cfg(target_os = "macos")]
|
||
fn open_link(rt: &mut rune::Runtime<Ui>, link: &str) {
|
||
let link = super::super::story_link::parse(link, "hex").expect(link);
|
||
rt.open_playground(&link.story, link.variant.as_deref());
|
||
assert!(
|
||
rt.playground_state::<Ui>().is_none(),
|
||
"{} is a story",
|
||
link.story
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn old_links_find_their_story() {
|
||
for (old, new) in [
|
||
("mac-settings", "Window/General/Settings"),
|
||
("General/mac-settings", "Window/General/Settings"),
|
||
("general-mac-settings", "Window/General/Settings"),
|
||
("Meetings/meetings-calendar", "Window/Meetings/Calendar"),
|
||
(
|
||
"onboarding-onboarding-demo",
|
||
"Linux & Windows/Onboarding · demo",
|
||
),
|
||
("HUD/Processing", "Prototypes/HUD/Processing"),
|
||
(
|
||
"hud-recording-your-voice",
|
||
"prototypes-hud-recording-your-voice",
|
||
),
|
||
(
|
||
"Onboarding/Option · Pill",
|
||
"Prototypes/Onboarding/Option · Pill",
|
||
),
|
||
(
|
||
"onboarding-option-pill",
|
||
"prototypes-onboarding-option-pill",
|
||
),
|
||
("capture-capsule-notch", "prototypes-capture-capsule-notch"),
|
||
] {
|
||
assert_eq!(alias(old).as_deref(), Some(new), "{old}");
|
||
}
|
||
for current in [
|
||
"Prototypes/HUD/Processing",
|
||
"prototypes-hud-processing",
|
||
"Processing",
|
||
"Option · Pill",
|
||
"Window/General/Settings",
|
||
] {
|
||
assert_eq!(alias(current), None, "{current}");
|
||
}
|
||
}
|
||
}
|