Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

feat(gui): float the update notice as a capsule

RoversXeedb92e2f523
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftl
index f56982e2..5de42c44 100644
--- a/thinkterm-i18n/i18n/de-DE.ftl
+++ b/thinkterm-i18n/i18n/de-DE.ftl
@@ -937,6 +937,13 @@ settings-sidebar-snippets-description = Gespeicherte Befehle und Texte, die Sie
# Update-Hinweis (Mitteilung) und der Installationsablauf der Seite „Software-Update“.
update-toast-title = ThinkTerm-Update verfügbar
update-toast-body = Klicken, um die Neuerungen zu sehen
+update-capsule-available = Update verfügbar
+update-capsule-downloading = Wird geladen
+update-capsule-installing = Wird installiert
+update-capsule-restart = Neu starten zum Aktualisieren
+update-capsule-installed = Update installiert
+update-capsule-failed = Update fehlgeschlagen
+update-capsule-retry = Erneut versuchen
settings-update-install = Update installieren
settings-update-preparing = Installation von ThinkTerm { $version } wird vorbereitet…
settings-update-installing = Dieses Fenster funktioniert währenddessen weiter.
diff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftl
index f328283c..513e65e6 100644
--- a/thinkterm-i18n/i18n/en-US.ftl
+++ b/thinkterm-i18n/i18n/en-US.ftl
@@ -937,6 +937,13 @@ settings-sidebar-snippets-description = Saved commands and text you can paste in
# Update notice (toast) and the Software Update page's install flow.
update-toast-title = ThinkTerm update available
update-toast-body = Click to see what's new
+update-capsule-available = Update available
+update-capsule-downloading = Downloading
+update-capsule-installing = Installing
+update-capsule-restart = Restart to update
+update-capsule-installed = Update installed
+update-capsule-failed = Update failed
+update-capsule-retry = Retry
settings-update-install = Install Update
settings-update-preparing = Preparing to install ThinkTerm { $version }…
settings-update-installing = This window keeps working meanwhile.
diff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftl
index c3ca7100..9bb8be96 100644
--- a/thinkterm-i18n/i18n/fr-FR.ftl
+++ b/thinkterm-i18n/i18n/fr-FR.ftl
@@ -931,6 +931,13 @@ settings-sidebar-snippets-description = Commandes et textes enregistrés, à col
# Notification de mise à jour et installation depuis la page Mise à jour logicielle.
update-toast-title = Mise à jour de ThinkTerm disponible
update-toast-body = Cliquez pour voir les nouveautés
+update-capsule-available = Mise à jour disponible
+update-capsule-downloading = Téléchargement
+update-capsule-installing = Installation
+update-capsule-restart = Redémarrer pour mettre à jour
+update-capsule-installed = Mise à jour installée
+update-capsule-failed = Échec de la mise à jour
+update-capsule-retry = Réessayer
settings-update-install = Installer la mise à jour
settings-update-preparing = Préparation de l'installation de ThinkTerm { $version }…
settings-update-installing = Cette fenêtre reste utilisable pendant ce temps.
diff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftl
index 044625fb..8fb24a09 100644
--- a/thinkterm-i18n/i18n/ja-JP.ftl
+++ b/thinkterm-i18n/i18n/ja-JP.ftl
@@ -907,6 +907,13 @@ settings-sidebar-snippets-description = 保存したコマンドやテキスト
# 更新通知(トースト)と「ソフトウェアアップデート」ページのインストール処理。
update-toast-title = ThinkTerm の新しいバージョンがあります
update-toast-body = クリックして更新内容を表示
+update-capsule-available = アップデートがあります
+update-capsule-downloading = ダウンロード中
+update-capsule-installing = インストール中
+update-capsule-restart = 再起動してアップデート
+update-capsule-installed = アップデート済み
+update-capsule-failed = アップデートに失敗
+update-capsule-retry = 再試行
settings-update-install = アップデートをインストール
settings-update-preparing = ThinkTerm { $version } のインストールを準備中…
settings-update-installing = その間もこのウィンドウは使えます。
diff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftl
index d32622b9..99372973 100644
--- a/thinkterm-i18n/i18n/zh-CN.ftl
+++ b/thinkterm-i18n/i18n/zh-CN.ftl
@@ -907,6 +907,13 @@ settings-sidebar-snippets-description = 保存的命令和文本,可以粘贴
# 更新提醒(系统通知)与"软件更新"页的安装流程。
update-toast-title = ThinkTerm 有新版本
update-toast-body = 点击查看更新内容
+update-capsule-available = 有新版本
+update-capsule-downloading = 正在下载
+update-capsule-installing = 正在安装
+update-capsule-restart = 重启以完成更新
+update-capsule-installed = 更新已安装
+update-capsule-failed = 更新失败
+update-capsule-retry = 重试
settings-update-install = 安装更新
settings-update-preparing = 正在准备安装 ThinkTerm { $version }…
settings-update-installing = 期间本窗口可以继续使用。
diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rs
index 74920146..e584ef87 100644
--- a/wezterm-gui/src/settings_window.rs
+++ b/wezterm-gui/src/settings_window.rs
@@ -447,6 +447,219 @@ fn repaint_open_settings(refresh: bool) {
}
}
+/// Start installing `release`, unless an install already runs. Its progress
+/// and outcome land in `UPDATE_INSTALL`, for the Update page and the update
+/// capsule of every window alike.
+fn start_update_install_with(
+ release: crate::update::Release,
+ method: thinkterm_update::InstallMethod,
+) {
+ if matches!(update_install(), Some(UpdateInstall::Running { .. })) {
+ return;
+ }
+ let version = release.tag_name.trim_start_matches('v').to_string();
+ set_update_install(Some(UpdateInstall::Running {
+ version: version.clone(),
+ progress: None,
+ download_started: None,
+ }));
+ if matches!(update_check(), Some(UpdateCheck::Failed { .. })) {
+ set_update_check(None);
+ }
+ repaint_open_settings(false);
+ crate::frontend::front_end().invalidate_all_windows();
+
+ // The installer downloads and replaces files: off the UI thread, with
+ // its progress and outcome posted back to whichever Settings window is
+ // open by then and to the windows' update capsules.
+ let spawned = std::thread::Builder::new()
+ .name("thinkterm-update-install".into())
+ .spawn(move || {
+ // A cache written by a build that did not keep
+ // GitHub's checksums lacks them: ask for the release
+ // again then, and settle for the cache if that fails.
+ let release = if release.assets.iter().any(|a| a.sha256().is_none()) {
+ thinkterm_update::get_release_by_tag(&release.tag_name)
+ .unwrap_or(release)
+ } else {
+ release
+ };
+ let mut progress = |progress| {
+ promise::spawn::spawn_into_main_thread(async move {
+ // Never over the outcome, should a report
+ // land after it.
+ let reported = UPDATE_INSTALL.with(|install| {
+ let mut install = install.borrow_mut();
+ let Some(UpdateInstall::Running {
+ progress: current,
+ download_started,
+ ..
+ }) = &mut *install
+ else {
+ return None;
+ };
+ let shown = capsule_percent(current);
+ use thinkterm_update::InstallProgress;
+ if let InstallProgress::Downloading { done, .. } = progress {
+ // A retry, or a redirect's body thrown
+ // away, starts the count over, and the
+ // rate is timed from there.
+ let restarted = matches!(
+ current,
+ Some(InstallProgress::Downloading { done: before, .. })
+ if done < *before
+ );
+ if download_started.is_none() || restarted {
+ *download_started = Some(Instant::now());
+ }
+ }
+ *current = Some(progress);
+ Some(capsule_percent(current) != shown)
+ });
+ if let Some(moved) = reported {
+ repaint_open_settings(false);
+ // The windows show only the whole percentage, and
+ // nothing of it once the capsule has gone into the
+ // gear.
+ if moved && !crate::termwindow::render::update_capsule::dismissed() {
+ crate::frontend::front_end().invalidate_all_windows();
+ }
+ }
+ })
+ .detach();
+ };
+ let result = if cfg!(windows) {
+ thinkterm_update::run_windows_installer(&release, &mut progress)
+ } else {
+ match method.manifest_for_install() {
+ Some(manifest) => thinkterm_update::run_local_installer_captured(
+ &manifest,
+ &release,
+ &mut progress,
+ )
+ .map(|_| ()),
+ None => Err(anyhow::anyhow!("{}", method.how_to_update())),
+ }
+ };
+ let outcome = match result {
+ Ok(()) => UpdateInstall::Installed { version },
+ Err(err) => UpdateInstall::Failed {
+ error: format!("{err:#}"),
+ },
+ };
+ promise::spawn::spawn_into_main_thread(async move {
+ set_update_install(Some(outcome));
+ repaint_open_settings(true);
+ crate::frontend::front_end().invalidate_all_windows();
+ })
+ .detach();
+ });
+ if let Err(err) = spawned {
+ set_update_install(Some(UpdateInstall::Failed {
+ error: err.to_string(),
+ }));
+ }
+}
+
+/// What the update capsule shows of an install's progress: the whole
+/// percentage while it downloads, none once the installer runs.
+fn capsule_percent(progress: &Option<thinkterm_update::InstallProgress>) -> Option<u64> {
+ match progress {
+ Some(thinkterm_update::InstallProgress::Downloading { done, total }) if *total > 0 => {
+ Some(done.saturating_mul(100) / total)
+ }
+ _ => None,
+ }
+}
+
+/// Install the newest release found, from outside Settings: the update
+/// capsule's click. False when there is none to install.
+pub(crate) fn start_update_install() -> bool {
+ let Some(release) =
+ crate::update::available_release().or_else(|| crate::update::cached_update_status().latest)
+ else {
+ return false;
+ };
+ start_update_install_with(release, thinkterm_update::InstallMethod::detect());
+ true
+}
+
+/// Whether this copy can replace itself, as opposed to one a package
+/// manager owns, whose update the Update page explains instead.
+pub(crate) fn installs_updates_itself() -> bool {
+ cfg!(windows) || thinkterm_update::InstallMethod::detect().self_updatable()
+}
+
+/// Where an update stands, as the update capsule shows it.
+#[derive(Debug, Clone, PartialEq)]
+pub(crate) enum UpdateCapsuleStatus {
+ Available { version: String },
+ /// `fraction` is None before the first report and once the download is
+ /// in and the installer runs.
+ Installing { fraction: Option<f32> },
+ /// `restart`: whether restarting now keeps every terminal; where it
+ /// would not, the Update page says what to do instead.
+ Installed { restart: bool },
+ Failed,
+}
+
+pub(crate) fn update_capsule_status() -> Option<UpdateCapsuleStatus> {
+ use thinkterm_update::InstallProgress;
+ Some(match update_install() {
+ Some(UpdateInstall::Running { progress, .. }) => UpdateCapsuleStatus::Installing {
+ fraction: match progress {
+ Some(InstallProgress::Downloading { done, total }) if total > 0 => {
+ Some((done as f32 / total as f32).clamp(0.0, 1.0))
+ }
+ _ => None,
+ },
+ },
+ Some(UpdateInstall::Installed { .. }) => UpdateCapsuleStatus::Installed {
+ restart: !cfg!(windows) && !restart_ends_terminals_lately(),
+ },
+ Some(UpdateInstall::Failed { .. }) => UpdateCapsuleStatus::Failed,
+ None => UpdateCapsuleStatus::Available {
+ version: crate::update::available_version()?,
+ },
+ })
+}
+
+/// `restart_ends_terminals`, asked again at most once a second: the update
+/// capsule asks on every paint of every window, and the answer only moves
+/// as panes come and go.
+fn restart_ends_terminals_lately() -> bool {
+ thread_local! {
+ static LAST: Cell<Option<(Instant, bool)>> = const { Cell::new(None) };
+ }
+ LAST.with(|last| match last.get() {
+ Some((at, ends)) if at.elapsed() < Duration::from_secs(1) => ends,
+ _ => {
+ let ends = restart_ends_terminals();
+ last.set(Some((Instant::now(), ends)));
+ ends
+ }
+ })
+}
+
+/// Restart into the installed update, from the update capsule. False when
+/// it did not: an install still runs, or restarting now would end
+/// terminals after all.
+pub(crate) fn restart_into_update() -> bool {
+ if !matches!(update_install(), Some(UpdateInstall::Installed { .. }))
+ || cfg!(windows)
+ || restart_ends_terminals()
+ {
+ return false;
+ }
+ match SettingsWindow::restart_application() {
+ Ok(()) => true,
+ Err(err) => {
+ log::error!("restarting into the update: {err:#}");
+ false
+ }
+ }
+}
+
fn settings_window_for_instance(instance_id: u64) -> Option<Rc<RefCell<SettingsWindow>>> {
open_settings_window_with_id()
.filter(|(current_id, _)| *current_id == instance_id)
@@ -6525,9 +6738,6 @@ impl SettingsWindow {
}
SettingsAction::InstallUpdate => {
self.ui.open_dropdown = None;
- if matches!(update_install(), Some(UpdateInstall::Running { .. })) {
- return;
- }
let Some(release) = self
.ui
.update_status
@@ -6541,99 +6751,8 @@ impl SettingsWindow {
.update_method
.clone()
.unwrap_or_else(thinkterm_update::InstallMethod::detect);
- let version = release.tag_name.trim_start_matches('v').to_string();
- set_update_install(Some(UpdateInstall::Running {
- version: version.clone(),
- progress: None,
- download_started: None,
- }));
- if matches!(update_check(), Some(UpdateCheck::Failed { .. })) {
- set_update_check(None);
- }
+ start_update_install_with(release, method);
window.invalidate();
-
- // The installer downloads and replaces files: off the UI
- // thread, with its progress and outcome posted back to
- // whichever Settings window is open by then.
- let spawned = std::thread::Builder::new()
- .name("thinkterm-update-install".into())
- .spawn(move || {
- // A cache written by a build that did not keep
- // GitHub's checksums lacks them: ask for the release
- // again then, and settle for the cache if that fails.
- let release = if release.assets.iter().any(|a| a.sha256().is_none()) {
- thinkterm_update::get_release_by_tag(&release.tag_name)
- .unwrap_or(release)
- } else {
- release
- };
- let mut progress = |progress| {
- promise::spawn::spawn_into_main_thread(async move {
- // Never over the outcome, should a report
- // land after it.
- let reported = UPDATE_INSTALL.with(|install| {
- let mut install = install.borrow_mut();
- let Some(UpdateInstall::Running {
- progress: current,
- download_started,
- ..
- }) = &mut *install
- else {
- return false;
- };
- use thinkterm_update::InstallProgress;
- if let InstallProgress::Downloading { done, .. } = progress {
- // A retry, or a redirect's body thrown
- // away, starts the count over, and the
- // rate is timed from there.
- let restarted = matches!(
- current,
- Some(InstallProgress::Downloading { done: before, .. })
- if done < *before
- );
- if download_started.is_none() || restarted {
- *download_started = Some(Instant::now());
- }
- }
- *current = Some(progress);
- true
- });
- if reported {
- repaint_open_settings(false);
- }
- })
- .detach();
- };
- let result = if cfg!(windows) {
- thinkterm_update::run_windows_installer(&release, &mut progress)
- } else {
- match method.manifest_for_install() {
- Some(manifest) => thinkterm_update::run_local_installer_captured(
- &manifest,
- &release,
- &mut progress,
- )
- .map(|_| ()),
- None => Err(anyhow::anyhow!("{}", method.how_to_update())),
- }
- };
- let outcome = match result {
- Ok(()) => UpdateInstall::Installed { version },
- Err(err) => UpdateInstall::Failed {
- error: format!("{err:#}"),
- },
- };
- promise::spawn::spawn_into_main_thread(async move {
- set_update_install(Some(outcome));
- repaint_open_settings(true);
- })
- .detach();
- });
- if let Err(err) = spawned {
- set_update_install(Some(UpdateInstall::Failed {
- error: err.to_string(),
- }));
- }
}
SettingsAction::OpenLatestRelease => {
self.ui.open_dropdown = None;
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index 1d4ac472..2d47ad29 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -808,6 +808,8 @@ pub enum UIItemType {
WorkspaceSidebarSshHosts,
WorkspaceSidebarLiveOverview,
WorkspaceSidebarNotifications,
+ UpdateCapsule,
+ UpdateCapsuleDismiss,
RightSidebarToggle,
RightSidebarMode(RightSidebarMode),
RightSidebarBackground,
@@ -3047,6 +3049,7 @@ pub struct TermWindow {
ui_items: Vec<UIItem>,
context_menu: Option<ui::context_menu::ContextMenuState>,
+ pub(crate) update_capsule: render::update_capsule::UpdateCapsule,
/// Lights running round copied or pasted text, and a paste waiting to
/// show up for one (see `render::edge_light`).
edge_lights: Vec<render::edge_light::EdgeLight>,
@@ -4091,6 +4094,7 @@ impl TermWindow {
// usual way, and a light left frozen on screen would stay.
|| !self.edge_lights.is_empty()
|| self.pending_paste.is_some()
+ || self.update_capsule.owes_frames()
}
/// An overlay scrollbar that is still up has a fade to finish; the
@@ -4803,6 +4807,7 @@ impl TermWindow {
semantic_zones: HashMap::new(),
ui_items: vec![],
context_menu: None,
+ update_capsule: Default::default(),
edge_lights: vec![],
pending_paste: None,
right_press_claimed: false,
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index df0f0086..8ae38f4e 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -48,6 +48,16 @@ use wezterm_term::{ClickPosition, LastMouseClick, StableRowIndex};
const TAB_WHEEL_SURFACE_LOCK_MS: u64 = 700;
const TAB_WHEEL_DIRECTION_LOCK_MS: u64 = 140;
+/// The update capsule floats over the terminal's corner: a wheel turned over
+/// it scrolls the terminal underneath.
+fn update_capsule_wheel_passthrough(event: &MouseEvent, item: &UIItem) -> bool {
+ matches!(event.kind, WMEK::VertWheel(_) | WMEK::HorzWheel(_))
+ && matches!(
+ item.item_type,
+ UIItemType::UpdateCapsule | UIItemType::UpdateCapsuleDismiss
+ )
+}
+
/// Consume the physical release without completing the action it would have
/// performed. True asks the caller to cancel (not commit) divider preview RPCs.
fn discard_blocked_pointer_release(
@@ -1633,6 +1643,8 @@ impl super::TermWindow {
| UIItemType::WorkspaceSidebarBackground
| UIItemType::WorkspaceSidebarResize
| UIItemType::WorkspaceSidebarSettings
+ | UIItemType::UpdateCapsule
+ | UIItemType::UpdateCapsuleDismiss
| UIItemType::WorkspaceSidebarThreadSearch
| UIItemType::WorkspaceSidebarViewOptions
| UIItemType::WorkspaceSidebarSshHosts
@@ -1805,6 +1817,8 @@ impl super::TermWindow {
| UIItemType::WorkspaceSidebarBackground
| UIItemType::WorkspaceSidebarResize
| UIItemType::WorkspaceSidebarSettings
+ | UIItemType::UpdateCapsule
+ | UIItemType::UpdateCapsuleDismiss
| UIItemType::WorkspaceSidebarThreadSearch
| UIItemType::WorkspaceSidebarViewOptions
| UIItemType::WorkspaceSidebarSshHosts
@@ -2452,7 +2466,10 @@ impl super::TermWindow {
let ui_item = if matches!(self.current_mouse_capture, None | Some(MouseCapture::UI)) {
let ui_item = self
.resolve_ui_item(&event)
- .filter(|item| !self.vertical_wheel_tab_surface_passthrough(&event, item));
+ .filter(|item| {
+ !self.vertical_wheel_tab_surface_passthrough(&event, item)
+ && !update_capsule_wheel_passthrough(&event, item)
+ });
match (self.last_ui_item.take(), &ui_item) {
(Some(prior), Some(item)) => {
@@ -4054,6 +4071,10 @@ impl super::TermWindow {
| UIItemType::RightSidebarRemoteTransfer(_) => {
self.mouse_event_right_sidebar_remote_file(item.clone(), event, context);
}
+ UIItemType::UpdateCapsule => self.mouse_event_update_capsule(false, event, context),
+ UIItemType::UpdateCapsuleDismiss => {
+ self.mouse_event_update_capsule(true, event, context)
+ }
UIItemType::WorkspaceSidebarSettings => {
self.mouse_event_workspace_sidebar_settings(event, context);
}
@@ -4510,6 +4531,10 @@ impl super::TermWindow {
UIItemType::WorkspaceSidebarResize => {
self.mouse_event_workspace_sidebar_resize(item, event, context);
}
+ UIItemType::UpdateCapsule => self.mouse_event_update_capsule(false, event, context),
+ UIItemType::UpdateCapsuleDismiss => {
+ self.mouse_event_update_capsule(true, event, context)
+ }
UIItemType::WorkspaceSidebarSettings => {
self.mouse_event_workspace_sidebar_settings(event, context);
}
@@ -5555,6 +5580,27 @@ impl super::TermWindow {
self.invalidate_or_reflow_right_sidebar(previous_width, context);
}
+ fn mouse_event_update_capsule(
+ &mut self,
+ dismiss: bool,
+ event: MouseEvent,
+ context: &dyn WindowOps,
+ ) {
+ let clickable = dismiss || self.update_capsule_clickable();
+ context.set_cursor(Some(if clickable {
+ MouseCursor::Hand
+ } else {
+ MouseCursor::Arrow
+ }));
+ if event.kind == WMEK::Press(MousePress::Left) {
+ if dismiss {
+ self.dismiss_update_capsule();
+ } else {
+ self.activate_update_capsule();
+ }
+ }
+ }
+
pub fn mouse_event_workspace_sidebar_settings(
&mut self,
event: MouseEvent,
@@ -5562,7 +5608,16 @@ impl super::TermWindow {
) {
context.set_cursor(Some(MouseCursor::Hand));
if event.kind == WMEK::Press(MousePress::Left) {
- crate::settings_window::show_from(self.mux_window_id, &self.active_space_id);
+ // The gear carries the dismissed update capsule's dot: the click
+ // goes where the capsule would have led.
+ if crate::termwindow::render::update_capsule::gear_dot().is_some() {
+ crate::settings_window::show_update_page_from(
+ self.mux_window_id,
+ &self.active_space_id,
+ );
+ } else {
+ crate::settings_window::show_from(self.mux_window_id, &self.active_space_id);
+ }
}
}
diff --git a/wezterm-gui/src/termwindow/render/mod.rs b/wezterm-gui/src/termwindow/render/mod.rs
index 1b727bc9..cdd841ea 100644
--- a/wezterm-gui/src/termwindow/render/mod.rs
+++ b/wezterm-gui/src/termwindow/render/mod.rs
@@ -53,6 +53,7 @@ pub mod screen_line;
pub mod selection_shape;
pub mod split;
pub mod tab_bar;
+pub mod update_capsule;
pub mod window_buttons;
/// The data that we associate with a line; we use this to cache it shape hash
diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rs
index 88c59641..85db3930 100644
--- a/wezterm-gui/src/termwindow/render/paint.rs
+++ b/wezterm-gui/src/termwindow/render/paint.rs
@@ -4637,6 +4637,8 @@ impl crate::TermWindow {
self.paint_window_borders(&mut layers)
.context("paint_window_borders")?;
drop(layers);
+ self.paint_update_capsule()
+ .context("paint_update_capsule")?;
self.paint_modal().context("paint_modal")?;
self.paint_context_menu().context("paint_context_menu")?;
diff --git a/wezterm-gui/src/termwindow/render/update_capsule.rs b/wezterm-gui/src/termwindow/render/update_capsule.rs
new file mode 100644
index 00000000..9fae934f
--- /dev/null
+++ b/wezterm-gui/src/termwindow/render/update_capsule.rs
@@ -0,0 +1,974 @@
+//! The update capsule: a pill floating in the window's bottom-right corner
+//! while a newer release is known, which then follows the install through
+//! to the restart. Dismissed, it flies into the dot on the settings gear.
+
+use crate::settings_window::UpdateCapsuleStatus;
+use crate::termwindow::render::RenderMetrics;
+use crate::termwindow::ui::icons::SvgIcon;
+use crate::termwindow::{UIItem, UIItemType};
+use crate::ui::anim::{Easing, Timeline};
+use crate::ui::draw::DrawContext;
+use anyhow::Context;
+use std::cell::Cell;
+use std::time::{Duration, Instant};
+use window::color::LinearRgba;
+use window::WindowOps;
+
+/// Above the terminal and the chrome, under the content views' transition
+/// layers: a view arriving, or the terminal flying into its card, passes
+/// over it. A z-index of its own, because the quad layers within one are a
+/// single order for the whole window: sharing one with another surface
+/// would draw each one's text through the other's background.
+const ZINDEX: i8 = 7;
+
+/// The sizes below are in points: two of the chrome's design pixels,
+/// which are a Retina display's pixels.
+const POINT: f32 = 2.0;
+const HEIGHT: f32 = 32.0;
+const ICON: f32 = 20.0;
+const PAD_LEFT: f32 = 6.0;
+const PAD_RIGHT: f32 = 12.0;
+const GAP: f32 = 8.0;
+const WORD_GAP: f32 = 6.0;
+const CLOSE: f32 = 16.0;
+const MARGIN: f32 = 10.0;
+/// The progress ring around the icon while the update downloads.
+const RING_RADIUS: f32 = 10.5;
+const RING_WIDTH: f32 = 2.2;
+
+const ARRIVE: Duration = Duration::from_millis(520);
+/// The sweep of light across a newly arrived capsule: twice, then still.
+const SWEEP_DELAY: Duration = Duration::from_millis(600);
+const SWEEP: Duration = Duration::from_millis(1500);
+const SWEEPS: u32 = 2;
+const RESIZE: Duration = Duration::from_millis(380);
+const SHAKE: Duration = Duration::from_millis(420);
+/// Folding into the icon, then the icon's flight to the gear.
+const FOLD: Duration = Duration::from_millis(220);
+const FLIGHT: Duration = Duration::from_millis(680);
+const FRAME: Duration = Duration::from_millis(16);
+/// How long a click shows as pressed.
+const PRESS: Duration = Duration::from_millis(160);
+/// How long after it changes what it says before a click on it counts: a
+/// click aimed at what it said a moment ago must not install or restart.
+const SETTLE: Duration = Duration::from_millis(350);
+
+thread_local! {
+ /// Dismissed in any window: it stays in the gear's dot until the next
+ /// launch.
+ static DISMISSED: Cell<bool> = const { Cell::new(false) };
+}
+
+/// Whether the capsule has gone into the gear's dot.
+pub(crate) fn dismissed() -> bool {
+ DISMISSED.with(Cell::get)
+}
+
+/// The settings gear's dot, when the capsule has gone into it: red when the
+/// install failed.
+pub(crate) fn gear_dot() -> Option<bool> {
+ if !dismissed() {
+ return None;
+ }
+ let status = crate::settings_window::update_capsule_status()?;
+ Some(status == UpdateCapsuleStatus::Failed)
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+enum Kind {
+ Available,
+ Installing,
+ Restart,
+ Installed,
+ Failed,
+}
+
+impl Kind {
+ fn of(status: &UpdateCapsuleStatus) -> Self {
+ match status {
+ UpdateCapsuleStatus::Available { .. } => Self::Available,
+ UpdateCapsuleStatus::Installing { .. } => Self::Installing,
+ UpdateCapsuleStatus::Installed { restart: true } => Self::Restart,
+ UpdateCapsuleStatus::Installed { restart: false } => Self::Installed,
+ UpdateCapsuleStatus::Failed => Self::Failed,
+ }
+ }
+}
+
+/// One window's capsule between frames.
+#[derive(Default)]
+pub(crate) struct UpdateCapsule {
+ /// When this window first painted it: the arrival and the sweep time
+ /// from here.
+ shown_at: Option<Instant>,
+ kind: Option<Kind>,
+ changed_at: Option<Instant>,
+ /// The width without the close button, eased on a change of words.
+ width: Option<Timeline>,
+ width_target: f32,
+ /// How far the close button has opened, 0 to 1.
+ close: Option<Timeline>,
+ close_open: bool,
+ /// What was last painted, for the flight to start from.
+ painted: Option<Painted>,
+ flight: Option<Flight>,
+ /// The gear dot's centre and diameter: set by the sidebar as it paints,
+ /// and read (then cleared) by the capsule later in the same frame.
+ pub(crate) gear_dot_slot: Option<(f32, f32, f32)>,
+ gear_dot: Option<(f32, f32, f32)>,
+ /// Whether the last frame was part of a movement still under way.
+ animating: bool,
+ pressed_at: Option<Instant>,
+}
+
+impl UpdateCapsule {
+ /// Its movements are short and few, and one stopped half way would stay
+ /// on screen like that: they finish in an unfocused window too. The
+ /// turning ring is not one of them; it keeps the spinners' clock.
+ pub(crate) fn owes_frames(&self) -> bool {
+ self.animating || self.flight.is_some()
+ }
+}
+
+#[derive(Clone, Copy)]
+struct Painted {
+ rect: euclid::Rect<f32, window::PixelUnit>,
+ fill: LinearRgba,
+ edge: LinearRgba,
+ shadow: LinearRgba,
+ icon_centre: (f32, f32),
+ icon_color: LinearRgba,
+}
+
+struct Flight {
+ started: Instant,
+ from: Painted,
+ to: Option<(f32, f32, f32)>,
+}
+
+impl crate::TermWindow {
+ pub(crate) fn paint_update_capsule(&mut self) -> anyhow::Result<()> {
+ let now = Instant::now();
+ let gear_dot = self.update_capsule.gear_dot_slot.take();
+ self.update_capsule.gear_dot = gear_dot;
+ if self.update_capsule.flight.is_some() {
+ return self.paint_update_capsule_flight(now);
+ }
+ let status = crate::settings_window::update_capsule_status();
+ // Out of the way while a menu, the palette or a dialog is up, and
+ // while the right sidebar is slid out over the corner.
+ let hidden = dismissed()
+ || self.context_menu.is_some()
+ || self.command_palette.is_some()
+ || self.get_modal().is_some()
+ || (self.right_sidebar_collapsed && self.right_sidebar_presented());
+ let Some(status) = status.filter(|_| !hidden) else {
+ let capsule = &mut self.update_capsule;
+ if status_gone(&capsule.kind, hidden) {
+ *capsule = UpdateCapsule {
+ gear_dot: capsule.gear_dot,
+ ..UpdateCapsule::default()
+ };
+ }
+ capsule.painted = None;
+ capsule.animating = false;
+ return Ok(());
+ };
+
+ let settings = crate::native_settings::load_shared();
+ let font_size = crate::native_settings::home_font_size(&settings);
+ let main_font = self
+ .fonts
+ .title_font_with_size_and_weight(font_size, 500)
+ .context("update capsule font")?;
+ let sub_font = self
+ .fonts
+ .title_font_with_size_and_weight(font_size, 400)
+ .context("update capsule font")?;
+ let metrics = RenderMetrics::with_font_metrics(&main_font.metrics());
+ let line = metrics.cell_size.height as f32;
+
+ let kind = Kind::of(&status);
+ let (main, sub, sub_room) = match &status {
+ UpdateCapsuleStatus::Available { version } => (
+ crate::i18n::tr("update-capsule-available"),
+ version.clone(),
+ None,
+ ),
+ UpdateCapsuleStatus::Installing {
+ fraction: Some(fraction),
+ } => (
+ crate::i18n::tr("update-capsule-downloading"),
+ format!("{}%", (fraction * 100.0).floor() as u32),
+ // The percentage changes every report; room for the widest
+ // keeps the capsule from twitching as it counts.
+ Some("100%"),
+ ),
+ UpdateCapsuleStatus::Installing { fraction: None } => (
+ crate::i18n::tr("update-capsule-installing"),
+ String::new(),
+ None,
+ ),
+ UpdateCapsuleStatus::Installed { restart: true } => (
+ crate::i18n::tr("update-capsule-restart"),
+ String::new(),
+ None,
+ ),
+ UpdateCapsuleStatus::Installed { restart: false } => (
+ crate::i18n::tr("update-capsule-installed"),
+ String::new(),
+ None,
+ ),
+ UpdateCapsuleStatus::Failed => (
+ crate::i18n::tr("update-capsule-failed"),
+ crate::i18n::tr("update-capsule-retry"),
+ None,
+ ),
+ };
+
+ let main_width = self
+ .cached_ui_text_advance(&main_font, &metrics, &main)?
+ .ceil();
+ let sub_width = match sub_room {
+ Some(room) => self.cached_ui_text_advance(&sub_font, &metrics, room)?,
+ None => self.cached_ui_text_advance(&sub_font, &metrics, &sub)?,
+ }
+ .ceil();
+ let scale = self.ui_f32(1.0);
+ let px = move |value: f32| value * POINT * scale;
+ let natural = px(PAD_LEFT + ICON + GAP)
+ + main_width
+ + if sub_width > 0.0 {
+ px(WORD_GAP) + sub_width
+ } else {
+ 0.0
+ }
+ + px(PAD_RIGHT);
+
+ // Where it sits: the same distance from the bottom and the right of
+ // the window's terminal area, left of the right sidebar; above the
+ // quote line when that is on, as it is drawn in that corner.
+ let (_, padding_top) = self.padding_left_top();
+ let border = self.get_os_border();
+ let (top_tab_height, bottom_tab_height) = self.pane_area_insets();
+ let content_bottom =
+ self.dimensions.pixel_height as f32 - border.bottom.get() as f32 - bottom_tab_height;
+ let grid_top = border.top.get() as f32 + top_tab_height + padding_top;
+ let grid_bottom = grid_top + self.terminal_size.pixel_height as f32;
+ let floor = if settings.terminal.bottom_quote_enabled {
+ grid_bottom
+ } else {
+ content_bottom
+ };
+
+ let hovered = self
+ .update_capsule
+ .painted
+ .is_some_and(|painted| pointer_over(self, painted.rect));
+
+ let capsule = &mut self.update_capsule;
+ let shown_at = *capsule.shown_at.get_or_insert(now);
+ if capsule.kind != Some(kind) {
+ if capsule.kind.is_some() {
+ capsule.changed_at = Some(now);
+ }
+ capsule.kind = Some(kind);
+ }
+ // Under the pointer it only grows: shrinking would pull its edge out
+ // from under the pointer, which then closes the close button and
+ // shrinks it again. It takes its own size once the pointer leaves.
+ let natural = if hovered && capsule.width.is_some() {
+ natural.max(capsule.width_target)
+ } else {
+ natural
+ };
+ match capsule.width.as_mut() {
+ Some(width) if (capsule.width_target - natural).abs() > 0.5 => {
+ width.retarget(now, natural, RESIZE, Easing::OutCubic);
+ capsule.width_target = natural;
+ }
+ Some(_) => {}
+ None => {
+ capsule.width = Some(Timeline::settled(now, natural));
+ capsule.width_target = natural;
+ }
+ }
+ // Open in every state: one shutting as a click starts the download
+ // would shrink the capsule under the pointer that is still on it.
+ // Closed during the download, the install carries on and the dot
+ // waits on the gear.
+ let open = hovered;
+ if capsule.close.is_none() {
+ capsule.close = Some(Timeline::settled(now, 0.0));
+ }
+ if open != capsule.close_open {
+ capsule.close_open = open;
+ if let Some(close) = capsule.close.as_mut() {
+ close.retarget(
+ now,
+ if open { 1.0 } else { 0.0 },
+ Duration::from_millis(240),
+ Easing::OutCubic,
+ );
+ }
+ }
+ let mut animating = false;
+ if let Some(width) = capsule.width.as_mut() {
+ animating |= width.advance(now);
+ }
+ if let Some(close) = capsule.close.as_mut() {
+ animating |= close.advance(now);
+ }
+ let base_width = capsule.width.as_ref().map_or(natural, |w| w.value(now));
+ let close_open = capsule
+ .close
+ .as_ref()
+ .map_or(0.0, |c| c.value(now))
+ .clamp(0.0, 1.0);
+ let changed_at = capsule.changed_at;
+ let pressed = match capsule.pressed_at {
+ Some(at) if now.duration_since(at) < PRESS => {
+ animating = true;
+ true
+ }
+ _ => false,
+ };
+
+ let height = px(HEIGHT);
+ let width = base_width + px(CLOSE + GAP) * close_open;
+ let right = self.dimensions.pixel_width as f32
+ - border.right.get() as f32
+ - self.right_sidebar_width() as f32
+ - px(MARGIN);
+ let bottom = floor - px(MARGIN);
+
+ // Arrival: up from below, overshooting a touch, fading in.
+ let arrive = (now.duration_since(shown_at).as_secs_f32() / ARRIVE.as_secs_f32()).min(1.0);
+ animating |= arrive < 1.0;
+ let rise = (1.0 - back_out(arrive)) * px(18.0);
+ let alpha = Easing::Smooth.apply((arrive * 1.6).min(1.0));
+ // A failure shakes it once.
+ let shake = match (kind, changed_at) {
+ (Kind::Failed, Some(at)) if now.duration_since(at) < SHAKE => {
+ animating = true;
+ shake_offset(now.duration_since(at).as_secs_f32() / SHAKE.as_secs_f32()) * px(1.0)
+ }
+ _ => 0.0,
+ };
+ let rect = euclid::rect(
+ (right - width + shake).round(),
+ (bottom - height + rise).round(),
+ width.round(),
+ height,
+ );
+
+ let chrome = self.chrome();
+ let mut card = chrome.as_menu_card();
+ crate::native_settings::apply_ui_colors(&mut card, self.config.ui_colors.as_ref());
+ let dark = card.is_dark();
+ let white = LinearRgba::with_srgba(255, 255, 255, 255);
+ let (fill, edge, text, muted) = if kind == Kind::Restart {
+ (
+ if pressed {
+ crate::ui::color::mix(chrome.accent, LinearRgba::with_srgba(0, 0, 0, 255), 0.18)
+ } else if hovered {
+ chrome.accent_hover
+ } else {
+ chrome.accent
+ },
+ LinearRgba::with_components(0.0, 0.0, 0.0, 0.0),
+ white,
+ white.mul_alpha(0.72),
+ )
+ } else {
+ (
+ // The menus' hover colour is a wash meant to lie over their
+ // card; on its own it would let the terminal show through.
+ if pressed {
+ crate::ui::color::mix(card.control_bg, card.text, 0.16)
+ } else if hovered {
+ crate::ui::color::mix(card.control_bg, card.text, 0.08)
+ } else {
+ card.control_bg
+ },
+ card.control_border,
+ card.text,
+ card.muted_text,
+ )
+ };
+ let icon_bg = match kind {
+ Kind::Available | Kind::Installed => chrome.accent,
+ Kind::Installing => fill,
+ Kind::Restart => white.mul_alpha(0.22),
+ Kind::Failed => chrome.danger,
+ };
+ let sub_color = if kind == Kind::Failed {
+ chrome.accent
+ } else {
+ muted
+ };
+
+ // The sweep, while it runs: its centre across the capsule, 0 to 1.
+ let sweep = if kind == Kind::Available {
+ let since = now.duration_since(shown_at);
+ let end = SWEEP_DELAY + SWEEP * SWEEPS;
+ if since < end {
+ animating = true;
+ }
+ since
+ .checked_sub(SWEEP_DELAY)
+ .filter(|after| *after < SWEEP * SWEEPS)
+ .map(|after| {
+ let t = (after.as_secs_f32() % SWEEP.as_secs_f32()) / SWEEP.as_secs_f32();
+ Easing::Smooth.apply(t)
+ })
+ } else {
+ None
+ };
+
+ let gl_state = self
+ .render_state
+ .as_ref()
+ .context("update capsule render state")?;
+ let layer = gl_state
+ .layer_for_zindex(ZINDEX)
+ .context("update capsule layer")?;
+ let mut layers = layer.quad_allocator();
+ let ctx = DrawContext::new(gl_state, self.dimensions, &metrics);
+ let radius = height / 2.0;
+ let shadow = LinearRgba::with_components(0.0, 0.0, 0.0, if dark { 0.58 } else { 0.43 });
+ ctx.draw_elevated_surface(
+ &mut layers,
+ 0,
+ rect,
+ fill.mul_alpha(alpha),
+ edge.mul_alpha(alpha),
+ shadow.mul_alpha(alpha),
+ radius,
+ )
+ .context("update capsule surface")?;
+
+ if let Some(at) = sweep {
+ let band = rect.size.width * 0.45;
+ let centre = rect.origin.x - band / 2.0 + (rect.size.width + band) * at;
+ let peak = if dark {
+ white.mul_alpha(0.16)
+ } else {
+ chrome.accent.mul_alpha(0.14)
+ };
+ paint_sweep(&ctx, &mut layers, rect, centre, band, peak.mul_alpha(alpha))?;
+ }
+
+ let icon_size = px(ICON);
+ let icon_cx = rect.origin.x + px(PAD_LEFT) + icon_size / 2.0;
+ let icon_cy = rect.origin.y + height / 2.0;
+ ctx.draw_disc(
+ &mut layers,
+ 1,
+ icon_cx,
+ icon_cy,
+ icon_size,
+ icon_bg.mul_alpha(alpha),
+ )
+ .context("update capsule icon")?;
+ let glyph = px(12.0);
+ match &status {
+ UpdateCapsuleStatus::Installing { fraction } => {
+ let turn = match fraction {
+ Some(_) => 0.0,
+ // Without a fraction a quarter of the ring turns, on
+ // the spinners' clock: it asks for no frames of its own.
+ None => {
+ self.request_spinner_frame();
+ let frames = crate::termwindow::ui::status_icon::spinner_frames();
+ (frames % SPIN_STEPS) as f32 / SPIN_STEPS as f32
+ }
+ };
+ paint_ring(
+ &ctx,
+ &mut layers,
+ (icon_cx, icon_cy),
+ px(RING_RADIUS),
+ px(RING_WIDTH),
+ *fraction,
+ turn,
+ muted.mul_alpha(0.35 * alpha),
+ chrome.accent.mul_alpha(alpha),
+ fill.mul_alpha(alpha),
+ )?;
+ ctx.draw_svg_icon(
+ &mut layers,
+ SvgIcon::ArrowDown,
+ icon_cx - glyph / 2.0,
+ icon_cy - glyph / 2.0,
+ glyph,
+ chrome.accent.mul_alpha(alpha),
+ )?;
+ }
+ UpdateCapsuleStatus::Failed => {
+ // "!": a bar and a dot.
+ let bar = px(2.2);
+ self.fill_rounded_rectangle(
+ &mut layers,
+ 2,
+ euclid::rect(icon_cx - bar / 2.0, icon_cy - px(5.5), bar, px(6.5)),
+ white.mul_alpha(alpha),
+ bar / 2.0,
+ )?;
+ ctx.draw_disc(
+ &mut layers,
+ 2,
+ icon_cx,
+ icon_cy + px(4.0),
+ px(2.6),
+ white.mul_alpha(alpha),
+ )?;
+ }
+ UpdateCapsuleStatus::Available { .. } | UpdateCapsuleStatus::Installed { .. } => {
+ let icon = if kind == Kind::Restart {
+ SvgIcon::RotateCw
+ } else {
+ SvgIcon::ArrowDown
+ };
+ ctx.draw_svg_icon(
+ &mut layers,
+ icon,
+ icon_cx - glyph / 2.0,
+ icon_cy - glyph / 2.0,
+ glyph,
+ white.mul_alpha(alpha),
+ )?;
+ }
+ }
+
+ // The words, faded in again after a change.
+ let words_alpha = alpha
+ * changed_at.map_or(1.0, |at| {
+ let t = now.duration_since(at).as_secs_f32() / 0.18;
+ animating |= t < 1.0;
+ Easing::Smooth.apply(t.min(1.0))
+ });
+ let text_x = rect.origin.x + px(PAD_LEFT + ICON + GAP);
+ let text_y = (icon_cy - line / 2.0).round();
+ self.paint_agent_text(
+ &mut layers,
+ &main_font,
+ metrics,
+ &main,
+ text_x.round() as usize,
+ text_y as usize,
+ // Room for the whole word: the capsule is sized to it, and a limit
+ // that rounding can shave a pixel off fades its last letter.
+ (main_width + px(2.0)) as usize,
+ text.mul_alpha(words_alpha),
+ )?;
+ if !sub.is_empty() {
+ let sub_x = text_x + main_width + px(WORD_GAP);
+ self.paint_agent_text(
+ &mut layers,
+ &sub_font,
+ metrics,
+ &sub,
+ sub_x.round() as usize,
+ text_y as usize,
+ (sub_width + px(2.0)) as usize,
+ sub_color.mul_alpha(words_alpha),
+ )?;
+ }
+
+ let close_size = px(13.0);
+ let close_rect = euclid::rect(
+ rect.max_x() - px(PAD_RIGHT) - px(CLOSE),
+ icon_cy - px(CLOSE) / 2.0,
+ px(CLOSE),
+ px(CLOSE),
+ );
+ let close_shown = close_open > 0.01;
+ let close_hovered = close_shown && pointer_over(self, close_rect);
+ if close_shown {
+ ctx.draw_svg_icon(
+ &mut layers,
+ SvgIcon::X,
+ close_rect.origin.x + (px(CLOSE) - close_size) / 2.0,
+ icon_cy - close_size / 2.0,
+ close_size,
+ (if close_hovered { text } else { muted }).mul_alpha(close_open * alpha),
+ )?;
+ }
+ drop(layers);
+
+ self.update_capsule.painted = Some(Painted {
+ rect,
+ fill,
+ edge,
+ shadow,
+ icon_centre: (icon_cx, icon_cy),
+ icon_color: match kind {
+ Kind::Installing | Kind::Restart => chrome.accent,
+ _ => icon_bg,
+ },
+ });
+ // Clickable once it has arrived: until then a click is meant for
+ // whatever was in the corner, and goes there.
+ if arrive >= 1.0 {
+ self.ui_items.push(ui_item(rect, UIItemType::UpdateCapsule));
+ // The close button takes its clicks from the moment it shows.
+ if close_shown {
+ self.ui_items
+ .push(ui_item(close_rect, UIItemType::UpdateCapsuleDismiss));
+ }
+ }
+ self.update_capsule.animating = animating;
+ if animating {
+ self.update_next_frame_time(Some(now + FRAME));
+ }
+ Ok(())
+ }
+
+ /// The close button: fold into the icon and fly it into the gear.
+ pub(crate) fn dismiss_update_capsule(&mut self) {
+ let capsule = &mut self.update_capsule;
+ let Some(painted) = capsule.painted else {
+ DISMISSED.with(|dismissed| dismissed.set(true));
+ crate::frontend::front_end().invalidate_all_windows();
+ return;
+ };
+ capsule.flight = Some(Flight {
+ started: Instant::now(),
+ from: painted,
+ to: capsule.gear_dot,
+ });
+ if let Some(window) = self.window.as_ref() {
+ window.invalidate();
+ }
+ }
+
+ /// Whether a click on the capsule would do anything: nothing does while
+ /// the update installs.
+ pub(crate) fn update_capsule_clickable(&self) -> bool {
+ self.update_capsule.kind != Some(Kind::Installing)
+ }
+
+ /// What the capsule's click does in what it shows.
+ pub(crate) fn activate_update_capsule(&mut self) {
+ let now = Instant::now();
+ let status = crate::settings_window::update_capsule_status();
+ let capsule = &self.update_capsule;
+ // It acts on what was seen: not on a state that came since the last
+ // paint, nor on one only just painted.
+ let seen = status.as_ref().map(Kind::of) == capsule.kind;
+ let settled = capsule
+ .changed_at
+ .is_none_or(|at| now.duration_since(at) >= SETTLE);
+ let Some(status) = status.filter(|_| seen && settled) else {
+ return;
+ };
+ if Kind::of(&status) == Kind::Installing {
+ return;
+ }
+ self.update_capsule.pressed_at = Some(now);
+ if let Some(window) = self.window.as_ref() {
+ window.invalidate();
+ }
+ let acted = match status {
+ UpdateCapsuleStatus::Available { .. } | UpdateCapsuleStatus::Failed
+ if crate::settings_window::installs_updates_itself() =>
+ {
+ crate::settings_window::start_update_install()
+ }
+ UpdateCapsuleStatus::Installed { restart: true } => {
+ crate::settings_window::restart_into_update()
+ }
+ // A copy a package manager owns, or one whose restart would end
+ // terminals: the Update page says what to do instead.
+ _ => false,
+ };
+ if !acted {
+ crate::settings_window::show_update_page_from(
+ self.mux_window_id,
+ &self.active_space_id,
+ );
+ }
+ }
+
+ fn paint_update_capsule_flight(&mut self, now: Instant) -> anyhow::Result<()> {
+ let Some(flight) = self.update_capsule.flight.as_ref() else {
+ return Ok(());
+ };
+ let elapsed = now.duration_since(flight.started);
+ let (from, to) = (flight.from, flight.to);
+ let scale = self.ui_f32(1.0);
+ let px = move |value: f32| value * POINT * scale;
+ let settings = crate::native_settings::load_shared();
+ let font = self
+ .fonts
+ .title_font_with_size(crate::native_settings::home_font_size(&settings))
+ .context("update capsule font")?;
+ let metrics = RenderMetrics::with_font_metrics(&font.metrics());
+ let gl_state = self
+ .render_state
+ .as_ref()
+ .context("update capsule render state")?;
+ let layer = gl_state
+ .layer_for_zindex(ZINDEX)
+ .context("update capsule layer")?;
+ let mut layers = layer.quad_allocator();
+ let ctx = DrawContext::new(gl_state, self.dimensions, &metrics);
+
+ let icon = px(ICON);
+ let (cx, cy) = from.icon_centre;
+ if elapsed >= FOLD + FLIGHT {
+ // Landed. The sidebar painted this frame before the capsule
+ // was dismissed, still without its dot: this frame the disc
+ // stands in for it, and from the next the sidebar draws it.
+ if let Some((x, y, diameter)) = to {
+ ctx.draw_disc(&mut layers, 1, x, y, diameter, from.icon_color)?;
+ }
+ drop(layers);
+ self.update_capsule = UpdateCapsule {
+ gear_dot: self.update_capsule.gear_dot,
+ ..UpdateCapsule::default()
+ };
+ DISMISSED.with(|dismissed| dismissed.set(true));
+ crate::frontend::front_end().invalidate_all_windows();
+ return Ok(());
+ }
+ if elapsed < FOLD {
+ // The surface closes in on the icon and fades away.
+ let t = Easing::OutCubic.apply(elapsed.as_secs_f32() / FOLD.as_secs_f32());
+ let rect = from.rect;
+ let side = rect.size.height;
+ let folded: euclid::Rect<f32, window::PixelUnit> = euclid::rect(
+ rect.origin.x + (cx - side / 2.0 - rect.origin.x) * t,
+ rect.origin.y,
+ rect.size.width + (side - rect.size.width) * t,
+ side,
+ );
+ ctx.draw_elevated_surface(
+ &mut layers,
+ 0,
+ folded,
+ from.fill.mul_alpha(1.0 - t),
+ from.edge.mul_alpha(1.0 - t),
+ from.shadow.mul_alpha(1.0 - t),
+ side / 2.0,
+ )?;
+ ctx.draw_disc(&mut layers, 1, cx, cy, icon, from.icon_color)?;
+ } else {
+ let t = (elapsed - FOLD).as_secs_f32() / FLIGHT.as_secs_f32();
+ let (x, y, diameter, alpha) = match to {
+ Some((to_x, to_y, dot)) => {
+ let along = Easing::Smooth.apply(t);
+ // A toss: up and over, then down into the dot.
+ let lift = px(90.0) * (std::f32::consts::PI * along).sin();
+ let diameter = icon + (dot - icon) * Easing::OutCubic.apply(t);
+ (
+ cx + (to_x - cx) * along,
+ cy + (to_y - cy) * along - lift,
+ diameter,
+ 1.0,
+ )
+ }
+ // No gear on screen: it shrinks away where it is.
+ None => (cx, cy, icon * (1.0 - t), 1.0 - t),
+ };
+ ctx.draw_disc(
+ &mut layers,
+ 1,
+ x,
+ y,
+ diameter,
+ from.icon_color.mul_alpha(alpha),
+ )?;
+ }
+ drop(layers);
+ self.update_next_frame_time(Some(now + FRAME));
+ Ok(())
+ }
+}
+
+/// The spinners' frames to one turn of the ring.
+const SPIN_STEPS: u128 = 12;
+
+fn ui_item(rect: euclid::Rect<f32, window::PixelUnit>, item_type: UIItemType) -> UIItem {
+ UIItem {
+ x: rect.origin.x.max(0.0) as usize,
+ y: rect.origin.y.max(0.0) as usize,
+ width: rect.size.width as usize,
+ height: rect.size.height as usize,
+ item_type,
+ }
+}
+
+fn pointer_over(window: &crate::TermWindow, rect: euclid::Rect<f32, window::PixelUnit>) -> bool {
+ window.is_pointer_over_ui_rect(
+ rect.origin.x.max(0.0) as usize,
+ rect.origin.y.max(0.0) as usize,
+ rect.size.width as usize,
+ rect.size.height as usize,
+ )
+}
+
+/// Whether a capsule that is not painted this frame should start over:
+/// it went away rather than being hidden for a moment under a menu.
+fn status_gone(kind: &Option<Kind>, hidden: bool) -> bool {
+ kind.is_some() && !hidden
+}
+
+/// Ease-out with an overshoot of about a tenth.
+fn back_out(t: f32) -> f32 {
+ let (c1, c3) = (1.2_f32, 2.2_f32);
+ let u = t - 1.0;
+ 1.0 + c3 * u * u * u + c1 * u * u
+}
+
+/// The shake's offset, in points, at `t` from 0 to 1.
+fn shake_offset(t: f32) -> f32 {
+ let keys = [
+ (0.0, 0.0),
+ (0.15, -1.0),
+ (0.3, 3.0),
+ (0.45, -4.0),
+ (0.55, -4.0),
+ (0.7, 3.0),
+ (0.85, -1.0),
+ (1.0, 0.0),
+ ];
+ for pair in keys.windows(2) {
+ let ((t0, v0), (t1, v1)) = (pair[0], pair[1]);
+ if t <= t1 {
+ let f = if t1 > t0 { (t - t0) / (t1 - t0) } else { 1.0 };
+ return v0 + (v1 - v0) * f;
+ }
+ }
+ 0.0
+}
+
+/// A soft vertical band of light centred at `centre`, `band` wide, cut to
+/// the capsule's rounded ends.
+fn paint_sweep(
+ ctx: &DrawContext,
+ layers: &mut crate::quad::TripleLayerQuadAllocator,
+ rect: euclid::Rect<f32, window::PixelUnit>,
+ centre: f32,
+ band: f32,
+ peak: LinearRgba,
+) -> anyhow::Result<()> {
+ let radius = rect.size.height / 2.0;
+ let cy = rect.origin.y + radius;
+ let left_cap = rect.origin.x + radius;
+ let right_cap = rect.max_x() - radius;
+ let slice = ctx.px(2.0).max(1.0);
+ let mut x = (centre - band / 2.0).max(rect.origin.x);
+ let end = (centre + band / 2.0).min(rect.max_x());
+ while x < end {
+ let mid = x + slice / 2.0;
+ let off = if mid < left_cap {
+ left_cap - mid
+ } else if mid > right_cap {
+ mid - right_cap
+ } else {
+ 0.0
+ };
+ if off < radius {
+ let half = (radius * radius - off * off).sqrt();
+ let d = (mid - centre) / (band / 2.0);
+ let strength = (1.0 - d * d).max(0.0).powi(2);
+ ctx.draw_rect(
+ layers,
+ 1,
+ x,
+ cy - half,
+ slice.min(end - x),
+ half * 2.0,
+ peak.mul_alpha(strength),
+ )?;
+ }
+ x += slice;
+ }
+ Ok(())
+}
+
+/// The ring around the icon: a faint track, the downloaded part over it
+/// from twelve o'clock, then the surface's colour inside to cut the ring's
+/// inner edge clean. Without a fraction, a quarter of it at `turn` (0 to 1).
+#[allow(clippy::too_many_arguments)]
+fn paint_ring(
+ ctx: &DrawContext,
+ layers: &mut crate::quad::TripleLayerQuadAllocator,
+ (cx, cy): (f32, f32),
+ radius: f32,
+ width: f32,
+ fraction: Option<f32>,
+ turn: f32,
+ track: LinearRgba,
+ arc: LinearRgba,
+ inside: LinearRgba,
+) -> anyhow::Result<()> {
+ use std::f32::consts::TAU;
+ ctx.draw_disc(layers, 1, cx, cy, (radius + width / 2.0) * 2.0, track)?;
+ let (start, sweep) = match fraction {
+ Some(fraction) => (0.0, fraction * TAU),
+ None => (turn * TAU, TAU / 4.0),
+ };
+ if sweep > 0.0 {
+ let steps = ((radius * sweep) / ctx.px(0.75).max(0.5)).ceil().max(1.0) as usize;
+ for step in 0..=steps {
+ let angle = start + sweep * step as f32 / steps as f32 - TAU / 4.0;
+ ctx.draw_disc(
+ layers,
+ 1,
+ cx + radius * angle.cos(),
+ cy + radius * angle.sin(),
+ width,
+ arc,
+ )?;
+ }
+ }
+ ctx.draw_disc(layers, 1, cx, cy, (radius - width / 2.0) * 2.0, inside)?;
+ Ok(())
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn the_arrival_overshoots_a_little_and_settles() {
+ assert!(back_out(0.0).abs() < 1e-6);
+ assert!((back_out(1.0) - 1.0).abs() < 1e-6);
+ let peak = (0..=100)
+ .map(|i| back_out(i as f32 / 100.0))
+ .fold(0.0, f32::max);
+ assert!(peak > 1.02 && peak < 1.15, "{}", peak);
+ }
+
+ #[test]
+ fn the_shake_starts_and_ends_at_rest() {
+ assert_eq!(shake_offset(0.0), 0.0);
+ assert_eq!(shake_offset(1.0), 0.0);
+ assert!(shake_offset(0.45).abs() > 3.0);
+ }
+
+ #[test]
+ fn the_capsule_reads_each_status_as_its_kind() {
+ let version = || "1.2.3".to_string();
+ assert_eq!(
+ Kind::of(&UpdateCapsuleStatus::Available { version: version() }),
+ Kind::Available
+ );
+ assert_eq!(
+ Kind::of(&UpdateCapsuleStatus::Installing { fraction: None }),
+ Kind::Installing
+ );
+ assert_eq!(
+ Kind::of(&UpdateCapsuleStatus::Installed { restart: true }),
+ Kind::Restart
+ );
+ assert_eq!(
+ Kind::of(&UpdateCapsuleStatus::Installed { restart: false }),
+ Kind::Installed
+ );
+ assert_eq!(Kind::of(&UpdateCapsuleStatus::Failed), Kind::Failed);
+ }
+}
diff --git a/wezterm-gui/src/termwindow/ui/sidebar.rs b/wezterm-gui/src/termwindow/ui/sidebar.rs
index 6bfb2d6f..4f9ae43d 100644
--- a/wezterm-gui/src/termwindow/ui/sidebar.rs
+++ b/wezterm-gui/src/termwindow/ui/sidebar.rs
@@ -3284,15 +3284,17 @@ impl crate::TermWindow {
settings_icon_size,
foreground,
)?;
- // A newer release exists: a dot on the gear's shoulder, ringed in
- // the sidebar background so it reads on the icon rather than in
- // it. This is the whole in-app notice; the page it leads to has
- // the details and the button.
- if crate::update::update_available() {
- let dot = (settings_icon_size / 3).max(self.ui_px(5)) as f32;
+ // The update capsule, once dismissed, lives on as a dot on the
+ // gear's shoulder, ringed in the sidebar background so it reads
+ // on the icon rather than in it; red when the install failed.
+ // Where the dot goes is recorded either way: the capsule flies
+ // there when it is dismissed.
+ let dot = (settings_icon_size / 3).max(self.ui_px(5)) as f32;
+ let dot_x = (settings_icon_x + settings_icon_size) as f32 - dot * 0.75;
+ let dot_y = settings_icon_y as f32 - dot * 0.25;
+ self.update_capsule.gear_dot_slot = Some((dot_x + dot / 2.0, dot_y + dot / 2.0, dot));
+ if let Some(failed) = crate::termwindow::render::update_capsule::gear_dot() {
let ring = dot + 2.0 * self.ui_f32(1.5);
- let dot_x = (settings_icon_x + settings_icon_size) as f32 - dot * 0.75;
- let dot_y = settings_icon_y as f32 - dot * 0.25;
self.fill_rounded_rectangle(
layers,
2,
@@ -3310,7 +3312,7 @@ impl crate::TermWindow {
layers,
2,
euclid::rect(dot_x, dot_y, dot, dot),
- chrome.accent,
+ if failed { chrome.danger } else { chrome.accent },
dot / 2.0,
)
.context("sidebar update dot")?;
diff --git a/wezterm-gui/src/update.rs b/wezterm-gui/src/update.rs
index 4ad791ec..49f91ab1 100644
--- a/wezterm-gui/src/update.rs
+++ b/wezterm-gui/src/update.rs
@@ -17,28 +17,64 @@ lazy_static::lazy_static! {
static ref UPDATER_WINDOW: Mutex<Option<ConnectionUI>> = Mutex::new(None);
}
-/// Whether a release newer than this build is known. What the sidebar's
-/// settings button reads on every paint, so it is a flag and not a file:
-/// set from the cache at startup and by the checker after every check.
+/// Whether a release newer than this build is known. What the update
+/// capsule reads on every paint, so it is a flag and not a file: set from
+/// the cache at startup and by the checker after every check.
///
/// Nothing is written into terminal output any more. The upstream banner
/// printed two rows and an icon into every new local shell and left them in
-/// its scrollback; a dot on the settings button says the same thing without
-/// taking any space, on remote panes too, and leads to the page that can
-/// act on it.
+/// its scrollback; the capsule floating in the window's corner says the same
+/// thing without taking any of the terminal's lines, on remote panes too,
+/// and installs the update itself.
static UPDATE_AVAILABLE: AtomicBool = AtomicBool::new(false);
pub fn update_available() -> bool {
UPDATE_AVAILABLE.load(Ordering::Relaxed)
}
-/// Record the flag; when it changes, ask every window to repaint so the dot
-/// appears or goes away. Only the checker thread and a check asked for from
-/// Settings call this: both run once the GUI is up, and spawning onto the
-/// main thread needs its scheduler.
-fn set_update_available(available: bool) {
+lazy_static::lazy_static! {
+ /// The release `UPDATE_AVAILABLE` is about, kept in memory with the
+ /// flag: the update capsule names it on every paint and installs it when
+ /// clicked, whether or not the check could be saved to disk.
+ static ref AVAILABLE_RELEASE: Mutex<Option<Release>> = Mutex::new(None);
+}
+
+/// The newer release, while one is known.
+pub fn available_release() -> Option<Release> {
+ if !update_available() {
+ return None;
+ }
+ AVAILABLE_RELEASE.lock().ok()?.clone()
+}
+
+/// The newer release's version, without its `v`, while one is known.
+pub fn available_version() -> Option<String> {
+ if !update_available() {
+ return None;
+ }
+ let release = AVAILABLE_RELEASE.lock().ok()?;
+ release
+ .as_ref()
+ .map(|release| release.tag_name.trim_start_matches('v').to_string())
+}
+
+/// Record the flag and the release it is about; when either changes, ask
+/// every window to repaint so the update capsule appears, goes away or
+/// names the new release. Only the checker thread and a check asked for
+/// from Settings call this: both run once the GUI is up, and spawning onto
+/// the main thread needs its scheduler.
+fn set_update_available(available: bool, latest: &Release) {
+ let renamed = AVAILABLE_RELEASE
+ .lock()
+ .map(|mut release| {
+ let renamed = release.as_ref().map(|release| release.tag_name.as_str())
+ != Some(latest.tag_name.as_str());
+ *release = Some(latest.clone());
+ renamed
+ })
+ .unwrap_or(false);
let was = UPDATE_AVAILABLE.swap(available, Ordering::Relaxed);
- if was != available {
+ if was != available || (available && renamed) {
promise::spawn::spawn_into_main_thread(async move {
crate::frontend::front_end().invalidate_all_windows();
})
@@ -54,6 +90,9 @@ pub fn load_last_release_info() {
return;
}
let status = cached_update_status();
+ if let Ok(mut release) = AVAILABLE_RELEASE.lock() {
+ release.clone_from(&status.latest);
+ }
UPDATE_AVAILABLE.store(
status.update_available || always_show_update_ui(),
Ordering::Relaxed,
@@ -148,7 +187,7 @@ mod update_version_tests {
pub fn check_now() -> anyhow::Result<()> {
let latest = get_latest_release_info()?;
let newer = is_newer_release(&latest.tag_name, &running_release_version());
- set_update_available(newer || always_show_update_ui());
+ set_update_available(newer || always_show_update_ui(), &latest);
// Settings shows what it reads back from the cache: an answer that could
// not be kept there is, as far as the page can tell, no answer.
record_latest_release(&latest)
@@ -196,7 +235,7 @@ fn update_checker() {
if let Ok(latest) = get_latest_release_info() {
let current = running_release_version();
let newer = is_newer_release(&latest.tag_name, &current);
- set_update_available(newer || force_ui);
+ set_update_available(newer || force_ui, &latest);
if newer || force_ui {
log::info!(
"latest release {} is newer than current build {}",