Compare commits

..
Author SHA1 Message Date
skylartaylor c738c6d77c fix(nightly): name the shared-workflow port in the release-preparation prerequisite 2026-11-25 01:22:47 +01:00
skylartaylor c161c7039c fix(nightly): derive the Windows signing fixture's identity from the checkout
The fixture mocks Cargo but nightly.ps1 validates the same source identity a
packaging run does, so a fixed "gaaaaaaaaaaaa" version with no build sha or
date threw in source validation before the mocked compiler. The version, the
build sha and the build date now come from this checkout.
2026-11-25 01:05:35 +01:00
skylartaylor d240c1adcd fix(nightly): attribute the Nightly icon set in ATTRIBUTION.md
The `assets` check failed: every file under `assets/` must be listed as a
`path` in ATTRIBUTION.md, and the six files this port adds were not. Add the
Nightly icon rows (source: `packaging/nightly-icons.py` from the committed
stable renders, hashes and recipe in `assets/app-icon/nightly-provenance.json`),
the provenance file itself and the icon README.
2026-11-25 00:58:07 +01:00
skylartaylor c79a12c9ba fix(nightly): record the shared-workflow port as a go-live prerequisite
The pinned shared producer and signer admit only PhotoCraft, so a WordCraft
dispatch builds and signs nothing until craft-common-actions admits it.
2026-11-25 00:56:51 +01:00
skylartaylor 6d9553a826 fix(nightly): satisfy clippy in the ported nightly code
The gate's `cargo clippy --workspace --all-targets -- -D warnings` failed on two
new items, so gate (ubuntu) and both Print lint jobs went red:

* profile_root.rs compared an OsString with `OsString::from(NIGHTLY_FLATPAK_ID)`
  (clippy::cmp_owned); compare the OsString with the &str constant instead.
* credits.rs declared the inline `nightly_about_tests` module before `about()`,
  which clippy::items_after_test_module rejects; the module now sits at the end
  of the file.

Both files are rustfmt-clean.
2026-11-25 00:33:20 +01:00
skylartaylor 564b281813 fix(nightly): set the check folder modes without mkdir -m -p
shellcheck reports SC2174 for `mkdir -m 700 -p "$work/home" "$work/profile"`
in the Linux tar check, and actionlint runs shellcheck over the workflow
script, so the lint job failed. Create both folders with -p and set the mode
with chmod afterwards, which keeps the 700 modes and no longer trips the check.
2026-11-25 00:30:36 +01:00
skylartaylor ed712acdab fix(nightly): one Linux launcher, a working tar step and persistent Flatpak state
Batch 2A review fixes on top of 4279762e:

- One launcher (packaging/linux/nightly-launcher.sh) serves the app-owned
  nightly tar, the deb/rpm wrapper, the AppImage AppRun, the Arch handoff and
  the Flatpak bundle. It passes an already-supplied --launch-profile (and
  --version/-V) straight through, so the ArtCraft Launcher's own profile root is
  honoured instead of being wrapped into file names, and it resolves its own
  folder (also when a shell finds it through PATH) rather than a relative path.
- The profile moves to ${XDG_DATA_HOME:-$HOME/.local/share}/wordcraft-nightly,
  which persists inside the Flatpak sandbox; the sandbox home does not, so
  preferences, recovery and autosaves were lost on every exit.
- package.sh's nightly tar step uses the tar's real member paths (no usr/), so
  the tar format no longer aborts and the Flatpak bundle can be built from it.
- The app-owned tar uses the standard layout: `wordcraft` is the launcher and
  `wordcraft-bin` the GUI (was wordcraft.real). The archive allowlist and its
  tests follow, and nightly-build.yml's exact member check accepts the OFL-*.txt
  licences CRAFT_FONTS_DIR adds.
- Windows: the print helper runs before prepare_launch(), so File > Print works
  in a Nightly build instead of hitting the launch-profile refusal.
- sign.ps1 keeps the stable signing step's random create-new temp folder; only
  the Nightly additions remain.
- Drop our dormant nightly-dispatch.yml, as in the other apps.
- profile_root: a test pins the Flatpak's own data folder as an accepted profile.

Tests: new packaging/linux/nightly-package-test.sh renders package.sh's nightly
tar with stub binaries and runs the extracted launcher (plain, the Launcher
form, --version, XDG_DATA_HOME, a PATH lookup from another directory, and the
AppImage and flat layouts); nightly-arch-tar-test.sh covers the Launcher form
and the data-home profile.
- Fix a compile error in the flavour's own window body: the unclean-session notice flag
  (an Arc) was moved into the window closure and then read after run_native, so
  cargo check failed with E0382. The window body now takes its own clone, as the exit
  hook already did; found by the first capped cargo check in this pass.
2026-11-25 00:16:15 +01:00
skylartaylor 4279762e28 fix(nightly): start every Linux format through the launch profile
On top of #7746 at 99b15ac2, keeping his commits.

