Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: commit mode on pointer-down and add update harness

Ilyaed8c455d6311
diff --git a/apps/desktop-gpui/src/tray.rs b/apps/desktop-gpui/src/tray.rs
index 3e16092a9..930ea3343 100644
--- a/apps/desktop-gpui/src/tray.rs
+++ b/apps/desktop-gpui/src/tray.rs
@@ -1562,6 +1562,16 @@ mod mac {
menu_item.setKeyEquivalent(&NSString::from_str(","));
menu_item.setKeyEquivalentModifierMask(NSEventModifierFlags::Command);
}
+ if *item == Some(TrayItem::Quit) {
+ // Lowercase: an uppercase equivalent implies Shift, which
+ // rendered this as ⇧⌘Q.
+ menu_item.setKeyEquivalent(&NSString::from_str("q"));
+ menu_item.setKeyEquivalentModifierMask(NSEventModifierFlags::Command);
+ }
+ if *item == Some(TrayItem::Quit) {
+ menu_item.setKeyEquivalent(&NSString::from_str("Q"));
+ menu_item.setKeyEquivalentModifierMask(NSEventModifierFlags::Command);
+ }
// Previous's rows are photo thumbnails; every other iconed row
// is an SF Symbol, template-tinted by the menu. Windows draws
// `icon`'s raster instead.
diff --git a/apps/desktop-gpui/src/tray/mac_mode_picker.rs b/apps/desktop-gpui/src/tray/mac_mode_picker.rs
index dbf7eb35f..dcc6d3d55 100644
--- a/apps/desktop-gpui/src/tray/mac_mode_picker.rs
+++ b/apps/desktop-gpui/src/tray/mac_mode_picker.rs
@@ -99,7 +99,6 @@ impl PillAccessibilityElement {
struct PickerIvars {
selected: Cell<usize>,
focused: Cell<Option<usize>>,
- pressed: Cell<Option<usize>>,
flash: Cell<bool>,
/// `actions` index of the first pill; pill `i` posts `tag_base + i`.
tag_base: isize,
@@ -112,7 +111,7 @@ struct PickerIvars {
impl Drop for PickerIvars {
fn drop(&mut self) {
- tracing::debug!("mode picker view deallocated");
+ tracing::info!("mode picker view deallocated");
}
}
@@ -178,22 +177,10 @@ define_class!(
#[unsafe(method(mouseDown:))]
fn mouse_down(&self, event: &NSEvent) {
- let pressed = self.pill_at(event);
- self.ivars().pressed.set(pressed);
- if let Some(i) = pressed {
- // Update the subtitle immediately so the old name never flashes.
- self.ivars().focused.set(Some(i));
- self.ivars().selected.set(i);
- self.refresh();
- }
- }
-
- #[unsafe(method(mouseUp:))]
- fn mouse_up(&self, _event: &NSEvent) {
- // Commit the pill that was pressed, even if the pointer left the
- // capsule before release, so the shown subtitle and the applied
- // mode cannot drift apart.
- if let Some(i) = self.ivars().pressed.take() {
+ // Commit and update the visuals in the same event: a release
+ // outside the menu never reaches this view, which used to leave
+ // the subtitle showing a mode that was never applied.
+ if let Some(i) = self.pill_at(event) {
self.choose(i);
}
}
@@ -211,7 +198,6 @@ impl ModePickerView {
let this = mtm.alloc::<Self>().set_ivars(PickerIvars {
selected: Cell::new(selected),
focused: Cell::new(None),
- pressed: Cell::new(None),
flash: Cell::new(false),
tag_base,
capsule: RefCell::new(None),
diff --git a/apps/desktop-gpui/src/updates.rs b/apps/desktop-gpui/src/updates.rs
index c866bae6e..f4834e189 100644
--- a/apps/desktop-gpui/src/updates.rs
+++ b/apps/desktop-gpui/src/updates.rs
@@ -263,6 +263,42 @@ fn busy_alert(cx: &mut App) {
.detach();
}
+/// `CAP_GPUI_AUTO_UPDATE=<state>`: skip the network check and put the menu
+/// into a fixed update state for verification.
+///
+/// States: `checking`, `downloading:<version>[:<fraction>]`, `ready:<version>`,
+/// `installing:<version>`, `installed:<version>`.
+fn harness_status() -> Option<UpdateStatus> {
+ let value = std::env::var("CAP_GPUI_AUTO_UPDATE").ok()?;
+ let mut parts = value.split(':');
+ let state = parts.next()?;
+ let version = |parts: &mut std::str::Split<'_, char>| {
+ parts.next().and_then(|value| Version::parse(value).ok())
+ };
+ match state {
+ "checking" => Some(UpdateStatus::Checking),
+ "downloading" => {
+ let version = version(&mut parts)?;
+ let fraction = parts.next().and_then(|value| value.parse::<f32>().ok());
+ Some(UpdateStatus::Downloading { version, fraction })
+ }
+ "ready" => Some(UpdateStatus::Ready {
+ version: version(&mut parts)?,
+ }),
+ "installing" => Some(UpdateStatus::Installing {
+ version: version(&mut parts)?,
+ }),
+ "installed" => Some(UpdateStatus::Installed {
+ version: version(&mut parts)?,
+ executable: PathBuf::from("/Applications/Cap.app"),
+ }),
+ _ => {
+ tracing::warn!(value, "CAP_GPUI_AUTO_UPDATE: unknown state");
+ None
+ }
+ }
+}
+
pub(crate) fn schedule_startup_check(cx: &mut App) {
let (wake, requests) = flume::bounded(1);
cx.set_global(UpdateScheduler {
@@ -275,6 +311,11 @@ pub(crate) fn schedule_startup_check(cx: &mut App) {
download_epoch: 0,
});
+ if let Some(status) = harness_status() {
+ set_status(status, cx);
+ return;
+ }
+
cx.spawn(async move |cx| {
let mut channel = cx
.background_executor()