Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(desktop-gpui): restore the About Cap action

Ilyab316721ecc7a
diff --git a/apps/desktop-gpui/src/menus.rs b/apps/desktop-gpui/src/menus.rs
index a967ac073..bd0f31be7 100644
--- a/apps/desktop-gpui/src/menus.rs
+++ b/apps/desktop-gpui/src/menus.rs
@@ -173,6 +173,10 @@ pub fn init(cx: &mut App) {
// `on_key_down` project-undo). A global binding here would shadow both.
cx.bind_keys(bindings());
+ cx.on_action(|_: &About, cx: &mut App| {
+ cx.spawn(async move |_| platform::show_about_panel(APP_NAME, app_version()))
+ .detach();
+ });
cx.on_action(|_: &CheckForUpdate, cx: &mut App| {
updates::check_manually(cx);
});
diff --git a/apps/desktop-gpui/src/platform.rs b/apps/desktop-gpui/src/platform.rs
index b85c5d51b..65e7a0608 100644
--- a/apps/desktop-gpui/src/platform.rs
+++ b/apps/desktop-gpui/src/platform.rs
@@ -708,6 +708,35 @@ mod mac {
const FILE_MENU: isize = 1;
const OPEN_RECENT_ROW: isize = 1;
+ /// `PredefinedMenuItem::about`, which on macOS is `orderFrontStandardAboutPanelWithOptions:`.
+ /// Ordering a window front re-enters gpui's window callbacks, so call it
+ /// from a task, never from 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;
+ }
+ let values = NSArray::from_retained_slice(&[
+ NSString::from_str(name),
+ NSString::from_str(version),
+ ]);
+ let keys = NSArray::from_retained_slice(&[
+ 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];
+ }
+ }
+
pub fn patch_standard_application_menu() {
use objc2::{exception, msg_send, runtime::AnyObject, sel};
@@ -3040,6 +3069,7 @@ mod stub {
pub fn close_native(_native: &NativeWindow) {}
pub fn set_dock_icon(_png: &[u8]) {}
+ pub fn show_about_panel(_name: &str, _version: &str) {}
pub fn escape_hotkey_events() -> flume::Receiver<()> {
// A channel whose sender is dropped immediately: the drain task's
// `recv` errors once and the task exits.
diff --git a/apps/desktop-gpui/src/platform/windows.rs b/apps/desktop-gpui/src/platform/windows.rs
index 8a25c01de..a0468465b 100644
--- a/apps/desktop-gpui/src/platform/windows.rs
+++ b/apps/desktop-gpui/src/platform/windows.rs
@@ -699,6 +699,8 @@ pub fn activation_policy() -> isize {
-1
}
+pub fn show_about_panel(_name: &str, _version: &str) {}
+
pub fn escape_hotkey_events() -> flume::Receiver<()> {
flume::unbounded().1
}