The deb/rpm wrapper (one shared launcher in package.sh), the AppImage AppRun, the
Arch launcher, the plain tar's bin/wordcraft and the Flatpak bundle built from
that tar now exec the real binary with
`--launch-profile nightly-v1 --profile-root $HOME/.local/share/wordcraft-nightly
--`. The XDG redirects are gone: the flavour derives the stable boundary from
them, so the chosen profile sat inside it and the build refused to start. The
real binary keeps the ../lib/wordcraft-nightly/ layout in every format, a bare
--version/-V still goes straight to it, and the archive policy allows and
requires the launcher's binary.

nightly_compile_gui passes WORDCRAFT_BUILD_CHANNEL and WORDCRAFT_VERSION
explicitly (WORDCRAFT_OVERRIDE_VERSION was read by nothing here), so the build is
the nightly channel and its "WordCraft <version> (nightly-v1)" line is what
nightly_build_gui and the macOS verifier already check.

The nightly metainfo drops its mediatypes in the deb/rpm and Flatpak trees,
matching the desktop file's dropped MimeType. profile_root accepts the nightly
Flatpak's own id and still refuses a stable sandbox, so the nightly Flatpak can
start at all. Sonar's coverage exclusions name both binaries' main.rs and the
Windows-only identity module: his two coverable new lines are in main.rs, which
the Linux coverage job never runs, which is the whole of the 0.0% on new code.

Found by the one capped cargo check: the font-store match had a `()` arm and a
`bool` arm (use_font_store returns bool), so the crate did not type-check; the
call is now a statement, as the CLI already writes it.
2026-11-24 23:21:24 +01:00
skylartaylor 66d56083e9 nightly: the isolated Nightly channel for Windows, macOS and Linux (off)
On top of dylanmtaylor's Linux packaging (#7746), whose nightly-common.sh, nightly.sh,
helpers, callers, policy and preparation doc this branch reuses unchanged.

A separately identified WordCraft Nightly build: its own build channel and version line, the
Launcher's launch-profile protocol with the early --version answer, one private data root for
all user state (preferences, window place, logs, recovery, fonts, templates, dictionary, and the
suite font store), its own Windows AUMID, window titles and About, launcher-owned updates, and a
session health record. Its Linux counterpart is the Arch handoff in #7746; a Nightly build here
needs the Launcher's profile flag, so that wrapper gains one line.

Windows packaging (GUI-only intermediate ZIP through package.ps1 -Nightly and the sign.ps1
required-signing modes), macOS packaging with signing and verification, derived Nightly icons,
and a label-gated three-leg unsigned build check that exercises all three scripts without
secrets.
2026-11-24 22:45:55 +01:00
Dylan M. Taylor 99b15ac2d1 fix(packaging): port nightly.sh helpers and fix fmt, Exec sed delimiter, and Sonar coverage exclusions 2026-11-24 16:18:21 -05:00
Dylan M. Taylor 0fdf358ba5 fix(packaging): fix nightly-sign actionlint and address review comments
- Remove unsupported 'queue: max' key from concurrency in .github/workflows/nightly-sign.yml and update packaging/nightly-release-tests.py to match
- Use FLATPAK_ID (falling back to ai.storyteller.wordcraft) for runtime app_id in apps/wordcraft/src/main.rs
- Append -nightly marker to BASENAME in packaging/linux/package.sh and flatpak-bundle.sh when channel-only Nightly builds lack -nightly in VERSION
2026-11-24 14:22:00 -05:00
Dylan M. Taylorandskylartaylor ad46c883ff ci(nightly): enable supervised manual nightly runs
Port Skylar's (@skylartaylor) supervised manual nightly workflow and v3
signing policy setup from storytold/photocraft#16594 to WordCraft:

- Add .github/workflows/nightly.yml and .github/workflows/nightly-sign.yml
  pinned to craft-common-actions@605d58766e8f536564da8fc81d3676ac86816dea
  for supervised manual workflow_dispatch runs by release managers.
- Add .github/nightly-signing-policy.json adapted for storytold/wordcraft
  (repository ID 1408489772, CI workflow 380135788, SonarCloud project
  storytold_wordcraft; producer_workflow_id left null until nightly.yml
  is registered on main).
- Add docs/nightly-release-preparation.md and packaging/nightly-release-tests.py.

