Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Give the macOS app a menu bar with its actions (#804)

BFlatb2d7e89ee811
diff --git a/Cargo.lock b/Cargo.lock
index 28acd1e9..24ac32f0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1391,6 +1391,7 @@ dependencies = [
"egui_extras",
"egui_kittest",
"log",
+ "muda",
"pollster 0.4.0",
"rfd",
"serde",
@@ -1586,6 +1587,15 @@ dependencies = [
"cfg-if",
]
+[[package]]
+name = "crossbeam-channel"
+version = "0.5.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "98b0cc327b5bc766e7fda9c9260cc0fa81b43a8e240440422dff70788e3f9ef1"
+dependencies = [
+ "crossbeam-utils",
+]
+
[[package]]
name = "crossbeam-deque"
version = "0.8.8"
@@ -3239,6 +3249,16 @@ dependencies = [
"escape-simd",
]
+[[package]]
+name = "keyboard-types"
+version = "0.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0fbe853b403ae61a04233030ae8a79d94975281ed9770a1f9e246732b534b28d"
+dependencies = [
+ "bitflags 2.13.2",
+ "serde",
+]
+
[[package]]
name = "keyring"
version = "3.6.3"
@@ -3548,6 +3568,24 @@ dependencies = [
"pxfm",
]
+[[package]]
+name = "muda"
+version = "0.21.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4340e89c178916e62879c5c36b7f699019369be413e496178a6983ce91b8bc03"
+dependencies = [
+ "crossbeam-channel",
+ "dpi",
+ "keyboard-types",
+ "objc2 0.6.5",
+ "objc2-app-kit 0.3.2",
+ "objc2-core-foundation",
+ "objc2-foundation 0.3.2",
+ "png 0.18.1",
+ "thiserror 2.0.21",
+ "windows-sys 0.61.2",
+]
+
[[package]]
name = "multiversion_no_op"
version = "1.0.0"
diff --git a/apps/craft-anything/src/main.rs b/apps/craft-anything/src/main.rs
index a772126d..903e9e76 100644
--- a/apps/craft-anything/src/main.rs
+++ b/apps/craft-anything/src/main.rs
@@ -18,6 +18,8 @@ static RETRY_IN_SOFTWARE: std::sync::atomic::AtomicBool = std::sync::atomic::Ato
#[cfg(any(target_os = "linux", test))]
mod linux_gpu;
+/// Opens the window on the engine and AI hub (a path on the command line opens as the first
+/// target); if the window can't start, says why and where its log is.
fn main() -> eframe::Result {
let args: Vec<String> = std::env::args().skip(1).collect();
if args.iter().any(|a| a == "--version" || a == "-V") {
@@ -102,6 +104,7 @@ fn main() -> eframe::Result {
shown_by_app.store(true, std::sync::atomic::Ordering::Relaxed);
});
app.load_prefs(cc.storage);
+ app.install_menu_bar(&cc.egui_ctx);
if let Some(p) = open {
app.open_path(p);
}
diff --git a/crates/ui-egui/Cargo.toml b/crates/ui-egui/Cargo.toml
index 6fa2f024..8842c0ef 100644
--- a/crates/ui-egui/Cargo.toml
+++ b/crates/ui-egui/Cargo.toml
@@ -4,6 +4,7 @@ description = "The Craft Anything egui interface: Beginner and Experienced modes
version.workspace = true
edition.workspace = true
license.workspace = true
+repository.workspace = true
publish = false
build = "build.rs"
@@ -34,6 +35,10 @@ pollster = "0.4"
# Safe, small OS-language lookup; MIT OR Apache-2.0, no native runtime dependency.
sys-locale = "0.3.2"
+[target.'cfg(target_os = "macos")'.dependencies]
+# The system menu bar (a safe API over AppKit); MIT OR Apache-2.0.
+muda = { version = "0.21.2", default-features = false }
+
[dev-dependencies]
craft-anything-testkit = { workspace = true }
egui_kittest = { workspace = true, features = ["wgpu", "snapshot", "eframe"] }
diff --git a/crates/ui-egui/src/fr.tsv b/crates/ui-egui/src/fr.tsv
index 8aeba517..d4d0df15 100644
--- a/crates/ui-egui/src/fr.tsv
+++ b/crates/ui-egui/src/fr.tsv
@@ -860,3 +860,20 @@ Add Unreal's Linux C++ toolchain Ajouter la chaîne d'outils C++ Linux d'Unreal
Run Engine/Build/BatchFiles/Linux/SetupToolchain.sh in the engine folder to install its bundled Clang toolchain. If you built Unreal from source, Setup.sh downloads the native toolchain instead. A system Clang may not match the engine's version. Dans le dossier du moteur, exécutez Engine/Build/BatchFiles/Linux/SetupToolchain.sh pour installer sa chaîne d'outils Clang intégrée. Si vous compilez depuis les sources, Setup.sh télécharge à la place la chaîne d'outils native. Un Clang système peut ne pas correspondre à la version du moteur.
Unreal is here, but it also needs Xcode. Unreal est là, mais il lui faut aussi Xcode.
About 60 GB, an Epic Games account, and Xcode. Environ 60 Go, un compte Epic Games et Xcode.
+File Fichier
+View Présentation
+Window Fenêtre
+Help Aide
+Command palette Palette de commandes
+Craft Anything on GitHub Craft Anything sur GitHub
+Report a problem… Signaler un problème…
+Quit Craft Anything Quitter Craft Anything
+About Craft Anything À propos de Craft Anything
+Services Services
+Hide Craft Anything Masquer Craft Anything
+Hide others Masquer les autres
+Show all Tout afficher
+Close window Fermer la fenêtre
+Full screen Plein écran
+Zoom Réduire/agrandir
+Bring all to front Tout ramener au premier plan
diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv
index 55265277..5acfe1c7 100644
--- a/crates/ui-egui/src/i18n/cs.tsv
+++ b/crates/ui-egui/src/i18n/cs.tsv
@@ -1425,3 +1425,20 @@ Add Unreal's Linux C++ toolchain Přidat linuxový nástrojový řetězec C++ pr
Run Engine/Build/BatchFiles/Linux/SetupToolchain.sh in the engine folder to install its bundled Clang toolchain. If you built Unreal from source, Setup.sh downloads the native toolchain instead. A system Clang may not match the engine's version. Ve složce enginu spusťte Engine/Build/BatchFiles/Linux/SetupToolchain.sh a nainstaluje se přibalený nástrojový řetězec Clang. Při sestavení ze zdrojů Setup.sh místo toho stáhne nativní nástrojový řetězec. Systémový Clang nemusí odpovídat verzi enginu.
Unreal is here, but it also needs Xcode. Unreal je dostupný, ale potřebuje také Xcode.
About 60 GB, an Epic Games account, and Xcode. Přibližně 60 GB, účet Epic Games a Xcode.
+File Soubor
+View Zobrazení
+Window Okno
+Help Nápověda
+Command palette Paleta příkazů
+Craft Anything on GitHub Craft Anything na GitHubu
+Report a problem… Nahlásit problém…
+Quit Craft Anything Ukončit Craft Anything
+About Craft Anything O aplikaci Craft Anything
+Services Služby
+Hide Craft Anything Skrýt Craft Anything
+Hide others Skrýt ostatní
+Show all Zobrazit vše
+Close window Zavřít okno
+Full screen Celá obrazovka
+Zoom Zvětšit
+Bring all to front Vše do popředí
diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv
index 84023812..cfc004d3 100644
--- a/crates/ui-egui/src/i18n/de.tsv
+++ b/crates/ui-egui/src/i18n/de.tsv
@@ -1425,3 +1425,20 @@ Add Unreal's Linux C++ toolchain Unreals Linux-C++-Toolchain hinzufügen
Run Engine/Build/BatchFiles/Linux/SetupToolchain.sh in the engine folder to install its bundled Clang toolchain. If you built Unreal from source, Setup.sh downloads the native toolchain instead. A system Clang may not match the engine's version. Führe im Engine-Ordner Engine/Build/BatchFiles/Linux/SetupToolchain.sh aus, um die mitgelieferte Clang-Toolchain zu installieren. Bei einem Quellcode-Build lädt Setup.sh stattdessen die native Toolchain herunter. Ein System-Clang passt möglicherweise nicht zur Engine-Version.
Unreal is here, but it also needs Xcode. Unreal ist da, braucht aber zusätzlich Xcode.
About 60 GB, an Epic Games account, and Xcode. Etwa 60 GB, ein Epic-Games-Konto und Xcode.
+File Ablage
+View Darstellung
+Window Fenster
+Help Hilfe
+Command palette Befehlspalette
+Craft Anything on GitHub Craft Anything auf GitHub
+Report a problem… Problem melden …
+Quit Craft Anything Craft Anything beenden
+About Craft Anything Über Craft Anything
+Services Dienste
+Hide Craft Anything Craft Anything ausblenden
+Hide others Andere ausblenden
+Show all Alle einblenden
+Close window Fenster schließen
+Full screen Vollbild
+Zoom Zoomen
+Bring all to front Alle nach vorne bringen
diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv
index 302c728b..dc757bc1 100644
--- a/crates/ui-egui/src/i18n/ko.tsv
+++ b/crates/ui-egui/src/i18n/ko.tsv
@@ -1425,3 +1425,20 @@ Add Unreal's Linux C++ toolchain Unreal의 Linux C++ 도구 체인 추가
Run Engine/Build/BatchFiles/Linux/SetupToolchain.sh in the engine folder to install its bundled Clang toolchain. If you built Unreal from source, Setup.sh downloads the native toolchain instead. A system Clang may not match the engine's version. 엔진 폴더에서 Engine/Build/BatchFiles/Linux/SetupToolchain.sh를 실행해 함께 제공되는 Clang 도구 체인을 설치하세요. 소스 빌드라면 Setup.sh가 대신 네이티브 도구 체인을 내려받습니다. 시스템 Clang은 엔진 버전과 맞지 않을 수 있습니다.
Unreal is here, but it also needs Xcode. Unreal은 있지만 Xcode도 필요합니다.
About 60 GB, an Epic Games account, and Xcode. 약 60 GB, Epic Games 계정, Xcode가 필요합니다.
+File 파일
+View 보기
+Window 윈도우
+Help 도움말
+Command palette 명령 팔레트
+Craft Anything on GitHub GitHub의 Craft Anything
+Report a problem… 문제 신고…
+Quit Craft Anything Craft Anything 종료
+About Craft Anything Craft Anything에 관하여
+Services 서비스
+Hide Craft Anything Craft Anything 가리기
+Hide others 기타 가리기
+Show all 모두 보기
+Close window 윈도우 닫기
+Full screen 전체 화면
+Zoom 확대/축소
+Bring all to front 모두 앞으로 가져오기
diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv
index da44d3de..ec72a916 100644
--- a/crates/ui-egui/src/i18n/ru.tsv
+++ b/crates/ui-egui/src/i18n/ru.tsv
@@ -1425,3 +1425,20 @@ Add Unreal's Linux C++ toolchain Добавить цепочку инструм
Run Engine/Build/BatchFiles/Linux/SetupToolchain.sh in the engine folder to install its bundled Clang toolchain. If you built Unreal from source, Setup.sh downloads the native toolchain instead. A system Clang may not match the engine's version. Запустите Engine/Build/BatchFiles/Linux/SetupToolchain.sh в папке движка, чтобы установить встроенную цепочку инструментов Clang. При сборке из исходников Setup.sh вместо этого скачивает нативную цепочку инструментов. Системный Clang может не подходить к версии движка.
Unreal is here, but it also needs Xcode. Unreal установлен, но также требует Xcode.
About 60 GB, an Epic Games account, and Xcode. Около 60 ГБ, аккаунт Epic Games и Xcode.
+File Файл
+View Вид
+Window Окно
+Help Справка
+Command palette Палитра команд
+Craft Anything on GitHub Craft Anything на GitHub
+Report a problem… Сообщить о проблеме…
+Quit Craft Anything Завершить Craft Anything
+About Craft Anything О программе Craft Anything
+Services Службы
+Hide Craft Anything Скрыть Craft Anything
+Hide others Скрыть остальные
+Show all Показать все
+Close window Закрыть окно
+Full screen Полноэкранный режим
+Zoom Изменить масштаб
+Bring all to front Все окна — на передний план
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index 852bf823..a1846324 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -1425,3 +1425,20 @@ Add Unreal's Linux C++ toolchain 添加 Unreal 的 Linux C++ 工具链
Run Engine/Build/BatchFiles/Linux/SetupToolchain.sh in the engine folder to install its bundled Clang toolchain. If you built Unreal from source, Setup.sh downloads the native toolchain instead. A system Clang may not match the engine's version. 在引擎文件夹中运行 Engine/Build/BatchFiles/Linux/SetupToolchain.sh,安装其自带的 Clang 工具链。如果是源码构建,Setup.sh 会改为下载本机工具链。系统 Clang 可能与引擎版本不匹配。
Unreal is here, but it also needs Xcode. 已安装 Unreal,但还需要 Xcode。
About 60 GB, an Epic Games account, and Xcode. 约 60 GB,需要 Epic Games 账户和 Xcode。
+File 文件
+View 显示
+Window 窗口
+Help 帮助
+Command palette 命令面板
+Craft Anything on GitHub GitHub 上的 Craft Anything
+Report a problem… 报告问题…
+Quit Craft Anything 退出 Craft Anything
+About Craft Anything 关于 Craft Anything
+Services 服务
+Hide Craft Anything 隐藏 Craft Anything
+Hide others 隐藏其他
+Show all 全部显示
+Close window 关闭窗口
+Full screen 全屏幕
+Zoom 缩放
+Bring all to front 前置全部窗口
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index 8259e7c4..519cbcc7 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -1425,3 +1425,20 @@ Add Unreal's Linux C++ toolchain 新增 Unreal 的 Linux C++ 工具鏈
Run Engine/Build/BatchFiles/Linux/SetupToolchain.sh in the engine folder to install its bundled Clang toolchain. If you built Unreal from source, Setup.sh downloads the native toolchain instead. A system Clang may not match the engine's version. 在引擎資料夾中執行 Engine/Build/BatchFiles/Linux/SetupToolchain.sh,安裝其內建的 Clang 工具鏈。如果是原始碼建置,Setup.sh 會改為下載原生工具鏈。系統 Clang 可能與引擎版本不相符。
Unreal is here, but it also needs Xcode. 已安裝 Unreal,但還需要 Xcode。
About 60 GB, an Epic Games account, and Xcode. 約 60 GB,需要 Epic Games 帳戶和 Xcode。
+File 檔案
+View 顯示方式
+Window 視窗
+Help 輔助說明
+Command palette 命令面板
+Craft Anything on GitHub GitHub 上的 Craft Anything
+Report a problem… 回報問題…
+Quit Craft Anything 結束 Craft Anything
+About Craft Anything 關於 Craft Anything
+Services 服務
+Hide Craft Anything 隱藏 Craft Anything
+Hide others 隱藏其他
+Show all 顯示全部
+Close window 關閉視窗
+Full screen 全螢幕
+Zoom 縮放
+Bring all to front 將全部視窗移至最前
diff --git a/crates/ui-egui/src/ja.tsv b/crates/ui-egui/src/ja.tsv
index 11da34e4..4727c826 100644
--- a/crates/ui-egui/src/ja.tsv
+++ b/crates/ui-egui/src/ja.tsv
@@ -862,3 +862,20 @@ Add Unreal's Linux C++ toolchain Unreal の Linux C++ ツールチェーンを
Run Engine/Build/BatchFiles/Linux/SetupToolchain.sh in the engine folder to install its bundled Clang toolchain. If you built Unreal from source, Setup.sh downloads the native toolchain instead. A system Clang may not match the engine's version. エンジンのフォルダーで Engine/Build/BatchFiles/Linux/SetupToolchain.sh を実行し、同梱の Clang ツールチェーンをインストールします。ソースからビルドした場合は、代わりに Setup.sh がネイティブツールチェーンをダウンロードします。システムの Clang はエンジンのバージョンと一致しない場合があります。
Unreal is here, but it also needs Xcode. Unreal はありますが、Xcode も必要です。
About 60 GB, an Epic Games account, and Xcode. 約 60 GB、Epic Games アカウント、Xcode が必要です。
+File ファイル
+View 表示
+Window ウインドウ
+Help ヘルプ
+Command palette コマンドパレット
+Craft Anything on GitHub GitHub の Craft Anything
+Report a problem… 問題を報告…
+Quit Craft Anything Craft Anything を終了
+About Craft Anything Craft Anything について
+Services サービス
+Hide Craft Anything Craft Anything を非表示
+Hide others ほかを非表示
+Show all すべてを表示
+Close window ウインドウを閉じる
+Full screen フルスクリーン
+Zoom 拡大/縮小
+Bring all to front すべてを手前に移動
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 9b5a9b88..03f6f926 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -25,6 +25,8 @@ pub mod jobs;
pub mod just_ask;
pub mod make;
pub mod manage;
+#[cfg(target_os = "macos")]
+pub mod menu;
pub mod palette;
pub mod paste;
pub mod pins;
@@ -423,6 +425,9 @@ pub struct CraftApp {
pub persist: bool,
/// Never open native dialogs (tests and snapshots).
pub headless: bool,
+ /// The macOS menu bar, once the window is open ([`CraftApp::install_menu_bar`]).
+ #[cfg(target_os = "macos")]
+ pub menu_bar: Option<menu::MenuBar>,
pub view: SessionView,
pub jobs: jobs::Jobs<Done>,
pub conversation: Option<Box<dyn Conversation>>,
@@ -548,6 +553,8 @@ impl CraftApp {
first_frames: None,
persist: true,
headless: false,
+ #[cfg(target_os = "macos")]
+ menu_bar: None,
view: SessionView::default(),
jobs: jobs::Jobs::default(),
conversation: None,
@@ -617,6 +624,16 @@ impl CraftApp {
egui_extras::install_image_loaders(ctx);
}
+ /// Gives the macOS app its menu bar (nothing elsewhere). Call once the window is open.
+ pub fn install_menu_bar(&mut self, ctx: &egui::Context) {
+ #[cfg(target_os = "macos")]
+ {
+ self.menu_bar = menu::MenuBar::install(ctx);
+ }
+ #[cfg(not(target_os = "macos"))]
+ let _ = ctx;
+ }
+
/// Call `done` once [`FIRST_FRAMES`] frames have been drawn and shown: the window is really up by
/// then. eframe opens the window hidden and draws its first frame after the app is built, so
/// a graphics driver that crashes while presenting does so after that (#74).
@@ -1736,6 +1753,8 @@ impl CraftApp {
let ctx = ui.ctx().clone();
self.tick(&ctx);
self.shortcuts(&ctx);
+ #[cfg(target_os = "macos")]
+ menu::update(self, &ctx);
let t = theme::Tokens::get(&ctx);
// The title bar is on every screen: it is how the window moves, resizes and closes.
egui::Panel::top("titlebar").exact_size(titlebar::HEIGHT).frame(egui::Frame::new().fill(t.chrome)).show(ui, |ui| {
@@ -1852,13 +1871,12 @@ impl CraftApp {
painter.galley(inner.center() - g.size() / 2.0, g, t.text);
}
+ /// Keys that work on every screen: Ctrl/⌘ K for the palette, and Esc to close what's on top
+ /// (the palette, a dialog, Settings) or go back home.
fn shortcuts(&mut self, ctx: &egui::Context) {
let (palette, esc) = ctx.input_mut(|i| (i.consume_key(egui::Modifiers::COMMAND, egui::Key::K), i.key_pressed(egui::Key::Escape)));
- if palette && self.settings.first_run_done {
- self.state.palette.open = !self.state.palette.open;
- self.state.palette.query.clear();
- self.state.palette.selected = 0;
- self.state.palette.form_tool = None;
+ if palette {
+ palette::toggle(self);
}
if esc {
if self.state.palette.open {
diff --git a/crates/ui-egui/src/menu.rs b/crates/ui-egui/src/menu.rs
new file mode 100644
index 00000000..42e42cca
--- /dev/null
+++ b/crates/ui-egui/src/menu.rs
@@ -0,0 +1,211 @@
+//! The macOS menu bar: the app's own actions, with the shortcuts Mac apps use, beside the system's
+//! window and app items. Every label is in the app's language, and follows it when it changes.
+
+use crate::CraftApp;
+use crate::i18n::{self, tr};
+use crate::palette::{self, AppCommand};
+use crate::state::Screen;
+use craft_anything_engine::Mode;
+use muda::accelerator::{Accelerator, Code, Modifiers};
+use muda::{AboutMetadata, CheckMenuItem, Menu, MenuEvent, MenuId, MenuItem, PredefinedMenuItem, Submenu};
+use std::sync::mpsc::{Receiver, channel};
+
+const REPO: &str = env!("CARGO_PKG_REPOSITORY");
+const NEW_ISSUE: &str = concat!(env!("CARGO_PKG_REPOSITORY"), "/issues/new/choose");
+
+#[derive(Debug, Clone, Copy)]
+enum Action {
+ App(AppCommand),
+ NewProject,
+ Palette,
+ Mode(Mode),
+ Deep(bool),
+ Quit,
+ Url(&'static str),
+}
+
+/// A menu entry with a translated label, retitled when the language changes.
+enum Label {
+ Item(MenuItem),
+ Check(CheckMenuItem),
+ Sub(Submenu),
+ System(PredefinedMenuItem),
+}
+
+impl Label {
+ /// Shows `text` as the entry's label.
+ fn set(&self, text: &str) {
+ match self {
+ Label::Item(i) => i.set_text(text),
+ Label::Check(i) => i.set_text(text),
+ Label::Sub(i) => i.set_text(text),
+ Label::System(i) => i.set_text(text),
+ }
+ }
+}
+
+/// The menu bar, kept alive for as long as the app runs.
+pub struct MenuBar {
+ _menu: Menu,
+ actions: Vec<(MenuId, Action)>,
+ /// Each label with its English text, and the language they're shown in.
+ labels: Vec<(Label, &'static str)>,
+ language: String,
+ /// What only makes sense once first run is done (the palette's rule).
+ gated: Vec<MenuItem>,
+ simple: CheckMenuItem,
+ advanced: CheckMenuItem,
+ clean: CheckMenuItem,
+ deep: CheckMenuItem,
+ picked: Receiver<MenuId>,
+}
+
+fn cmd(key: Code) -> Option<Accelerator> {
+ Some(Accelerator::new(Modifiers::META, key))
+}
+
+impl MenuBar {
+ /// Builds the menu bar and puts it in place of the system's default one. Call on the main
+ /// thread once the window is open; `None` (logged) if the system refused it.
+ pub fn install(ctx: &egui::Context) -> Option<Self> {
+ let mut actions = Vec::new();
+ let mut labels = Vec::new();
+ let mut item = |label: &'static str, key: Option<Accelerator>, action: Action| {
+ let i = MenuItem::new(tr(label), true, key);
+ actions.push((i.id().clone(), action));
+ labels.push((Label::Item(i.clone()), label));
+ i
+ };
+ let settings = item("Settings", cmd(Code::Comma), Action::App(AppCommand::Settings));
+ let quit = item("Quit Craft Anything", cmd(Code::KeyQ), Action::Quit);
+ let new_project = item("New project", cmd(Code::KeyN), Action::NewProject);
+ let open_file = item("Open a file…", cmd(Code::KeyO), Action::App(AppCommand::OpenFile));
+ let open_folder =
+ item("Open a folder or app bundle…", Some(Accelerator::new(Modifiers::META | Modifiers::SHIFT, Code::KeyO)), Action::App(AppCommand::OpenFolder));
+ let export = item("Export a report (Markdown)", None, Action::App(AppCommand::ExportReport));
+ let palette = item("Command palette", cmd(Code::KeyK), Action::Palette);
+ let theme = item("Switch light / dark theme", None, Action::App(AppCommand::ToggleTheme));
+ let website = item("Craft Anything on GitHub", None, Action::Url(REPO));
+ let report = item("Report a problem…", None, Action::Url(NEW_ISSUE));
+ let mut check = |label: &'static str, action: Action| {
+ let i = CheckMenuItem::new(tr(label), true, false, None);
+ actions.push((i.id().clone(), action));
+ labels.push((Label::Check(i.clone()), label));
+ i
+ };
+ let simple = check("Simple", Action::Mode(Mode::Beginner));
+ let advanced = check("Advanced", Action::Mode(Mode::Experienced));
+ let clean = check("Clean room", Action::Deep(false));
+ let deep = check("Deep", Action::Deep(true));
+
+ let mut sub = |label: &'static str| {
+ let s = Submenu::new(tr(label), true);
+ labels.push((Label::Sub(s.clone()), label));
+ s
+ };
+ // The first submenu is the app menu; macOS titles it with the app's name.
+ let app_menu = Submenu::new("Craft Anything", true);
+ let file = sub("File");
+ let view = sub("View");
+ let window = sub("Window");
+ let help = sub("Help");
+ // The system's own items, named in the app's language rather than the system's.
+ let mut system = |make: fn(Option<&str>) -> PredefinedMenuItem, label: &'static str| {
+ let i = make(Some(&tr(label)));
+ labels.push((Label::System(i.clone()), label));
+ i
+ };
+ let services = system(PredefinedMenuItem::services, "Services");
+ let hide = system(PredefinedMenuItem::hide, "Hide Craft Anything");
+ let hide_others = system(PredefinedMenuItem::hide_others, "Hide others");
+ let show_all = system(PredefinedMenuItem::show_all, "Show all");
+ let close_window = system(PredefinedMenuItem::close_window, "Close window");
+ let fullscreen = system(PredefinedMenuItem::fullscreen, "Full screen");
+ let minimise = system(PredefinedMenuItem::minimize, "Minimise");
+ let zoom = system(PredefinedMenuItem::maximize, "Zoom");
+ let to_front = system(PredefinedMenuItem::bring_all_to_front, "Bring all to front");
+ let about_metadata = AboutMetadata { name: Some("Craft Anything".into()), version: Some(env!("CARGO_PKG_VERSION").into()), ..Default::default() };
+ let about = PredefinedMenuItem::about(Some(&tr("About Craft Anything")), Some(about_metadata));
+ labels.push((Label::System(about.clone()), "About Craft Anything"));
+ let sep = PredefinedMenuItem::separator;
+ let menu = Menu::new();
+ let built = app_menu
+ .append_items(&[&about, &sep(), &settings, &sep(), &services, &sep(), &hide, &hide_others, &show_all, &sep(), &quit])
+ .and_then(|()| file.append_items(&[&new_project, &open_file, &open_folder, &sep(), &export, &sep(), &close_window]))
+ .and_then(|()| view.append_items(&[&palette, &sep(), &simple, &advanced, &sep(), &clean, &deep, &sep(), &theme, &sep(), &fullscreen]))
+ .and_then(|()| window.append_items(&[&minimise, &zoom, &sep(), &to_front]))
+ .and_then(|()| help.append_items(&[&website, &report]))
+ .and_then(|()| menu.append_items(&[&app_menu, &file, &view, &window, &help]));
+ if let Err(e) = built {
+ log::warn!("the menu bar couldn't be built: {e}");
+ return None;
+ }
+ menu.init_for_nsapp();
+ window.set_as_windows_menu_for_nsapp();
+ help.set_as_help_menu_for_nsapp();
+
+ // Picks arrive between frames: pass them on and wake the UI to act on them.
+ let (tx, picked) = channel();
+ let ctx = ctx.clone();
+ MenuEvent::set_event_handler(Some(move |e: MenuEvent| {
+ let _ = tx.send(e.id);
+ ctx.request_repaint();
+ }));
+ let gated = vec![settings, new_project, open_file, open_folder, export, palette, theme];
+ Some(Self { _menu: menu, actions, labels, language: i18n::language(), gated, simple, advanced, clean, deep, picked })
+ }
+}
+
+/// Runs what was picked since the last frame and shows the current mode and switches.
+pub fn update(app: &mut CraftApp, ctx: &egui::Context) {
+ if let Some(bar) = app.menu_bar.as_mut() {
+ let language = i18n::language();
+ if bar.language != language {
+ for (label, text) in &bar.labels {
+ label.set(&tr(text));
+ }
+ bar.language = language;
+ }
+ }
+ let Some(bar) = app.menu_bar.as_ref() else { return };
+ let ready = app.settings.first_run_done;
+ let picked: Vec<Action> = bar.picked.try_iter().filter_map(|id| bar.actions.iter().find(|(i, _)| *i == id).map(|(_, a)| *a)).collect();
+ for i in &bar.gated {
+ if i.is_enabled() != ready {
+ i.set_enabled(ready);
+ }
+ }
+ let deep = app.settings.deep_mode;
+ let beginner = app.beginner();
+ for (item, on) in [(&bar.simple, beginner), (&bar.advanced, !beginner), (&bar.clean, !deep), (&bar.deep, deep)] {
+ if item.is_enabled() != ready {
+ item.set_enabled(ready);
+ }
+ if item.is_checked() != on {
+ item.set_checked(on);
+ }
+ }
+ for action in picked {
+ match action {
+ Action::Quit => ctx.send_viewport_cmd(egui::ViewportCommand::Close),
+ Action::Url(url) => ctx.open_url(egui::OpenUrl::new_tab(url)),
+ _ if !ready => {}
+ Action::App(c) => palette::run_app_command(app, c),
+ Action::NewProject => app.state.screen = Screen::Home,
+ Action::Palette => palette::toggle(app),
+ Action::Mode(m) => app.set_mode(m),
+ Action::Deep(on) => app.set_deep(on),
+ }
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ /// An empty repository field made Help open a local folder instead of the web page.
+ #[test]
+ fn help_links_are_web_pages() {
+ for url in [super::REPO, super::NEW_ISSUE] {
+ assert!(url.starts_with("https://github.com/"), "{url}");
+ }
+ }
+}
diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs
index c5edb466..0ffbf9de 100644
--- a/crates/ui-egui/src/palette.rs
+++ b/crates/ui-egui/src/palette.rs
@@ -9,7 +9,7 @@ use craft_anything_engine::{Consent, Mode};
use egui::{Margin, RichText, Vec2};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-enum AppCommand {
+pub(crate) enum AppCommand {
OpenFile,
OpenFolder,
ToggleMode,
@@ -207,7 +207,18 @@ pub fn show(app: &mut CraftApp, ctx: &egui::Context) {
}
}
-fn run_app_command(app: &mut CraftApp, c: AppCommand) {
+/// Opens or closes the palette (Ctrl/⌘ K), once first run is done.
+pub(crate) fn toggle(app: &mut CraftApp) {
+ if app.settings.first_run_done {
+ app.state.palette.open = !app.state.palette.open;
+ app.state.palette.query.clear();
+ app.state.palette.selected = 0;
+ app.state.palette.form_tool = None;
+ }
+}
+
+/// Runs one of the app's own commands, from the palette or the macOS menu bar.
+pub(crate) fn run_app_command(app: &mut CraftApp, c: AppCommand) {
match c {
AppCommand::OpenFile => app.pick(Pick::OpenFile),
AppCommand::OpenFolder => app.pick(Pick::OpenFolder),
diff --git a/crates/ui-egui/tests/headless_parity.rs b/crates/ui-egui/tests/headless_parity.rs
index 3d0073b0..9af0db2f 100644
--- a/crates/ui-egui/tests/headless_parity.rs
+++ b/crates/ui-egui/tests/headless_parity.rs
@@ -150,7 +150,7 @@ const PLUMBING: &[(&str, &str)] = &[
("acted", "shows a button tool's result (toast, open the preview)"),
("engines_found", "a job's result"), ("engine_got", "a job's result"), ("ghidra_got", "a job's result"),
("ghidra_ready", "a query"), ("ghidra_missing", "a query"),
- ("load_prefs", "startup"), ("after_first_frames", "startup"), ("log", "the log panel"), ("toast", "a message"),
+ ("load_prefs", "startup"), ("after_first_frames", "startup"), ("install_menu_bar", "startup; its items run palette commands"), ("log", "the log panel"), ("toast", "a message"),
("check_pictures", "a picture-size preflight"), ("picture_check_finished", "a preflight's result"),
("keep_attachments", "part of pictures_checked"),
("attach_checked", "part of pictures_checked"), ("add_pictures_checked", "part of pictures_checked"),
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index f15fa1a9..8ac05c47 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -738,6 +738,12 @@ Gaps found while using the app for real projects.
- [ ] Keep the builder-availability smoke regression independent of live agent discovery.
— claimed: Afloat16, branch test/r2.9-builder-discovery-fixture-20261104
Test fixture implemented with controlled discovery; automated validation remains pending.
+- [x] macOS: a menu bar with the app's own actions (open a file or folder, new project, settings,
+ Simple / Advanced, Clean room / Deep, the command palette, help); the system's menu bar
+ showed only the app menu
+ — claimed: sanketdofe, branch feature/r2.9-macos-menu-bar
+- [ ] macOS: an Edit menu (Undo, Cut, Copy, Paste, Select All). The keys work in text boxes, but
+ the system's Edit items need the text box to answer them, so they'd show greyed out today
### R2.10 Pinned builds
Owner: maintainers · Status: in progress
diff --git a/docs/STATUS.md b/docs/STATUS.md
index 5b2094fc..5c0407bc 100644
--- a/docs/STATUS.md
+++ b/docs/STATUS.md
@@ -47,7 +47,7 @@ workspace clippy, layers, fmt and the secret scan of all history were clean. Chi
| WebAssembly tag interfaces | `formats_wasm_compare` resolves retained imported and defined tag exports to their declared parameter types. Identical unresolved or invalid diagnostics may still count as unchanged; those counts do not establish interface compatibility, and invalid/partial limitations remain present | Synthetic core modules with tag changes and re-exports, mixed index spaces, import/tag limits, and missing or non-function type references; formats and engine tests. No real module corpus or WebAssembly execution was used for this correction |
| Questions and approvals | A file inbox per project; `core_person_ask`, `core_action_approve` and MCP consent requests become cards in the app | Cross-handle round-trip tests, a full approval round trip through the engine |
| Runtime assets in pinned builds | Frozen and light pins, size estimates and project copies keep runtime files in `obj` folders. An `obj` directory beside a regular C#, F# or Visual Basic project file is still recognised as compiler output; ambiguous folders are retained. New pins record the direct-launch program relative to the copy so a newer helper cannot replace it; older pins retain discovery behavior | Synthetic filesystem tests cover both pin modes, model bytes, compiler-output controls and project duplication. A Linux tool-level regression starts temporary scripts through `project_pin_open`, with a newer `Build/obj/helper`, and verifies the originally selected program and its output; a missing recorded program is refused. No real pinned application was launched for this correction |
-| Desktop app | Simple mode: sidebar with New project and the project history (kept across restarts); New project makes something, works on a project the person already has (Work on my project: its folder's files are the app, edited in place without a question, and the project takes the folder's name), or just looks inside an app or file, a website or a game's files; a Game files screen (a game's archives; pictures from Unreal paks, Unity .assets files and Unity bundles saved as PNG after the person confirms they may unpack the game; uncompressed textures and the block formats DXT1, DXT5 and BC4–BC7), make prompt with picture attachments (picked, dropped, or pasted with Ctrl+V, shown as picture tiles) and, for anything recreated, a Clean room / Deep choice (also in the title bar; in Clean room, Just look inside, Game files, opening a file and the workbench ask for Deep mode instead), project screen (steps with the time spent and the AI cost and tokens of every build, saved in the project's usage.json by the run (a coding agent's figure is shown as an estimate at API prices, not the bill), what the build is on now and its activity as it arrives (kept in `build-activity.log`), pinned builder checklist (its X folds it away between builds, kept in the project, `project_plan_fold`; a later run's checklist shows again), feed, question and approval cards, a Continue card when a build was paused or stopped part-way (the app or computer closed; the project shows Interrupted) that carries on the builder's own session instead of starting over, and "It's done" beside Continue or Try again to keep the build as it is (`project_build_finish`), checks with screenshots and the requirements not met yet, the builder's open questions, preview, play, folder, follow-ups while it builds, which Claude Code takes at its next step; Up in the prompt box takes back the last note still waiting). Projects can start in a folder the person picks, whose files are either the app, edited in place (its stack read from those files unless the request names another, and, with nothing to recreate, judged by its own build and tests, whatever it's written in), or material to start from (asked, or the answer remembered in Settings), and are listed from any number of folders (`project_folders`, `project_list`, `rebuild --project-folder`). Make says which AI builds ("Built by": automatic, or any AI that can build, by name); a pick stays with the project and builds its later changes. With nothing to build with, Start offers the coding agents found on the computer. Settings → AI turns an AI off or removes it, and sets how hard the Claude API or Claude Code thinks (every Claude level, low to max; also `ai effort` in the CLI). Each Claude Code AI can keep its sign-in in a folder of its own (its `CLAUDE_CONFIG_DIR`, so its own account; `ai folder` in the CLI, a folder on that computer over SSH), used for its runs, its sign-in check and its kept session, and Add another adds a second Claude Code for a second account. In the prompt box, Up at the very start and Down at the very end go through earlier prompts when no note is waiting. Questions about a build ("Just ask" under the prompt box, or a message starting with `/btw`, the first slash command; `rebuild_question_ask`) are answered in the conversation, where each folds away and is kept in the project, without a build or a round and changing nothing: Claude Code answers from a read-only copy of the builder's own session. Under each project's prompt box, "Builder's questions: Ask me / Decide yourself" chooses whether the builder's questions come to the person as cards or are decided by the builder, which says what it chose (`project_questions_set`; the default is in Settings and follows Auto mode until picked). Projects can be renamed, duplicated and deleted (right-click in the sidebar, or the project's page; a delete keeps the person's own files). A build can be pinned (Pin this build on its page, or `project_pin_*` from the CLI and MCP): a frozen copy in the project's pinned/ folder (the default) or a light one that shares dependencies and media with the project through hard links (each one's size shown first), opened from the sidebar's collapsible Pinned section (icons with a running dot when folded); a pin or Play runs once per folder unless another copy is asked for, and a start that quits at once says so with its last output. Typed drafts survive a restart. In a narrow window the sidebar folds to icons and the project's details move above its feed; messages float over the screen and errors stay until dismissed. Advanced mode: workbench with every panel wired to real tools, as a screen beside the projects (builds and their questions stay a click away) | UI unit and smoke tests (egui_kittest), offscreen snapshots of every screen |
+| Desktop app | Simple mode: sidebar with New project and the project history (kept across restarts); New project makes something, works on a project the person already has (Work on my project: its folder's files are the app, edited in place without a question, and the project takes the folder's name), or just looks inside an app or file, a website or a game's files; a Game files screen (a game's archives; pictures from Unreal paks, Unity .assets files and Unity bundles saved as PNG after the person confirms they may unpack the game; uncompressed textures and the block formats DXT1, DXT5 and BC4–BC7), make prompt with picture attachments (picked, dropped, or pasted with Ctrl+V, shown as picture tiles) and, for anything recreated, a Clean room / Deep choice (also in the title bar; in Clean room, Just look inside, Game files, opening a file and the workbench ask for Deep mode instead), project screen (steps with the time spent and the AI cost and tokens of every build, saved in the project's usage.json by the run (a coding agent's figure is shown as an estimate at API prices, not the bill), what the build is on now and its activity as it arrives (kept in `build-activity.log`), pinned builder checklist (its X folds it away between builds, kept in the project, `project_plan_fold`; a later run's checklist shows again), feed, question and approval cards, a Continue card when a build was paused or stopped part-way (the app or computer closed; the project shows Interrupted) that carries on the builder's own session instead of starting over, and "It's done" beside Continue or Try again to keep the build as it is (`project_build_finish`), checks with screenshots and the requirements not met yet, the builder's open questions, preview, play, folder, follow-ups while it builds, which Claude Code takes at its next step; Up in the prompt box takes back the last note still waiting). Projects can start in a folder the person picks, whose files are either the app, edited in place (its stack read from those files unless the request names another, and, with nothing to recreate, judged by its own build and tests, whatever it's written in), or material to start from (asked, or the answer remembered in Settings), and are listed from any number of folders (`project_folders`, `project_list`, `rebuild --project-folder`). Make says which AI builds ("Built by": automatic, or any AI that can build, by name); a pick stays with the project and builds its later changes. With nothing to build with, Start offers the coding agents found on the computer. Settings → AI turns an AI off or removes it, and sets how hard the Claude API or Claude Code thinks (every Claude level, low to max; also `ai effort` in the CLI). Each Claude Code AI can keep its sign-in in a folder of its own (its `CLAUDE_CONFIG_DIR`, so its own account; `ai folder` in the CLI, a folder on that computer over SSH), used for its runs, its sign-in check and its kept session, and Add another adds a second Claude Code for a second account. In the prompt box, Up at the very start and Down at the very end go through earlier prompts when no note is waiting. Questions about a build ("Just ask" under the prompt box, or a message starting with `/btw`, the first slash command; `rebuild_question_ask`) are answered in the conversation, where each folds away and is kept in the project, without a build or a round and changing nothing: Claude Code answers from a read-only copy of the builder's own session. Under each project's prompt box, "Builder's questions: Ask me / Decide yourself" chooses whether the builder's questions come to the person as cards or are decided by the builder, which says what it chose (`project_questions_set`; the default is in Settings and follows Auto mode until picked). Projects can be renamed, duplicated and deleted (right-click in the sidebar, or the project's page; a delete keeps the person's own files). A build can be pinned (Pin this build on its page, or `project_pin_*` from the CLI and MCP): a frozen copy in the project's pinned/ folder (the default) or a light one that shares dependencies and media with the project through hard links (each one's size shown first), opened from the sidebar's collapsible Pinned section (icons with a running dot when folded); a pin or Play runs once per folder unless another copy is asked for, and a start that quits at once says so with its last output. Typed drafts survive a restart. In a narrow window the sidebar folds to icons and the project's details move above its feed; messages float over the screen and errors stay until dismissed. Advanced mode: workbench with every panel wired to real tools, as a screen beside the projects (builds and their questions stay a click away). On macOS the menu bar has the app's actions (open, new project, settings, Simple / Advanced, Clean room / Deep, the command palette, help) with the usual shortcuts | UI unit and smoke tests (egui_kittest), offscreen snapshots of every screen |
| CLI | Every tool, `--deep` or `--clean-room` for one run (never saved), `rebuild` (including `--continue-in`, and `--resume` to carry on a stopped build), `mcp --inbox`, `ai`, `setup`, `doctor`, `report` | CLI integration tests |
| SQLite database files (`db_sqlite_show`) | A rowid alias column (`INTEGER PRIMARY KEY`, including the table-constraint form) shows the rowid; `DESC`, non-`INTEGER` and composite keys keep their stored values | Hand-built fixtures; generated files compared with the official SQLite library |
| SQLite WITHOUT ROWID tables | Read from the index b-tree, interior records and overflow included; rows in primary-key order, values in declaration order, `rowid` null | Hand-built fixtures; generated files compared with the official SQLite library |