Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Merge remote-tracking branch 'upstream/main' into macos-menus

Ilya4ef3f635da34
diff --cc apps/cli/tests/cli.rs
index d3372bb3e,3e7a3c8c8..8177fb7e0
--- a/apps/cli/tests/cli.rs
+++ b/apps/cli/tests/cli.rs
@@@ -702,9 -702,11 +702,32 @@@ fn project_config_get_without_file_retu
]);
assert!(output.status.success(), "stderr: {}", stderr(&output));
let json = parse_json(&output);
- assert!(json.is_object(), "expected a default project config object");
+ let expected_json =
+ serde_json::to_string(&cap_project::ProjectConfiguration::default()).unwrap();
+ assert_eq!(json, serde_json::from_str::<Value>(&expected_json).unwrap());
+ }
+
++#[test]
++fn project_config_commands_reject_directories_without_recordings() {
++ let dir = tempfile::tempdir().unwrap();
++ let project = dir.path().join("not-a-recording.cap");
++ std::fs::create_dir(&project).unwrap();
++
++ for command in ["get", "set"] {
++ let mut args = vec!["project", "config", command, project.to_str().unwrap()];
++ if command == "set" {
++ args.extend(["--settings-json", "{}"]);
++ }
++ args.push("--json");
++
++ let output = run(&args);
++ assert!(!output.status.success(), "{command} unexpectedly succeeded");
++ assert!(parse_json(&output)["error"].is_string());
++ }
++
++ assert!(!project.join("project-config.json").exists());
+}
+
#[test]
fn project_config_commands_reject_directories_without_recordings() {
let dir = tempfile::tempdir().unwrap();
diff --cc apps/desktop-gpui/Cargo.toml
index e51320a0a,8de8fcd39..1a62219b6
--- a/apps/desktop-gpui/Cargo.toml
+++ b/apps/desktop-gpui/Cargo.toml
@@@ -103,13 -100,12 +103,16 @@@ ffmpeg = { package = "ffmpeg-next", gi
# `webp` is the config sidebar's four background-source illustrations, which
# the app ships as webp; features are additive, so enabling it here does not
# move gpui's own pin.
-image = { version = "0.25.1", default-features = false, features = ["jpeg", "png", "webp"] }
+image = { version = "0.25.1", default-features = false, features = [
+ "jpeg",
+ "png",
+ "webp",
+] }
jpeg-decoder = "0.3"
smallvec = "1"
+ # The OS language list the UI language follows when set to System default.
+ # Already in this lockfile through cosmic-text.
+ sys-locale = "0.3"
# Grapheme boundaries for `ui::TextInput`: Backspace deletes a user-perceived
# character, not a `char`, so a flag emoji or a combining accent goes in one
# press. gpui's own input example uses the same crate and it is already in this
diff --cc apps/desktop-gpui/src/feeds.rs
index 4b02665fb,4b02665fb..14ce0bd60
--- a/apps/desktop-gpui/src/feeds.rs
+++ b/apps/desktop-gpui/src/feeds.rs
@@@ -341,9 -341,9 +341,9 @@@ impl RecordingCameraWorker
}
self.publisher.publish(
cap_recording::instant_recording::LinuxProcessedCameraFrame {
-- bgra: cap_recording::instant_recording::LinuxCameraPixels::new(
-- RenderImagePixels(image.clone()),
-- ),
++ bgra: cap_recording::instant_recording::LinuxCameraPixels::new(RenderImagePixels(
++ image.clone(),
++ )),
dimensions: (dims.0 as u32, dims.1 as u32),
stride: dims.0 * 4,
timestamp,
diff --cc apps/desktop-gpui/src/main.rs
index ecdc47011,f4a441758..ebeaeec01
--- a/apps/desktop-gpui/src/main.rs
+++ b/apps/desktop-gpui/src/main.rs
@@@ -44,7 -47,9 +47,9 @@@ mod i18n
mod import;
mod installer;
mod jpeg_thumbnail;
+mod library;
+ #[cfg(not(any(target_os = "macos", target_os = "windows")))]
+ mod linux_dialog;
-mod library;
mod main_window;
mod media_access;
mod menus;
diff --cc apps/desktop-gpui/src/menus.rs
index eff030be9,118f85823..d3f4db824
--- a/apps/desktop-gpui/src/menus.rs
+++ b/apps/desktop-gpui/src/menus.rs
@@@ -38,78 -39,9 +41,78 @@@ use crate::
};
/// `productName` in `tauri.conf.json`, which is what macOS renames the first
- /// submenu to and what the About/Hide/Quit labels interpolate.
+ /// submenu to.
pub const APP_NAME: &str = "Cap";
+struct MenuRegistration(UpdateRow);
+
+impl Global for MenuRegistration {}
+
+/// What the Check for Update row currently says. Download progress only moves
+/// the badge, and only macOS applies it without rebuilding the menu bar, so a
+/// percentage tick never touches the menu on the other platforms.
+#[derive(Clone, PartialEq)]
+struct UpdateRow {
+ title: &'static str,
+ enabled: bool,
+ badge: Option<String>,
+}
+
+const CHECK_TITLE: &str = "Check for Update";
+const CHECKING_TITLE: &str = "Checking for Update…";
+const DOWNLOAD_TITLE: &str = "Download update…";
+const RESTART_TITLE: &str = "Restart to update…";
+
+// macOS recognizes `Preferences…` as the proper menu item for settings.
+// On macOS 15+ it uses the new translation showing `Settings…` along with the gear sf symbol.
+#[cfg(target_os = "macos")]
+const SETTINGS_LABEL: &str = "Preferences…";
+#[cfg(not(target_os = "macos"))]
+const SETTINGS_LABEL: &str = "Settings…";
+
+impl UpdateRow {
+ fn of(status: &updates::UpdateStatus) -> Self {
+ use updates::UpdateStatus;
+
+ let title = match status {
+ UpdateStatus::Idle => CHECK_TITLE,
+ UpdateStatus::Checking => CHECKING_TITLE,
+ UpdateStatus::Downloading { .. } | UpdateStatus::Installing { .. } => DOWNLOAD_TITLE,
+ UpdateStatus::Ready { .. } | UpdateStatus::Installed { .. } => RESTART_TITLE,
+ };
+ Self {
+ title,
+ enabled: !matches!(status, UpdateStatus::Checking),
+ badge: update_menu_badge(status),
+ }
+ }
+}
+
+#[cfg(target_os = "macos")]
+fn update_menu_badge(status: &updates::UpdateStatus) -> Option<String> {
+ use updates::UpdateStatus;
+
+ match status {
+ UpdateStatus::Downloading {
+ version,
+ fraction: Some(fraction),
+ } => Some(format!(
+ "v{version} · {}%",
+ (fraction * 100.0).round() as u32
+ )),
+ UpdateStatus::Downloading { version, .. }
+ | UpdateStatus::Ready { version }
+ | UpdateStatus::Installing { version }
+ | UpdateStatus::Installed { version, .. } => Some(format!("v{version}")),
+ UpdateStatus::Idle | UpdateStatus::Checking => None,
+ }
+}
+
+#[cfg(not(target_os = "macos"))]
+fn update_menu_badge(_: &updates::UpdateStatus) -> Option<String> {
+ None
+}
+
/// `env!("CARGO_PKG_VERSION")`, exactly as `build_tray_menu` spells it -- this
/// crate's version, which is the gpui app's own (0.1.x) rather than the
/// shipping desktop app's. Noted as a deviation in the report: there is no
@@@ -246,34 -133,37 +249,62 @@@ pub fn init(cx: &mut App)
with_key_native(cx, platform::toggle_fullscreen_native)
});
- cx.set_menus(build_menus());
+ cx.set_global(MenuRegistration(UpdateRow::of(&updates::status(cx))));
+ install_menus(cx);
+ MENUS_INSTALLED.store(true, Ordering::Relaxed);
+ #[cfg(target_os = "macos")]
+ if crate::i18n::current() != crate::i18n::Locale::En {
+ register_system_menus();
+ }
+ }
+
+ static MENUS_INSTALLED: AtomicBool = AtomicBool::new(false);
+
+ /// Rebuild the menu bar in the current language, if [`init`] installed one.
+ pub fn refresh(cx: &mut App) {
+ if !MENUS_INSTALLED.load(Ordering::Relaxed) {
+ return;
+ }
- cx.set_menus(build_menus());
++ install_menus(cx);
+ #[cfg(target_os = "macos")]
+ register_system_menus();
+ }
+
+ /// gpui only registers a Window menu titled "Window" and never registers Help.
+ /// English keeps exactly what gpui sets up; a translated bar gets both.
+ #[cfg(target_os = "macos")]
+ fn register_system_menus() {
+ let translated = crate::i18n::current() != crate::i18n::Locale::En;
+ platform::register_system_menus(
+ tr::menu::window::title(),
+ translated.then(tr::menu::help::title),
+ );
}
+pub(crate) fn refresh_update_menu(cx: &mut App) {
+ if !cx.has_global::<MenuRegistration>() {
+ return;
+ }
+
+ let row = UpdateRow::of(&updates::status(cx));
+ if cx.global::<MenuRegistration>().0 == row {
+ return;
+ }
+ cx.global_mut::<MenuRegistration>().0 = row.clone();
+
+ #[cfg(target_os = "macos")]
+ platform::set_update_menu_item(row.title, row.badge.as_deref(), row.enabled);
+ #[cfg(not(target_os = "macos"))]
+ install_menus(cx);
+}
+
+fn install_menus(cx: &mut App) {
+ let update_status = updates::status(cx);
+ cx.set_menus(build_menus(&update_status));
+ #[cfg(target_os = "macos")]
+ platform::patch_standard_application_menu();
+}
+
pub(crate) fn bindings() -> Vec<KeyBinding> {
vec![
KeyBinding::new("cmd-q", Quit, None),
@@@ -302,31 -190,28 +333,31 @@@ pub fn build_menus(update_status: &upda
name: APP_NAME.into(),
disabled: false,
items: vec![
- MenuItem::action(format!("About {APP_NAME}"), About),
+ MenuItem::action(tr::menu::app::about(), About),
+ MenuItem::action(update_row.title, CheckForUpdate).disabled(!update_row.enabled),
MenuItem::separator(),
- MenuItem::action(tr::menu::app::settings(), OpenSettings),
+ MenuItem::action(SETTINGS_LABEL, OpenSettings),
MenuItem::separator(),
- MenuItem::os_submenu("Services", SystemMenuType::Services),
+ MenuItem::os_submenu(tr::menu::app::services(), SystemMenuType::Services),
MenuItem::separator(),
- MenuItem::action(format!("Hide {APP_NAME}"), HideSelf),
- MenuItem::action("Hide Others", HideOthers),
+ MenuItem::action(tr::menu::app::hide(), HideSelf),
+ MenuItem::action(tr::menu::app::hide_others(), HideOthers),
MenuItem::separator(),
- MenuItem::action(format!("Quit {APP_NAME}"), Quit),
+ MenuItem::action(tr::menu::app::quit(), Quit),
],
},
Menu {
- name: "File".into(),
+ name: tr::menu::file::title().into(),
disabled: false,
- items: vec![MenuItem::action(
- tr::menu::file::close_window(),
- CloseWindow,
- )],
+ items: vec![
+ MenuItem::action("Open File…", OpenFile),
+ MenuItem::action("Import Media…", ImportMedia),
+ MenuItem::separator(),
- MenuItem::action("Close Window", CloseWindow),
++ MenuItem::action(tr::menu::file::close_window(), CloseWindow),
+ ],
},
Menu {
- name: "Edit".into(),
+ name: tr::menu::edit::title().into(),
disabled: false,
// The text field's own actions, tagged with the AppKit selector
// that belongs to each. gpui routes `cut:`/`copy:`/`paste:`/
@@@ -365,19 -260,9 +406,19 @@@
],
},
Menu {
- name: "Help".into(),
+ name: tr::menu::help::title().into(),
disabled: false,
- items: vec![],
+ items: vec![
+ MenuItem::action("Changelog", Changelog),
+ MenuItem::separator(),
+ MenuItem::action("Dashboard", HelpDashboard),
+ MenuItem::action("Documentation", HelpDocs),
+ MenuItem::action("FAQ", HelpFaq),
+ MenuItem::action("Self-hosting", HelpSelfHosting),
+ MenuItem::action("Help Center", HelpCenter),
+ MenuItem::action("System Status", HelpStatus),
+ MenuItem::action("Join Discord Community", HelpDiscord),
+ ],
},
]
}
diff --cc apps/desktop-gpui/src/onboarding_window.rs
index 8027f9611,a19f48ab1..3703af15c
--- a/apps/desktop-gpui/src/onboarding_window.rs
+++ b/apps/desktop-gpui/src/onboarding_window.rs
@@@ -1244,12 -1246,12 +1246,16 @@@ impl OnboardingWindow
.justify_center()
.gap(px(4.))
.child(
- copy("Click here, or press", 11., ink.opacity(0.55))
- copy(tr::onboarding::welcome::click_or_press(), 11., ink.opacity(0.55))
-- .font_weight(FontWeight::NORMAL)
-- .line_height(px(14.)),
++ copy(
++ tr::onboarding::welcome::click_or_press(),
++ 11.,
++ ink.opacity(0.55),
++ )
++ .font_weight(FontWeight::NORMAL)
++ .line_height(px(14.)),
)
.child(
- copy("Space", 10., ink.opacity(0.7))
+ copy(tr::onboarding::welcome::space_key(), 10., ink.opacity(0.7))
.font_weight(FontWeight::MEDIUM)
.line_height(px(14.))
.px(px(4.))
@@@ -1288,18 -1290,18 +1294,14 @@@
.child(welcome_script(written, title_opacity)),
)
.child(
-- copy(
- "The open source screen sharing app for everyone.",
- tr::onboarding::welcome::tagline(),
-- 22.,
-- ink.opacity(0.75),
-- )
-- .relative()
-- .top(px(subtitle_y))
-- .opacity(subtitle_opacity)
-- .font_family("Source Serif 4")
-- .font_weight(FontWeight::LIGHT)
-- .line_height(px(32.))
-- .whitespace_nowrap(),
++ copy(tr::onboarding::welcome::tagline(), 22., ink.opacity(0.75))
++ .relative()
++ .top(px(subtitle_y))
++ .opacity(subtitle_opacity)
++ .font_family("Source Serif 4")
++ .font_weight(FontWeight::LIGHT)
++ .line_height(px(32.))
++ .whitespace_nowrap(),
)
.child(button)
.when_some(self.error.clone(), |el, error| {
@@@ -1340,18 -1342,18 +1342,64 @@@
fn render_overview(&self) -> AnyElement {
let theme = self.theme;
-- div().flex().flex_col().items_center().justify_center().min_h_full().px(px(40.)).gap(px(32.))
- .child(self.heading("One app, every workflow", "Whether you need speed, studio quality, or a quick screenshot — Cap has a mode for it."))
- .child(self.heading(tr::onboarding::overview::title(), tr::onboarding::overview::subtitle()))
-- .child(div().flex().gap(px(16.)).w_full().max_w(px(540.)).children(MODES.iter().enumerate().map(|(index, mode)| {
-- let paper = stage::Paper::new(&theme);
-- let card = self.paper_card().flex_1().min_w_0().flex().flex_col().items_center().gap(px(10.)).px(px(20.)).pt(px(22.)).pb(px(24.))
-- .child(crate::doodle::doodle(mode_doodle(mode.mode), paper.palette(), self.step_at + Duration::from_millis(index as u64 * 180), !self.animated, 96., 84.))
- .child(copy(mode.title, 15., paper.ink).font_weight(FontWeight::MEDIUM).text_center().mt(px(4.)))
- .child(copy(mode.tagline, 12., paper.soft).font_weight(FontWeight::NORMAL).line_height(px(16.)).text_center());
- .child(copy((mode.title)(), 15., paper.ink).font_weight(FontWeight::MEDIUM).text_center().mt(px(4.)))
- .child(copy((mode.tagline)(), 12., paper.soft).font_weight(FontWeight::NORMAL).line_height(px(16.)).text_center());
-- if !self.animated { return card.into_any_element(); }
-- card.with_animation(("overview-card", index), Animation::new(Duration::from_millis(700 + index as u64 * 100)),
-- |el, t| el.relative().top(px(16. * (1. - ease(t)))).opacity(ease(t))).into_any_element()
-- }))).into_any_element()
++ div()
++ .flex()
++ .flex_col()
++ .items_center()
++ .justify_center()
++ .min_h_full()
++ .px(px(40.))
++ .gap(px(32.))
++ .child(self.heading(
++ tr::onboarding::overview::title(),
++ tr::onboarding::overview::subtitle(),
++ ))
++ .child(div().flex().gap(px(16.)).w_full().max_w(px(540.)).children(
++ MODES.iter().enumerate().map(|(index, mode)| {
++ let paper = stage::Paper::new(&theme);
++ let card = self
++ .paper_card()
++ .flex_1()
++ .min_w_0()
++ .flex()
++ .flex_col()
++ .items_center()
++ .gap(px(10.))
++ .px(px(20.))
++ .pt(px(22.))
++ .pb(px(24.))
++ .child(crate::doodle::doodle(
++ mode_doodle(mode.mode),
++ paper.palette(),
++ self.step_at + Duration::from_millis(index as u64 * 180),
++ !self.animated,
++ 96.,
++ 84.,
++ ))
++ .child(
++ copy((mode.title)(), 15., paper.ink)
++ .font_weight(FontWeight::MEDIUM)
++ .text_center()
++ .mt(px(4.)),
++ )
++ .child(
++ copy((mode.tagline)(), 12., paper.soft)
++ .font_weight(FontWeight::NORMAL)
++ .line_height(px(16.))
++ .text_center(),
++ );
++ if !self.animated {
++ return card.into_any_element();
++ }
++ card.with_animation(
++ ("overview-card", index),
++ Animation::new(Duration::from_millis(700 + index as u64 * 100)),
++ |el, t| el.relative().top(px(16. * (1. - ease(t)))).opacity(ease(t)),
++ )
++ .into_any_element()
++ }),
++ ))
++ .into_any_element()
}
fn render_detail(&self, index: usize) -> AnyElement {
@@@ -1538,19 -1540,19 +1586,61 @@@
fn render_shortcuts(&self) -> AnyElement {
let theme = self.theme;
-- div().flex().flex_col().items_center().justify_center().min_h_full().px(px(48.)).gap(px(24.))
- .child(self.heading("Make Cap yours", "Customize everything from keyboard shortcuts to storage. Cap adapts to your workflow."))
- .child(self.heading(tr::onboarding::customize::title(), tr::onboarding::customize::subtitle()))
-- .child(div().flex().flex_col().w_full().max_w(px(420.)).gap(px(8.)).children([
- ("Keyboard Shortcuts", "Global hotkeys for recording, screenshots, and switching modes"),
- ("Custom S3 Storage", "Connect your own S3-compatible bucket for full control over your recordings"),
- ("Custom Domain", "Use your own domain for shareable links instead of cap.so"),
- ("Recording Preferences", "FPS, quality, countdown timer, cursor effects, and more"),
- (tr::onboarding::customize::shortcuts::title(), tr::onboarding::customize::shortcuts::description()),
- (tr::onboarding::customize::s3::title(), tr::onboarding::customize::s3::description()),
- (tr::onboarding::customize::domain::title(), tr::onboarding::customize::domain::description()),
- (tr::onboarding::customize::preferences::title(), tr::onboarding::customize::preferences::description()),
-- ].into_iter().map(|(title, description)| {
-- self.paper_card().rounded(px(16.)).px(px(18.)).py(px(13.)).flex().flex_col().gap(px(4.))
-- .child(copy(title, 13., theme.gray_12).font_weight(FontWeight::MEDIUM))
-- .child(copy(description, 11., theme.gray_10).line_height(px(15.)))
-- })))
- .child(copy("Change any of these at any time in Settings", 12., theme.gray_9))
++ div()
++ .flex()
++ .flex_col()
++ .items_center()
++ .justify_center()
++ .min_h_full()
++ .px(px(48.))
++ .gap(px(24.))
++ .child(self.heading(
++ tr::onboarding::customize::title(),
++ tr::onboarding::customize::subtitle(),
++ ))
++ .child(
++ div()
++ .flex()
++ .flex_col()
++ .w_full()
++ .max_w(px(420.))
++ .gap(px(8.))
++ .children(
++ [
++ (
++ tr::onboarding::customize::shortcuts::title(),
++ tr::onboarding::customize::shortcuts::description(),
++ ),
++ (
++ tr::onboarding::customize::s3::title(),
++ tr::onboarding::customize::s3::description(),
++ ),
++ (
++ tr::onboarding::customize::domain::title(),
++ tr::onboarding::customize::domain::description(),
++ ),
++ (
++ tr::onboarding::customize::preferences::title(),
++ tr::onboarding::customize::preferences::description(),
++ ),
++ ]
++ .into_iter()
++ .map(|(title, description)| {
++ self.paper_card()
++ .rounded(px(16.))
++ .px(px(18.))
++ .py(px(13.))
++ .flex()
++ .flex_col()
++ .gap(px(4.))
++ .child(
++ copy(title, 13., theme.gray_12).font_weight(FontWeight::MEDIUM),
++ )
++ .child(copy(description, 11., theme.gray_10).line_height(px(15.)))
++ }),
++ ),
++ )
+ .child(copy(tr::onboarding::customize::footer(), 12., theme.gray_9))
.into_any_element()
}
@@@ -1619,13 -1621,13 +1709,17 @@@
)
.when(index == 0, |el| {
el.child(
- copy("View pricing plans", 13., theme.blue_10)
- copy(tr::onboarding::faq::pricing(), 13., theme.blue_10)
-- .id("onboarding-faq-pricing")
-- .cursor_pointer()
-- .mt(px(8.))
-- .on_click(|_, _, cx| {
-- cx.open_url(crate::auth::PRICING_URL)
-- }),
++ copy(
++ tr::onboarding::faq::pricing(),
++ 13.,
++ theme.blue_10,
++ )
++ .id("onboarding-faq-pricing")
++ .cursor_pointer()
++ .mt(px(8.))
++ .on_click(|_, _, cx| {
++ cx.open_url(crate::auth::PRICING_URL)
++ }),
)
}),
)
@@@ -1910,12 -1912,12 +2004,17 @@@ impl OnboardingWindow
.flex()
.flex_col()
.child(
- copy("Start Recording", 15., gpui::white())
- copy(tr::onboarding::demo::start_recording(), 15., gpui::white())
-- .font_weight(FontWeight::MEDIUM)
-- .whitespace_nowrap(),
++ copy(
++ tr::onboarding::demo::start_recording(),
++ 15.,
++ gpui::white(),
++ )
++ .font_weight(FontWeight::MEDIUM)
++ .whitespace_nowrap(),
)
.child(
- copy(MODES[index].title, 11., gpui::white()).opacity(0.9),
- copy((MODES[index].title)(), 11., gpui::white()).opacity(0.9),
++ copy((MODES[index].title)(), 11., gpui::white())
++ .opacity(0.9),
),
),
)
@@@ -2255,7 -2265,7 +2362,10 @@@
.border_color(theme.gray_3)
.bg(theme.body_fill(2)),
)
- .child(copy("BACKGROUND", 8., theme.gray_9).mt(px(4.)))
- .child(copy(tr::onboarding::demo::background(), 8., theme.gray_9).mt(px(4.)))
++ .child(
++ copy(tr::onboarding::demo::background(), 8., theme.gray_9)
++ .mt(px(4.)),
++ )
.child(div().flex().gap(px(4.)).children(
[0x667eea, 0xf78c88, 0xcccccc].map(|color| {
div()
@@@ -2547,7 -2557,7 +2657,11 @@@
12.,
self.success_palette().2,
))
- .child(copy("Copied to clipboard", 11., theme.gray_12)),
- .child(copy(tr::onboarding::demo::copied_to_clipboard(), 11., theme.gray_12)),
++ .child(copy(
++ tr::onboarding::demo::copied_to_clipboard(),
++ 11.,
++ theme.gray_12,
++ )),
),
)
}),
diff --cc apps/desktop-gpui/src/platform.rs
index 8b71158ae,70368f3bf..9fc78882f
--- a/apps/desktop-gpui/src/platform.rs
+++ b/apps/desktop-gpui/src/platform.rs
@@@ -2691,6 -2535,83 +2691,41 @@@ mod mac
}
}
- // -- The About panel ------------------------------------------------------
-
- /// `PredefinedMenuItem::about(.., AboutMetadata { name, version, .. })`,
- /// which on macOS is `orderFrontStandardAboutPanelWithOptions:`.
- ///
- /// The Tauri metadata also carries `copyright` and `publisher` from
- /// `tauri.conf.json` -- neither key exists in that file, so both are `None`
- /// there and there is nothing to pass here either.
- ///
- /// Spins no modal run loop of its own (the panel is an ordinary window), but
- /// ordering a window front re-enters gpui's window callbacks, so it keeps
- /// the [`place_overlay_panel`] rule: call it from a task, never inside an
- /// update.
- pub fn show_about_panel(name: &str, version: &str) {
- use objc2::{class, msg_send};
- use objc2_foundation::{NSArray, NSString};
-
- unsafe {
- let app: *mut AnyObject = msg_send![class!(NSApplication), sharedApplication];
- if app.is_null() {
- return;
- }
- // `dictionaryWithObjects:forKeys:` rather than a typed
- // `NSDictionary` constructor, for the reason
- // [`desktop_picture_path`] gives: the typed binding needs another
- // objc2-app-kit/foundation feature, and the rule here is that those
- // versions stay pinned to gpui's.
- let values =
- NSArray::from_vec(vec![NSString::from_str(name), NSString::from_str(version)]);
- let keys = NSArray::from_vec(vec![
- NSString::from_str("ApplicationName"),
- NSString::from_str("ApplicationVersion"),
- ]);
- let options: *mut AnyObject = msg_send![
- class!(NSDictionary),
- dictionaryWithObjects: &*values,
- forKeys: &*keys,
- ];
- let _: () = msg_send![app, orderFrontStandardAboutPanelWithOptions: options];
- }
- }
-
+ /// `NSApp.windowsMenu` and `NSApp.helpMenu`, looked up by the titles the
+ /// menu bar was just built with. `None` clears the Help menu.
+ pub fn register_system_menus(window_title: &str, help_title: Option<&str>) {
+ use objc2::{class, msg_send};
+ use objc2_foundation::NSString;
+
+ unsafe fn submenu(bar: *mut AnyObject, title: &str) -> *mut AnyObject {
+ unsafe {
+ let item: *mut AnyObject =
+ msg_send![bar, itemWithTitle: &*NSString::from_str(title)];
+ if item.is_null() {
+ return std::ptr::null_mut();
+ }
+ msg_send![item, submenu]
+ }
+ }
+
+ unsafe {
+ let app: *mut AnyObject = msg_send![class!(NSApplication), sharedApplication];
+ if app.is_null() {
+ return;
+ }
+ let bar: *mut AnyObject = msg_send![app, mainMenu];
+ if bar.is_null() {
+ return;
+ }
+ let windows = submenu(bar, window_title);
+ if !windows.is_null() {
+ let _: () = msg_send![app, setWindowsMenu: windows];
+ }
+ let help = help_title.map_or(std::ptr::null_mut(), |title| submenu(bar, title));
+ let _: () = msg_send![app, setHelpMenu: help];
+ }
+ }
+
/// One-line diagnostic of everything AppKit weighs into occlusion
/// visibility -- how the macOS 26 display-link failure was diagnosed; keep
/// it for the next platform mystery.
diff --cc apps/desktop-gpui/src/settings_window.rs
index a13f277e8,decabd793..d39d24b5a
--- a/apps/desktop-gpui/src/settings_window.rs
+++ b/apps/desktop-gpui/src/settings_window.rs
@@@ -1793,6 -1845,14 +1845,17 @@@ impl Render for SettingsWindow
.child(self.render_sidebar(cx))
.child(self.render_content(window, cx));
+ // GNOME and other compositors without server-side decorations leave
+ // the frame to the app; without this the window had no way to close.
+ #[cfg(target_os = "linux")]
+ let shell = shell.when(
- matches!(window.window_decorations(), gpui::Decorations::Client { .. }),
++ matches!(
++ window.window_decorations(),
++ gpui::Decorations::Client { .. }
++ ),
+ |shell| shell.child(linux_close_button(theme)),
+ );
+
shell
// Painted last so it lands over the page: the select menus, and
// the drag layer the zoom slider needs while the button is held.
diff --cc apps/desktop-gpui/src/tray.rs
index 11d09a445,aa2e3220c..e8f2f969f
--- a/apps/desktop-gpui/src/tray.rs
+++ b/apps/desktop-gpui/src/tray.rs
@@@ -376,16 -263,14 +377,16 @@@ pub fn scan_previous(load_thumbnails: b
fn previous_submenu(previous: &[PreviousItem]) -> Entry {
if previous.is_empty() {
return Entry::Submenu {
- title: "Previous".into(),
+ title: tr::tray::previous().into(),
enabled: false,
+ icon: menu_icon("previous"),
- items: vec![Entry::disabled("No recent items")],
+ items: vec![Entry::disabled(tr::tray::no_recent_items())],
};
}
Entry::Submenu {
- title: "Previous".into(),
+ title: tr::tray::previous().into(),
enabled: true,
+ icon: menu_icon("previous"),
items: previous
.iter()
.map(|item| Entry::Item {
@@@ -428,106 -305,72 +429,106 @@@ fn mode_submenu(mode: Mode) -> Entry
)
};
Entry::Submenu {
- title: "Recording Mode".into(),
+ title: tr::tray::select_mode().into(),
enabled: true,
+ icon: None,
items: vec![
- label(Mode::Studio, "Studio"),
- label(Mode::Instant, "Instant"),
- label(Mode::Screenshot, "Screenshot"),
+ label(Mode::Studio, tr::tray::mode::studio()),
+ label(Mode::Instant, tr::tray::mode::instant()),
+ label(Mode::Screenshot, tr::tray::mode::screenshot()),
],
}
}
/// `build_tray_menu`, minus the onboarding-minimal branch.
pub fn build_menu(mode: Mode, previous: &[PreviousItem], version: &str) -> Vec<Entry> {
- let mut entries = vec![Entry::item(tr::tray::open_main_window(), TrayItem::OpenCap)];
+ let mut entries = Vec::new();
+
- entries.push(Entry::item("Open Main Window", TrayItem::OpenCap));
++ entries.push(Entry::item(tr::tray::open_main_window(), TrayItem::OpenCap));
+ entries.push(Entry::Separator);
+ if cfg!(target_os = "macos") {
+ entries.push(Entry::ModePicker { mode });
+ entries.push(Entry::Separator);
+ } else {
+ entries.push(mode_submenu(mode));
+ entries.push(Entry::Separator);
+ }
if mode == Mode::Screenshot {
- entries.push(Entry::item(
+ entries.push(Entry::icon_item(
- "Screenshot Display",
+ tr::tray::screenshot_display(),
TrayItem::RecordDisplay,
+ "display",
));
- entries.push(Entry::item(
+ entries.push(Entry::icon_item(
- "Screenshot Window",
+ tr::tray::screenshot_window(),
TrayItem::RecordWindow,
+ "window",
));
- entries.push(Entry::item(
+ entries.push(Entry::icon_item(
- "Screenshot Area",
+ tr::tray::screenshot_area(),
TrayItem::RecordArea,
+ "area",
));
} else {
- entries.push(Entry::item(
+ entries.push(Entry::icon_item(
- "Record Display",
+ tr::tray::record_display(),
TrayItem::RecordDisplay,
+ "display",
));
- entries.push(Entry::item(
+ entries.push(Entry::icon_item(
- "Record Window",
+ tr::tray::record_window(),
TrayItem::RecordWindow,
+ "window",
+ ));
+ entries.push(Entry::icon_item(
- "Record Area",
++ tr::tray::record_area(),
+ TrayItem::RecordArea,
+ "area",
));
- entries.push(Entry::item(tr::tray::record_area(), TrayItem::RecordArea));
- entries.push(Entry::item(
+ entries.push(Entry::icon_item(
- "Take a Screenshot",
+ tr::tray::take_screenshot(),
TrayItem::TakeScreenshot,
+ "screenshot",
));
}
- entries.push(Entry::item(tr::tray::import_media(), TrayItem::ImportMedia));
-
entries.push(Entry::Separator);
- entries.push(mode_submenu(mode));
entries.push(previous_submenu(previous));
- entries.push(Entry::Separator);
-
entries.push(Entry::item(
- "View all recordings",
+ tr::tray::view_all_recordings(),
TrayItem::ViewAllRecordings,
));
entries.push(Entry::item(
- "View all screenshots",
+ tr::tray::view_all_screenshots(),
TrayItem::ViewAllScreenshots,
));
- entries.push(Entry::item(tr::tray::settings(), TrayItem::OpenSettings));
entries.push(Entry::Separator);
+ entries.push(Entry::icon_item(
- "Import Media…",
++ tr::tray::import_media(),
+ TrayItem::ImportMedia,
+ "import",
+ ));
+ entries.push(Entry::icon_item(
- "Settings…",
++ tr::tray::settings(),
+ TrayItem::OpenSettings,
+ "settings",
+ ));
// `logging::upload_log_file` needs the auth token and the HTTP client,
// neither of which this app has.
- entries.push(Entry::disabled("Upload Logs"));
+ entries.push(Entry::disabled(tr::tray::upload_logs()));
- entries.push(Entry::disabled(tr::tray::version(version)));
- entries.push(Entry::item(tr::tray::quit(), TrayItem::Quit));
+ entries.push(Entry::Separator);
+
+ if cfg!(target_os = "macos") {
- entries.push(Entry::item("Quit Cap", TrayItem::Quit));
++ entries.push(Entry::item(tr::tray::quit(), TrayItem::Quit));
+ entries.push(Entry::SectionHeader {
- title: format!("Cap v{version}"),
++ title: tr::tray::version(version),
+ });
+ } else {
- entries.push(Entry::disabled(format!("Cap v{version}")));
- entries.push(Entry::item("Quit Cap", TrayItem::Quit));
++ entries.push(Entry::disabled(tr::tray::version(version)));
++ entries.push(Entry::item(tr::tray::quit(), TrayItem::Quit));
+ }
entries
}
@@@ -1670,37 -1431,28 +1674,37 @@@ mod tests
#[test]
fn menu_matches_build_tray_menu() {
let menu = build_menu(Mode::Studio, &[], "0.1.0");
- assert_eq!(
- titles(&menu),
- vec![
- "Open Main Window",
- "Record Display",
- "Record Window",
- "Record Area",
- "Take a Screenshot",
- "Import Media...",
- "-",
- "Select Mode",
- "Previous",
- "-",
- "View all recordings",
- "View all screenshots",
- "Settings",
- "-",
- "Upload Logs",
- "Cap v0.1.0",
- "Quit Cap",
- ]
- );
+ // macOS renders the group as a section header naming the current
+ // mode; the `mode_submenu` other platforms get keeps its group label.
+ let mode_label = if cfg!(target_os = "macos") {
+ "Studio"
+ } else {
- "Recording Mode"
++ "Select Mode"
+ };
+ let mut expected = vec!["Open Main Window", "-", mode_label, "-"];
+ expected.extend([
+ "Record Display",
+ "Record Window",
+ "Record Area",
+ "Take a Screenshot",
+ "-",
+ "Previous",
+ "View all recordings",
+ "View all screenshots",
+ "-",
- "Import Media…",
- "Settings…",
++ "Import Media...",
++ "Settings",
+ "Upload Logs",
+ "-",
+ ]);
+ // The version row is a section header below Quit on macOS and a
+ // disabled row above it everywhere else.
+ if cfg!(target_os = "macos") {
+ expected.extend(["Quit Cap", "Cap v0.1.0"]);
+ } else {
+ expected.extend(["Cap v0.1.0", "Quit Cap"]);
+ }
+ assert_eq!(titles(&menu), expected);
}
/// Screenshot mode relabels the three target rows and drops "Take a
@@@ -1709,14 -1461,15 +1713,20 @@@
fn screenshot_mode_relabels_the_capture_rows() {
let menu = build_menu(Mode::Screenshot, &[], "0.1.0");
let titles = titles(&menu);
++ let mode_label = if cfg!(target_os = "macos") {
++ "Screenshot"
++ } else {
++ "Select Mode"
++ };
assert_eq!(
&titles[..6],
&[
"Open Main Window",
+ "-",
++ mode_label,
+ "-",
"Screenshot Display",
"Screenshot Window",
- "Screenshot Area",
- "Import Media...",
- "-",
]
);
assert!(!titles.iter().any(|title| title == "Take a Screenshot"));