Co-authored-by: skylartaylor <hi@skylar.cc>
2026-11-24 14:15:18 -05:00
Dylan M. Taylor 6dd8396e20 packaging(linux): support co-installable nightly packages 2026-11-24 13:33:58 -05:00
10 changed files with 92 additions and 352 deletions
+9 -9
View File
@@ -35,7 +35,7 @@ jobs:
CARGO_INCREMENTAL: 0
steps:
- name: Harden runner
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -44,10 +44,10 @@ jobs:
- name: Install the system libraries the GUI links
run: sudo apt-get update && sudo apt-get install -y pkg-config libxkbcommon-dev libwayland-dev libx11-dev libxcursor-dev libxrandr-dev libxi-dev libgtk-3-dev libfontconfig1-dev libfreetype-dev
- name: Check out craft-fonts
uses: storytold/craft-common-actions/actions/checkout-craft-fonts@1754016e67ca9b74dfa4cf4678b2ac3548e9840f
uses: storytold/craft-common-actions/actions/checkout-craft-fonts@f5141455aac7b2eb4708aa259d8ffcdf10fde939
with:
ref: b076417b5880bd4154bd22f00695b1d28c6bea83
- uses: storytold/craft-common-actions/actions/checkout-craft-i18n@1754016e67ca9b74dfa4cf4678b2ac3548e9840f
- uses: storytold/craft-common-actions/actions/checkout-craft-i18n@f5141455aac7b2eb4708aa259d8ffcdf10fde939
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
@@ -121,17 +121,17 @@ jobs:
shell: pwsh
steps:
- name: Harden runner
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Check out craft-fonts
uses: storytold/craft-common-actions/actions/checkout-craft-fonts@1754016e67ca9b74dfa4cf4678b2ac3548e9840f
uses: storytold/craft-common-actions/actions/checkout-craft-fonts@f5141455aac7b2eb4708aa259d8ffcdf10fde939
with:
ref: b076417b5880bd4154bd22f00695b1d28c6bea83
- uses: storytold/craft-common-actions/actions/checkout-craft-i18n@1754016e67ca9b74dfa4cf4678b2ac3548e9840f
- uses: storytold/craft-common-actions/actions/checkout-craft-i18n@f5141455aac7b2eb4708aa259d8ffcdf10fde939
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
@@ -181,17 +181,17 @@ jobs:
CARGO_INCREMENTAL: 0
steps:
- name: Harden runner
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Check out craft-fonts
uses: storytold/craft-common-actions/actions/checkout-craft-fonts@1754016e67ca9b74dfa4cf4678b2ac3548e9840f
uses: storytold/craft-common-actions/actions/checkout-craft-fonts@f5141455aac7b2eb4708aa259d8ffcdf10fde939
with:
ref: b076417b5880bd4154bd22f00695b1d28c6bea83
- uses: storytold/craft-common-actions/actions/checkout-craft-i18n@1754016e67ca9b74dfa4cf4678b2ac3548e9840f
- uses: storytold/craft-common-actions/actions/checkout-craft-i18n@f5141455aac7b2eb4708aa259d8ffcdf10fde939
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
with:
toolchain: stable
+1 -1
View File
@@ -33,7 +33,7 @@ jobs:
checks: read
attestations: write
id-token: write
uses: storytold/craft-common-actions/.github/workflows/nightly-release.yml@1754016e67ca9b74dfa4cf4678b2ac3548e9840f
uses: storytold/craft-common-actions/.github/workflows/nightly-release.yml@605d58766e8f536564da8fc81d3676ac86816dea
with:
tooling-revision: 605d58766e8f536564da8fc81d3676ac86816dea
producer_run_id: ${{ inputs.producer_run_id }}
+1 -1
View File
@@ -22,7 +22,7 @@ jobs:
actions: read
attestations: write
id-token: write
uses: storytold/craft-common-actions/.github/workflows/nightly-unsigned.yml@1754016e67ca9b74dfa4cf4678b2ac3548e9840f
uses: storytold/craft-common-actions/.github/workflows/nightly-unsigned.yml@605d58766e8f536564da8fc81d3676ac86816dea
with:
tooling-revision: 605d58766e8f536564da8fc81d3676ac86816dea
app-name: wordcraft
+2 -2
View File
@@ -28,7 +28,7 @@ jobs:
runs-on: windows-latest
steps:
- name: Harden runner
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -58,7 +58,7 @@ jobs:
contents: read
steps:
- name: Harden runner
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
-2
View File
@@ -102,8 +102,6 @@ impl WordApp {
command_catalog_lang: "",
key_overrides: Default::default(),
command_states: Default::default(),
command_states_cache: None,
keytip_cache: None,
fonts_frames: 0,
clipboard_published: false,
printing: Default::default(),
+26 -192
View File
@@ -1,7 +1,7 @@
//! The app's side of the framework command runtime: the catalog of commands and their default
//! chords, the per-frame state (enabled, checked, hint) and the running of what the runtime fired.
use std::collections::{HashMap, HashSet};
use std::collections::HashSet;
use std::sync::Arc;
use craft::keymap::Overrides;
@@ -83,62 +83,6 @@ fn with_word_chords(catalog: AppCatalog) -> AppCatalog {
.fold(catalog, |catalog, command| catalog.replace_defaults(command.id(), Vec::new()))
}
/// Precomputed command references, translated hints, and last gate results for
/// [`WordApp::command_input`], rebuilt when the engine registry or interface language changes.
///
/// Every command's gate predicate still runs on every frame so enabled/disabled state is never
/// stale; only the per-frame `CATALOG.lines()` parsing, `i18n` hint formatting, and full
/// `CommandStates` map rebuild are skipped when nothing changed.
pub(crate) struct CommandStatesCache {
registry: Arc<wordcraft_engine::Registry>,
lang: &'static str,
/// `(id, location, label, prebuilt CommandRef, last (enabled, reason))` for every registered
/// engine command, in registry order.
registered: Vec<(&'static str, &'static str, &'static str, CommandRef, Option<(bool, Option<&'static str>)>)>,
/// `(id, prebuilt CommandRef, last enabled)` for gated `ui.*` commands.
ui_commands: Vec<(&'static str, CommandRef, Option<bool>)>,
/// `(id, prebuilt CommandRef, last enabled)` for unimplemented Word catalog commands.
unimplemented: Vec<(&'static str, CommandRef, Option<bool>)>,
/// Precomputed `CommandRef` and last enabled state for `ui.dialog {"name": "commands"}`.
commands_dialog: (CommandRef, Option<bool>),
/// Translated fallback hint shared by all unimplemented catalog commands.
unavailable_hint: Option<Arc<str>>,
/// Cached translated hints by `(spec index, disabled reason)` for the current language.
hints: HashMap<(usize, Option<&'static str>), Option<Arc<str>>>,
}
impl CommandStatesCache {
fn new(registry: Arc<wordcraft_engine::Registry>, lang: &'static str) -> Self {
let registered = registry.all().iter().map(|spec| (spec.id, spec.location, spec.label, CommandRef::new(spec.id), None)).collect();
let ui_commands = ["ui.collapseRibbon", "ui.resetInterfaceSize", "ui.print", "ui.printSubmit"]
.into_iter()
.chain(GATED_UI_COMMANDS.iter().map(|(id, _)| *id))
.map(|id| (id, CommandRef::new(id), None))
.collect();
let unimplemented = unimplemented_catalog_commands(&registry).map(|(id, _)| (id, CommandRef::new(id), None)).collect();
let commands_dialog = (CommandRef::with_params("ui.dialog", json!({"name": "commands"})), None);
let unavailable_hint = crate::widgets::command_hint("", "", Some("")).map(Arc::from);
CommandStatesCache { registry, lang, registered, ui_commands, unimplemented, commands_dialog, unavailable_hint, hints: HashMap::new() }
}
fn matches(&self, registry: &Arc<wordcraft_engine::Registry>, lang: &'static str) -> bool {
self.lang == lang && Arc::ptr_eq(&self.registry, registry)
}
fn hint_for(&mut self, idx: usize, location: &str, label: &str, reason: Option<&'static str>) -> Option<Arc<str>> {
self.hints.entry((idx, reason)).or_insert_with(|| crate::widgets::command_hint(location, label, reason).map(Arc::from)).clone()
}
}
/// Gate check for a command known to live in `app.session.registry` (skips the extra registry lookup).
fn gate_registered(app: &WordApp, id: &str) -> (bool, Option<&'static str>) {
if !app.has_document() && !super::commands::works_without_document(id) {
return (false, None);
}
let reason = app.session.why_disabled(id);
(reason.is_none(), reason)
}
impl WordApp {
/// The app's commands as the keymap knows them: every engine command with its default
/// chords, then the interface commands. The interface commands come last because a tie in the
@@ -233,108 +177,36 @@ impl WordApp {
if let Some(catalog) = self.catalog() {
input = input.catalog(catalog);
}
let lang = crate::i18n::current().code();
let fresh_cache = !self.command_states_cache.as_ref().is_some_and(|cache| cache.matches(&registry, lang));
let mut cache = if fresh_cache {
CommandStatesCache::new(registry, lang)
} else {
self.command_states_cache.take().unwrap_or_else(|| CommandStatesCache::new(registry, lang))
};
if fresh_cache {
let mut states = CommandStates::new();
for i in 0..cache.registered.len() {
let (id, location, label, _, _) = cache.registered[i];
let current = gate_registered(self, id);
cache.registered[i].4 = Some(current);
let mut state = CommandState::new().enabled(current.0);
if let Some(hint) = cache.hint_for(i, location, label, current.1) {
state = state.hint(hint);
}
states.set(cache.registered[i].3.clone(), state);
let mut states = CommandStates::new();
for spec in registry.all() {
let (enabled, reason) = gate(self, spec.id); // A toggle's checked state is bound at its ribbon button, not here.
let mut state = CommandState::new().enabled(enabled);
if let Some(hint) = crate::widgets::command_hint(spec.location, spec.label, reason) {
state = state.hint(hint);
}
for i in 0..cache.ui_commands.len() {
let id = cache.ui_commands[i].0;
let enabled = command_enabled(self, id);
cache.ui_commands[i].2 = Some(enabled);
states.set(cache.ui_commands[i].1.clone(), CommandState::new().enabled(enabled));
}
for i in 0..cache.unimplemented.len() {
let id = cache.unimplemented[i].0;
let enabled = command_enabled(self, id);
cache.unimplemented[i].2 = Some(enabled);
let mut state = CommandState::new().enabled(enabled);
if let Some(hint) = cache.unavailable_hint.as_ref() {
state = state.hint(Arc::clone(hint));
}
states.set(cache.unimplemented[i].1.clone(), state);
}
let dialog_enabled = command_enabled(self, "ui.dialog");
cache.commands_dialog.1 = Some(dialog_enabled);
states.set(cache.commands_dialog.0.clone(), CommandState::new().enabled(dialog_enabled));
if *self.command_states != states {
self.command_states.edit(|kept| *kept = states);
}
self.command_states_cache = Some(cache);
return input.states(&self.command_states);
states.set(CommandRef::new(spec.id), state);
}
// Steady-state path: re-evaluate every gate without allocating, and only touch
// `self.command_states` when at least one command's gate actually changed.
let mut reg_changes: Vec<(usize, bool, Option<&'static str>)> = Vec::new();
for (i, &(id, _, _, _, last)) in cache.registered.iter().enumerate() {
let current = gate_registered(self, id);
if last != Some(current) {
reg_changes.push((i, current.0, current.1));
// Print acts on the document, so with none open it is off like the engine's commands (#1129); a command with
// no state here resolves as enabled.
let ids = ["ui.collapseRibbon", "ui.resetInterfaceSize", "ui.print", "ui.printSubmit"]
.into_iter()
.chain(GATED_UI_COMMANDS.iter().map(|(id, _)| *id));
for id in ids {
states.set(CommandRef::new(id), CommandState::new().enabled(command_enabled(self, id)));
}
let unavailable_hint: Option<Arc<str>> = crate::widgets::command_hint("", "", Some("")).map(Arc::from);
for (id, _) in unimplemented_catalog_commands(&registry) {
let mut state = CommandState::new().enabled(command_enabled(self, id));
if let Some(hint) = unavailable_hint.as_ref() {
state = state.hint(Arc::clone(hint));
}
states.set(CommandRef::new(id), state);
}
let mut ui_changes: Vec<(usize, bool)> = Vec::new();
for (i, &(id, _, last)) in cache.ui_commands.iter().enumerate() {
let enabled = command_enabled(self, id);
if last != Some(enabled) {
ui_changes.push((i, enabled));
}
let commands = CommandRef::with_params("ui.dialog", json!({"name": "commands"}));
states.set(commands, CommandState::new().enabled(command_enabled(self, "ui.dialog")));
if *self.command_states != states {
self.command_states.edit(|kept| *kept = states);
}
let mut unimpl_changes: Vec<(usize, bool)> = Vec::new();
for (i, &(id, _, last)) in cache.unimplemented.iter().enumerate() {
let enabled = command_enabled(self, id);
if last != Some(enabled) {
unimpl_changes.push((i, enabled));
}
}
let dialog_enabled = command_enabled(self, "ui.dialog");
let dialog_changed = cache.commands_dialog.1 != Some(dialog_enabled);
if !reg_changes.is_empty() || !ui_changes.is_empty() || !unimpl_changes.is_empty() || dialog_changed {
self.command_states.edit(|kept| {
for (i, enabled, reason) in reg_changes {
let (_, location, label, _, _) = cache.registered[i];
cache.registered[i].4 = Some((enabled, reason));
let mut state = CommandState::new().enabled(enabled);
if let Some(hint) = cache.hint_for(i, location, label, reason) {
state = state.hint(hint);
}
kept.set(cache.registered[i].3.clone(), state);
}
for (i, enabled) in ui_changes {
cache.ui_commands[i].2 = Some(enabled);
kept.set(cache.ui_commands[i].1.clone(), CommandState::new().enabled(enabled));
}
for (i, enabled) in unimpl_changes {
cache.unimplemented[i].2 = Some(enabled);
let mut state = CommandState::new().enabled(enabled);
if let Some(hint) = cache.unavailable_hint.as_ref() {
state = state.hint(Arc::clone(hint));
}
kept.set(cache.unimplemented[i].1.clone(), state);
}
if dialog_changed {
cache.commands_dialog.1 = Some(dialog_enabled);
kept.set(cache.commands_dialog.0.clone(), CommandState::new().enabled(dialog_enabled));
}
});
}
self.command_states_cache = Some(cache);
input.states(&self.command_states)
}
@@ -449,42 +321,4 @@ mod tests {
);
}
}
/// Cached `command_input()` keeps steady-state idle calls zero-change while immediately reflecting
/// table/context transitions and document-open state changes.
#[test]
fn command_input_cache_tracks_state_transitions_and_is_noop_when_idle() {
let mut app = WordApp::new(Session::new(wordcraft_doc::Document::new()), Default::default());
let _ = app.command_input();
let rev_after_first = app.command_states.revision();
assert!(
!app.command_states.get(&CommandRef::new("table.deleteRow")).unwrap().is_enabled(),
"table.deleteRow starts disabled outside a table"
);
assert!(app.command_states.get(&CommandRef::new("format.bold")).unwrap().is_enabled(), "format.bold starts enabled");
// Repeated idle calls must not mutate `command_states` or bump its revision.
for _ in 0..5 {
let _ = app.command_input();
}
assert_eq!(app.command_states.revision(), rev_after_first, "idle frames leave command_states revision untouched");
// Entering a table enables `table.deleteRow` immediately on the next `command_input()`.
app.run("insert.table", json!({"rows": 2, "cols": 2})).unwrap();
let _ = app.command_input();
let rev_after_table = app.command_states.revision();
assert_ne!(rev_after_table, rev_after_first, "state change bumps command_states revision");
assert!(app.command_states.get(&CommandRef::new("table.deleteRow")).unwrap().is_enabled(), "table.deleteRow is enabled inside a table");
// Closing the document disables document commands immediately.
app.no_document = Some(app.session.document_id());
let _ = app.command_input();
assert!(!app.command_states.get(&CommandRef::new("format.bold")).unwrap().is_enabled(), "format.bold disables when no document is open");
// Dropping the cache and rebuilding from scratch must produce the exact same `CommandStates`.
let incremental = (*app.command_states).clone();
app.command_states_cache = None;
let _ = app.command_input();
assert_eq!(*app.command_states, incremental, "incremental cache matches full rebuild exactly");
}
}
+52 -115
View File
@@ -3,7 +3,7 @@
//! machine, badges, claimed keys) is the framework's `Keytips`; this module gives it WordCraft's
//! tabs, controls, legacy sequences and regions.
use std::sync::{Arc, OnceLock};
use std::sync::Arc;
use craft::behavior::overlay::MinWidth;
use craft::keymap::CommandRef;
@@ -59,32 +59,29 @@ pub const SEARCH_LETTER: &str = "Q";
/// Legacy menu keys (#1697): Word 2003 menu sequences Word for Windows still takes after Alt,
/// observed there. Hidden, as in Word: no badges, not in Customize Keyboard. They start only on
/// letters no tab keytip or Search uses (see the test).
fn legacy() -> &'static [(&'static str, CommandRef)] {
static LEGACY: OnceLock<Vec<(&'static str, CommandRef)>> = OnceLock::new();
LEGACY.get_or_init(|| {
let cmd = CommandRef::new;
let dialog = |name: &str| CommandRef::with_params("ui.dialog", serde_json::json!({ "name": name }));
vec![
("VU", cmd("view.fullScreenView")),
("VP", cmd("view.printLayout")),
("VW", cmd("view.webLayout")),
("VO", cmd("view.outline")),
("VN", cmd("view.draft")),
("VD", cmd("view.navigationPane")),
("VL", cmd("view.ruler")),
("VZ", dialog("zoom")),
("EL", cmd("select.all")),
("EF", dialog("find")),
("EE", dialog("replace")),
("EG", dialog("goto")),
("IS", dialog("symbol")),
("IPF", cmd("insert.picture")),
("OF", dialog("font")),
("OP", dialog("paragraph")),
("TW", cmd("review.wordCount")),
("AIT", dialog("insertTable")),
]
})
fn legacy() -> Vec<(&'static str, CommandRef)> {
let cmd = CommandRef::new;
let dialog = |name: &str| CommandRef::with_params("ui.dialog", serde_json::json!({ "name": name }));
vec![
("VU", cmd("view.fullScreenView")),
("VP", cmd("view.printLayout")),
("VW", cmd("view.webLayout")),
("VO", cmd("view.outline")),
("VN", cmd("view.draft")),
("VD", cmd("view.navigationPane")),
("VL", cmd("view.ruler")),
("VZ", dialog("zoom")),
("EL", cmd("select.all")),
("EF", dialog("find")),
("EE", dialog("replace")),
("EG", dialog("goto")),
("IS", dialog("symbol")),
("IPF", cmd("insert.picture")),
("OF", dialog("font")),
("OP", dialog("paragraph")),
("TW", cmd("review.wordCount")),
("AIT", dialog("insertTable")),
]
}
/// The letter badge for a tab (empty when it has none).
@@ -382,82 +379,13 @@ fn controls(tab: &str) -> Vec<Control> {
}
}
/// Maps an ASCII alphanumeric keytip letter to a static single-character `&'static str`, avoiding
/// per-control `String` allocations when caching [`KeytipControl`].
fn ascii_upper_str(c: char) -> Option<&'static str> {
const CHARS: &str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let idx = CHARS.find(c.to_ascii_uppercase())?;
CHARS.get(idx..idx + 1)
}
/// Cached keytip controls and reserved shortcut letters per engine registry and active ribbon tab,
/// avoiding per-frame `registry.all()` scans and `KeytipControl` / `CommandRef` allocations while
/// idle.
pub(crate) struct KeytipCache {
registry: Arc<wordcraft_engine::Registry>,
reserved: Vec<char>,
tab: String,
tab_controls: Vec<KeytipControl<'static>>,
}
impl KeytipCache {
fn build_tab_controls(app: &WordApp, tab: &str) -> Vec<KeytipControl<'static>> {
let mut out: Vec<KeytipControl<'static>> = controls(tab)
.into_iter()
.map(|control| {
let letters = shortcut_letter(app, &control.command.id).and_then(ascii_upper_str);
KeytipControl::new(control.command, control.tip, letters)
})
.collect();
out.push(KeytipControl::new(CommandRef::new("tools.search"), "Search", Some(SEARCH_LETTER)));
out
}
fn new(app: &WordApp, tab: &str) -> Self {
KeytipCache {
registry: app.session.registry.clone(),
reserved: reserved_letters(app),
tab: tab.to_owned(),
tab_controls: Self::build_tab_controls(app, tab),
}
}
fn sync(&mut self, app: &WordApp, tab: &str) {
let reg_changed = !Arc::ptr_eq(&self.registry, &app.session.registry);
if reg_changed {
self.registry = app.session.registry.clone();
self.reserved = reserved_letters(app);
}
if reg_changed || self.tab != tab {
self.tab.clear();
self.tab.push_str(tab);
self.tab_controls = Self::build_tab_controls(app, tab);
}
}
}
/// The Backstage's pages as cached static keytip controls.
fn backstage_controls() -> &'static [KeytipControl<'static>] {
static CONTROLS: OnceLock<Vec<KeytipControl<'static>>> = OnceLock::new();
CONTROLS.get_or_init(|| {
crate::backstage::KEYTIPS
.iter()
.map(|(page, letter)| {
KeytipControl::new(CommandRef::with_params("ui.backstage", serde_json::json!({ "page": page })), page, Some(letter))
})
.collect()
})
}
/// A control with the letters it asks for (used by unit tests).
#[cfg(test)]
/// A control with the letters it asks for.
struct Row {
control: Control,
letters: Option<String>,
}
/// A tab's controls with the shortcut letter each keeps, when its command has an Alt+letter shortcut.
#[cfg(test)]
fn rows(app: &WordApp, tab: &str) -> Vec<Row> {
controls(tab)
.into_iter()
@@ -468,6 +396,22 @@ fn rows(app: &WordApp, tab: &str) -> Vec<Row> {
.collect()
}
/// The Search box: its badge is Alt, Q on every tab.
fn search_row() -> Row {
Row { control: Control { tip: "Search", command: CommandRef::new("tools.search") }, letters: Some(SEARCH_LETTER.to_string()) }
}
/// The Backstage's pages, one badge each: the first letter its page has in `KEYTIPS`.
fn backstage_rows() -> Vec<Row> {
crate::backstage::KEYTIPS
.iter()
.map(|(page, letter)| Row {
control: Control { tip: page, command: CommandRef::with_params("ui.backstage", serde_json::json!({ "page": page })) },
letters: Some(letter.to_string()),
})
.collect()
}
/// Shows the keytips after the shell and the regions they place badges on, and acts on what the keys chose.
pub(crate) fn show(ui: &mut Ui, app: &mut WordApp, ribbon: &RibbonOutput<String>, screen_bar: Option<Rect>) {
let ctx = ui.ctx().clone();
@@ -482,15 +426,14 @@ pub(crate) fn show(ui: &mut Ui, app: &mut WordApp, ribbon: &RibbonOutput<String>
.filter_map(|t| ribbon.tab_ids.iter().find(|(name, _)| name == t).map(|(_, id)| (Label::from(t), tab_letter(t), *id)))
.collect();
let cache = match app.keytip_cache.take() {
Some(mut cache) => {
cache.sync(app, &app.ui.tab);
cache
}
None => KeytipCache::new(app, &app.ui.tab),
};
let controls: &[KeytipControl<'_>] = if app.ui.backstage { backstage_controls() } else { &cache.tab_controls };
let sequences: &[(&str, CommandRef)] = if cfg!(target_os = "macos") { &[] } else { legacy() };
let mut rows = if app.ui.backstage { backstage_rows() } else { rows(app, &app.ui.tab) };
if !app.ui.backstage {
rows.push(search_row());
}
let controls: Vec<KeytipControl<'_>> =
rows.iter().map(|r| KeytipControl::new(r.control.command.clone(), r.control.tip, r.letters.as_deref())).collect();
let sequences = if cfg!(target_os = "macos") { Vec::new() } else { legacy() };
// A hidden toolbar has no badges, and a disabled command's button has none to press.
let digits: Vec<CommandRef> = if app.ui.quick_access_toolbar {
app.session
@@ -504,6 +447,7 @@ pub(crate) fn show(ui: &mut Ui, app: &mut WordApp, ribbon: &RibbonOutput<String>
} else {
Vec::new()
};
let reserved = reserved_letters(app);
let mut places: Vec<Arc<Recorded>> = Vec::new();
places.extend(ribbon.controls.clone());
@@ -513,15 +457,8 @@ pub(crate) fn show(ui: &mut Ui, app: &mut WordApp, ribbon: &RibbonOutput<String>
places.extend(inspect::recorded(&ctx, backstage_region()));
}
let out = Keytips::new(enabled)
.tabs(&tabs)
.controls(controls)
.sequences(sequences)
.digits(&digits)
.reserved(&cache.reserved)
.places(&places)
.show_over(ui);
app.keytip_cache = Some(cache);
let out =
Keytips::new(enabled).tabs(&tabs).controls(&controls).sequences(&sequences).digits(&digits).reserved(&reserved).places(&places).show_over(ui);
// PLAN: `WordApp::keytips_active` is app-hub's (rb.A11).
app.keytips_active = out.active;
if let Some(tab) = out.tab.as_deref().and_then(tab_of_badge) {
+1 -23
View File
@@ -83,7 +83,7 @@ fn legacy_menu_keys_stay_off_the_ribbon_letters_and_all_resolve() {
for (keys, command) in legacy() {
let first = &keys[..1];
assert!(!taken.iter().any(|l| l.starts_with(first)), "{keys} starts on a ribbon letter");
assert!(!legacy().iter().any(|(k, _)| *k != *keys && k.starts_with(*keys)), "{keys} hides a longer sequence");
assert!(!legacy().iter().any(|(k, _)| *k != keys && k.starts_with(keys)), "{keys} hides a longer sequence");
let mut b = app();
// The hosted parameter dialogs open nothing before the window's context is known.
b.ctx = Some(egui::Context::default());
@@ -253,25 +253,3 @@ fn keytips_option_persists() {
b.apply_prefs(serde_json::from_str("{}").unwrap());
assert!(b.ui.keytips_enabled, "older preferences retain enabled KeyTips");
}
#[test]
fn keytip_cache_reuses_tab_controls_and_updates_on_tab_switch() {
let mut h = harness(app());
assert_eq!(h.state().keytip_cache.as_ref().map(|c| c.tab.as_str()), Some("Home"));
let home_ptr = h.state().keytip_cache.as_ref().unwrap().tab_controls.as_ptr();
let reserved_ptr = h.state().keytip_cache.as_ref().unwrap().reserved.as_ptr();
// Idle frames reuse the cached control and reserved-letter buffers without rebuilding.
crate::test_harness::frames(&mut h, 4);
assert_eq!(h.state().keytip_cache.as_ref().unwrap().tab_controls.as_ptr(), home_ptr);
assert_eq!(h.state().keytip_cache.as_ref().unwrap().reserved.as_ptr(), reserved_ptr);
// Switching tabs rebuilds the cached tab controls while keeping reserved letters intact.
h.state_mut().run("ui.tab", serde_json::json!({"tab": "Insert"})).unwrap();
crate::test_harness::frame(&mut h);
let cache = h.state().keytip_cache.as_ref().unwrap();
assert_eq!(cache.tab, "Insert");
// Tab controls plus the trailing Search badge (`SEARCH_LETTER`).
assert_eq!(cache.tab_controls.len(), controls("Insert").len() + 1);
assert_eq!(cache.reserved.as_ptr(), reserved_ptr);
}
-5
View File
@@ -402,11 +402,6 @@ pub struct WordApp {
/// The app-scope command states handed to the runtime, edited only when they change: the runtime resolves
/// commands again only when their revision moves ([`WordApp::command_input`]).
pub(crate) command_states: craft::ui::contract::Tracked<craft::ui::runtime::commands::CommandStates>,
/// Precomputed command metadata, translated hints, and last gate results for [`WordApp::command_input`],
/// avoiding per-frame allocations and catalog reparsing while idle.
pub(crate) command_states_cache: Option<app::command_board::CommandStatesCache>,
/// Cached keytip control lists and reserved shortcut letters per registry and active ribbon tab.
pub(crate) keytip_cache: Option<keytips::KeytipCache>,
/// Frames drawn so far, counted to 2: the control channel's queued requests wait until the
/// fonts are warm.
pub(crate) fonts_frames: u8,
-2
View File
@@ -146,8 +146,6 @@ impl WordApp {
command_catalog_lang: _,
key_overrides: _,
command_states: _,
command_states_cache: _,
keytip_cache: _,
fonts_frames: _,
printing: _,
print_feedback_seen: _,