Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: disable the update row while busy and stretch the picker

Ilya99138a455378
diff --git a/apps/desktop-gpui/src/menus.rs b/apps/desktop-gpui/src/menus.rs
index 00224a750..531cfeba9 100644
--- a/apps/desktop-gpui/src/menus.rs
+++ b/apps/desktop-gpui/src/menus.rs
@@ -82,7 +82,12 @@ impl UpdateRow {
};
Self {
title,
- enabled: !matches!(status, UpdateStatus::Checking),
+ enabled: !matches!(
+ status,
+ UpdateStatus::Checking
+ | UpdateStatus::Downloading { .. }
+ | UpdateStatus::Installing { .. }
+ ),
badge: update_menu_badge(status),
}
}
@@ -1274,10 +1279,10 @@ mod tests {
}
/// The row is the second item of the App menu (`menu_bar_...` pins that
- /// order); it greys out for the duration of a check so a second click
- /// cannot fire another one.
+ /// order); it greys out while a check or download is running so a second
+ /// click cannot fire another one.
#[test]
- fn the_update_row_greys_out_while_checking() {
+ fn the_update_row_greys_out_while_busy() {
fn row(status: &updates::UpdateStatus) -> (String, bool) {
let menus = build_menus(status);
match &menus[0].items[1] {
@@ -1294,6 +1299,19 @@ mod tests {
row(&updates::UpdateStatus::Checking),
("Checking for Update…".to_string(), true)
);
+ assert_eq!(
+ row(&updates::UpdateStatus::Downloading {
+ version: semver::Version::parse("0.4.0").unwrap(),
+ fraction: Some(0.42),
+ }),
+ ("Downloading update…".to_string(), true)
+ );
+ assert_eq!(
+ row(&updates::UpdateStatus::Installing {
+ version: semver::Version::parse("0.4.0").unwrap(),
+ }),
+ ("Downloading update…".to_string(), true)
+ );
}
/// The version lives only in the badge, and a percentage tick changes
@@ -1313,7 +1331,8 @@ mod tests {
let cold = UpdateRow::of(&downloading(None));
let warm = UpdateRow::of(&downloading(Some(0.42)));
assert_eq!(cold.title, "Downloading update…");
- assert!(cold.enabled);
+ assert!(!cold.enabled);
+ assert!(!warm.enabled);
assert_eq!(warm.title, cold.title);
let ready = UpdateRow::of(&UpdateStatus::Ready {
@@ -1331,6 +1350,7 @@ mod tests {
version: version.clone(),
});
assert_eq!(installing.title, cold.title);
+ assert!(!installing.enabled);
}
#[cfg(target_os = "macos")]
diff --git a/apps/desktop-gpui/src/tray.rs b/apps/desktop-gpui/src/tray.rs
index 49d0d5bc1..1c96a6203 100644
--- a/apps/desktop-gpui/src/tray.rs
+++ b/apps/desktop-gpui/src/tray.rs
@@ -989,8 +989,8 @@ mod mac {
use objc2_foundation::{MainThreadMarker, NSData, NSRunLoop, NSString, NSTimer};
use super::mac_mode_picker::{
- append_mode_picker, clear_hover, clear_hover_unless, hover_from_pointer, install_key_hook,
- stop_flash,
+ append_mode_picker, clear_hover, clear_hover_unless, fit_to_menu_width, hover_from_pointer,
+ install_key_hook, stop_flash,
};
use super::{
Accelerator, Entry, PREVIOUS_SYMBOL, PreviousItem, STOP_ICON, TrayItem,
@@ -1076,8 +1076,9 @@ mod mac {
}
#[unsafe(method(menuWillOpen:))]
- fn menu_will_open(&self, _menu: &NSMenu) {
+ fn menu_will_open(&self, menu: &NSMenu) {
MENU_OPEN.with(|o| o.set(true));
+ fit_to_menu_width(menu.size().width);
clear_hover();
hover_from_pointer();
start_option_tracking();
diff --git a/apps/desktop-gpui/src/tray/mac_mode_picker.rs b/apps/desktop-gpui/src/tray/mac_mode_picker.rs
index df1b187b4..50f64c44f 100644
--- a/apps/desktop-gpui/src/tray/mac_mode_picker.rs
+++ b/apps/desktop-gpui/src/tray/mac_mode_picker.rs
@@ -14,11 +14,11 @@ use objc2::runtime::{AnyClass, AnyObject, Bool, Sel};
use objc2::{AnyThread, DefinedClass, MainThreadOnly, define_class, msg_send, sel};
use objc2_app_kit::{
NSAccessibility, NSAccessibilityElement, NSAccessibilityRadioButtonRole,
- NSAccessibilityRadioGroupRole, NSAppearanceCustomization, NSBitmapImageRep, NSColor, NSEvent,
- NSEventTrackingRunLoopMode, NSEventType, NSFont, NSFontAttributeName, NSFontManager,
- NSFontTraitMask, NSFontWeightSemibold, NSForegroundColorAttributeName, NSImage, NSImageScaling,
- NSImageView, NSMenu, NSMenuItem, NSStringDrawing, NSTrackingArea, NSTrackingAreaOptions,
- NSView, NSWindow,
+ NSAccessibilityRadioGroupRole, NSAppearanceCustomization, NSAutoresizingMaskOptions,
+ NSBitmapImageRep, NSColor, NSEvent, NSEventTrackingRunLoopMode, NSEventType, NSFont,
+ NSFontAttributeName, NSFontManager, NSFontTraitMask, NSFontWeightSemibold,
+ NSForegroundColorAttributeName, NSImage, NSImageScaling, NSImageView, NSMenu, NSMenuItem,
+ NSStringDrawing, NSTrackingArea, NSTrackingAreaOptions, NSView, NSWindow,
};
use objc2_foundation::{
MainThreadMarker, NSArray, NSData, NSDictionary, NSPoint, NSRect, NSRunLoop, NSSize, NSString,
@@ -212,6 +212,7 @@ impl ModePickerView {
// Initialise first; everything below touches the live view.
let this: Retained<Self> = unsafe { msg_send![super(this), initWithFrame: frame] };
+ this.setAutoresizingMask(NSAutoresizingMaskOptions::ViewWidthSizable);
this.setWantsLayer(true);
let root = this.layer().expect("layer-backed view");
let make_layer = |radius: f64| -> Retained<CALayer> {
@@ -510,6 +511,14 @@ impl ModePickerView {
}
}
+ fn fit_to_width(&self, width: f64) {
+ let frame = self.frame();
+ if width > frame.size.width + 1.0 {
+ self.setFrameSize(NSSize::new(width, frame.size.height));
+ self.refresh();
+ }
+ }
+
fn clear_focus(&self) {
if self.ivars().focused.replace(None).is_some() {
self.refresh();
@@ -563,6 +572,14 @@ pub(super) fn clear_hover() {
});
}
+pub(super) fn fit_to_menu_width(width: f64) {
+ PICKER.with(|p| {
+ if let Some((_, view)) = p.borrow().as_ref() {
+ view.fit_to_width(width);
+ }
+ });
+}
+
pub(super) fn hover_from_pointer() {
PICKER.with(|p| {
if let Some((_, view)) = p.borrow().as_ref() {