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.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
wezterm-gui: a Web section in Settings
RoversX467898d700c7
diff --git a/wezterm-gui/i18n/en-US.ftl b/wezterm-gui/i18n/en-US.ftlindex 54abe370..569ec9d3 100644--- a/wezterm-gui/i18n/en-US.ftl+++ b/wezterm-gui/i18n/en-US.ftl@@ -679,3 +679,40 @@ settings-update-method-system = Installed by the system package manager: installsettings-update-method-windows = Installed by the Windows installer; installing an update downloads the new installer and runs it.settings-update-method-source = This is a build from source: pull the repository and build again.settings-update-method-unknown = This copy was not installed by the install script, so ThinkTerm will not replace it; update it the way it was installed.++# --- Web: browser access to this machine's terminals ---+settings-section-web = Web+settings-web-heading = Reach these terminals from a browser+settings-web-enable = Allow browser access+settings-web-enable-description = Off. Nothing is listening, and no link will open.+settings-web-on-at = Listening on { $address }. Only someone holding a link can get in.+settings-web-link = Access link+settings-web-link-description = Whoever opens it gets a shell as you.+settings-web-ttl = Link expires+settings-web-ttl-description = Applies to the next link you copy.+settings-web-ttl-never = Until revoked+settings-web-ttl-hours = { $hours ->+ [one] 1 hour+ *[other] { $hours } hours+}+settings-web-ttl-days = { $days ->+ [one] 1 day+ *[other] { $days } days+}+settings-web-copy = Copy link+settings-web-copied = Copied+settings-web-links-heading = Links you have handed out+settings-web-tokens-empty = No links have been handed out.+settings-web-token-meta = Expires { $expires } · { $connections ->+ [0] no browser connected+ [one] 1 browser connected+ *[other] { $connections } browsers connected+}+settings-web-token-unused = Not used yet+settings-web-token-never = never+settings-web-revoke = Revoke+settings-web-revoke-all = Revoke all+settings-web-revoke-all-label = Every link+settings-web-revoke-all-description = Cuts off every browser at once.+settings-web-no-server = No mux server to ask. Browser access needs one running.+settings-web-no-listener = Nothing is listening, so there is nowhere for a link to point. Turn browser access on first.diff --git a/wezterm-gui/i18n/fr-FR.ftl b/wezterm-gui/i18n/fr-FR.ftlindex d810b4d0..1741262e 100644--- a/wezterm-gui/i18n/fr-FR.ftl+++ b/wezterm-gui/i18n/fr-FR.ftl@@ -676,3 +676,40 @@ settings-update-method-system = Installé par le gestionnaire de paquets du systsettings-update-method-windows = Installé par l'installateur Windows ; la mise à jour télécharge le nouvel installateur et l'exécute.settings-update-method-source = Ceci est une compilation depuis les sources : mettez à jour le dépôt et recompilez.settings-update-method-unknown = Cette copie n'a pas été installée par le script d'installation ; ThinkTerm ne la remplacera pas. Mettez-la à jour comme elle a été installée.++# --- Web : accéder à ces terminaux depuis un navigateur ---+settings-section-web = Web+settings-web-heading = Ouvrir ces terminaux depuis un navigateur+settings-web-enable = Autoriser l'accès par navigateur+settings-web-enable-description = Désactivé. Rien n'écoute, et aucun lien ne s'ouvrira.+settings-web-on-at = À l'écoute sur { $address }. Seul quelqu'un muni d'un lien peut entrer.+settings-web-link = Lien d'accès+settings-web-link-description = Qui l'ouvre obtient un shell à votre nom.+settings-web-ttl = Expiration du lien+settings-web-ttl-description = S'applique au prochain lien copié.+settings-web-ttl-never = Jusqu'à révocation+settings-web-ttl-hours = { $hours ->+ [one] 1 heure+ *[other] { $hours } heures+}+settings-web-ttl-days = { $days ->+ [one] 1 jour+ *[other] { $days } jours+}+settings-web-copy = Copier le lien+settings-web-copied = Copié+settings-web-links-heading = Liens distribués+settings-web-tokens-empty = Aucun lien n'a été distribué.+settings-web-token-meta = Expire { $expires } · { $connections ->+ [0] aucun navigateur connecté+ [one] 1 navigateur connecté+ *[other] { $connections } navigateurs connectés+}+settings-web-token-unused = Jamais utilisé+settings-web-token-never = jamais+settings-web-revoke = Révoquer+settings-web-revoke-all = Tout révoquer+settings-web-revoke-all-label = Tous les liens+settings-web-revoke-all-description = Coupe tous les navigateurs d'un coup.+settings-web-no-server = Aucun serveur mux à interroger. L'accès par navigateur en requiert un.+settings-web-no-listener = Rien n'écoute, un lien ne pointerait nulle part. Activez d'abord l'accès par navigateur.diff --git a/wezterm-gui/i18n/ja-JP.ftl b/wezterm-gui/i18n/ja-JP.ftlindex e74eaa75..c5321081 100644--- a/wezterm-gui/i18n/ja-JP.ftl+++ b/wezterm-gui/i18n/ja-JP.ftl@@ -664,3 +664,33 @@ settings-update-method-system = システムのパッケージマネージャーsettings-update-method-windows = Windows インストーラーでインストールされています。アップデートは新しいインストーラーをダウンロードして実行します。settings-update-method-source = ソースからのビルドです。リポジトリを更新して再ビルドしてください。settings-update-method-unknown = このコピーはインストールスクリプトによるものではないため、ThinkTerm は置き換えません。元の方法で更新してください。++# --- Web: ブラウザからこのマシンの端末へ ---+settings-section-web = Web+settings-web-heading = ブラウザからこの端末を開く+settings-web-enable = ブラウザからのアクセスを許可+settings-web-enable-description = オフです。待ち受けておらず、リンクも開きません。+settings-web-on-at = { $address } で待ち受け中。リンクを持つ人だけが入れます。+settings-web-link = アクセスリンク+settings-web-link-description = 開いた人はあなたのシェルを得ます。+settings-web-ttl = リンクの有効期限+settings-web-ttl-description = 次にコピーするリンクに適用されます。+settings-web-ttl-never = 失効させるまで+settings-web-ttl-hours = { $hours } 時間+settings-web-ttl-days = { $days } 日+settings-web-copy = リンクをコピー+settings-web-copied = コピーしました+settings-web-links-heading = 発行済みのリンク+settings-web-tokens-empty = まだリンクを発行していません。+settings-web-token-meta = { $expires }に失効 · { $connections ->+ [0] 接続中のブラウザなし+ *[other] { $connections } 個のブラウザが接続中+}+settings-web-token-unused = 未使用+settings-web-token-never = 無期限+settings-web-revoke = 失効+settings-web-revoke-all = すべて失効+settings-web-revoke-all-label = すべてのリンク+settings-web-revoke-all-description = すべてのブラウザを一度に切断します。+settings-web-no-server = 問い合わせ先の mux サーバーがありません。ブラウザアクセスには必要です。+settings-web-no-listener = 待ち受けていないため、リンクの向き先がありません。先にブラウザアクセスを有効にしてください。diff --git a/wezterm-gui/i18n/zh-CN.ftl b/wezterm-gui/i18n/zh-CN.ftlindex 9a8fe09a..df20cdc7 100644--- a/wezterm-gui/i18n/zh-CN.ftl+++ b/wezterm-gui/i18n/zh-CN.ftl@@ -664,3 +664,33 @@ settings-update-method-system = 由系统包管理器安装:从发布页下载settings-update-method-windows = 由 Windows 安装器安装;安装更新会下载新安装器并运行。settings-update-method-source = 这是从源码构建的版本:拉取仓库后重新构建。settings-update-method-unknown = 这个副本不是由安装脚本安装的,ThinkTerm 不会替换它;请按原来的安装方式更新。++# --- 网页端:用浏览器访问这台机器的终端 ---+settings-section-web = 网页+settings-web-heading = 用浏览器打开这里的终端+settings-web-enable = 允许浏览器访问+settings-web-enable-description = 未开启。没有在监听,链接也打不开。+settings-web-on-at = 正在监听 { $address }。只有拿到链接的人进得来。+settings-web-link = 访问链接+settings-web-link-description = 打开它的人拿到的是你的 shell。+settings-web-ttl = 链接有效期+settings-web-ttl-description = 对下一次复制的链接生效。+settings-web-ttl-never = 直到手动吊销+settings-web-ttl-hours = { $hours } 小时+settings-web-ttl-days = { $days } 天+settings-web-copy = 复制链接+settings-web-copied = 已复制+settings-web-links-heading = 已发出的链接+settings-web-tokens-empty = 还没有发出过链接。+settings-web-token-meta = { $expires }失效 · { $connections ->+ [0] 无浏览器连接+ *[other] { $connections } 个浏览器已连接+}+settings-web-token-unused = 尚未使用+settings-web-token-never = 永不+settings-web-revoke = 吊销+settings-web-revoke-all = 全部吊销+settings-web-revoke-all-label = 所有链接+settings-web-revoke-all-description = 一次性切断所有浏览器。+settings-web-no-server = 没有可询问的 mux 服务端。网页访问需要它在运行。+settings-web-no-listener = 没有在监听,链接无处指向。请先打开浏览器访问。diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rsindex 7160025d..f5a7ff06 100644--- a/wezterm-gui/src/main.rs+++ b/wezterm-gui/src/main.rs@@ -61,6 +61,7 @@ mod scrollbar;mod secret;mod selection;mod settings_window;+mod web_settings;mod shapecache;mod shell_catalog;mod snippets;diff --git a/wezterm-gui/src/native_settings.rs b/wezterm-gui/src/native_settings.rsindex 3892d8ec..1fd2882d 100644--- a/wezterm-gui/src/native_settings.rs+++ b/wezterm-gui/src/native_settings.rs@@ -418,6 +418,30 @@ impl NativeCommandPaletteHotkey {}}+/// How long a link minted from the Web settings section lasts.+///+/// `None` is "until it is revoked". That is a real choice -- a link kept in+/// a password manager for a machine you reach every day should not expire+/// under you -- so it is offered rather than assumed away. The default is+/// still bounded, because the common case is handing a link to a phone for+/// an afternoon and never thinking about it again.+pub(crate) const DEFAULT_WEB_LINK_TTL_SECS: u64 = 8 * 60 * 60;++#[derive(Debug, Clone, Deserialize, Serialize)]+#[serde(default)]+pub(crate) struct NativeWebSettings {+ /// Seconds, or `None` for "until revoked".+ pub(crate) link_ttl_secs: Option<u64>,+}++impl Default for NativeWebSettings {+ fn default() -> Self {+ Self {+ link_ttl_secs: Some(DEFAULT_WEB_LINK_TTL_SECS),+ }+ }+}+#[derive(Debug, Clone, Deserialize, Serialize)]#[serde(default)]pub(crate) struct NativeCommandPaletteSettings {@@ -457,6 +481,7 @@ pub(crate) struct ThinkTermNativeSettings {pub(crate) window: NativeWindowSettings,pub(crate) workspaces: NativeWorkspaceSettings,pub(crate) command_palette: NativeCommandPaletteSettings,+ pub(crate) web: NativeWebSettings,}impl Default for ThinkTermNativeSettings {@@ -473,6 +498,7 @@ impl Default for ThinkTermNativeSettings {window: NativeWindowSettings::default(),workspaces: NativeWorkspaceSettings::default(),command_palette: NativeCommandPaletteSettings::default(),+ web: NativeWebSettings::default(),}}}diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rsindex 8aba3bb3..21903a85 100644--- a/wezterm-gui/src/settings_window.rs+++ b/wezterm-gui/src/settings_window.rs@@ -302,6 +302,7 @@ enum SettingsSection {Terminal,Workspaces,Agents,+ Web,Archived,Keymap,CommandPalette,@@ -320,6 +321,7 @@ const BASE_SECTIONS: &[SettingsSection] = &[SettingsSection::Terminal,SettingsSection::Workspaces,SettingsSection::Agents,+ SettingsSection::Web,SettingsSection::Archived,SettingsSection::Keymap,SettingsSection::CommandPalette,@@ -382,6 +384,7 @@ fn initial_section() -> SettingsSection {"terminal" => SettingsSection::Terminal,"workspaces" => SettingsSection::Workspaces,"agents" => SettingsSection::Agents,+ "web" => SettingsSection::Web,"archived" => SettingsSection::Archived,"keymap" => SettingsSection::Keymap,"commandpalette" => SettingsSection::CommandPalette,@@ -408,6 +411,7 @@ impl SettingsSection {Self::Terminal => crate::i18n::tr("settings-section-terminal"),Self::Workspaces => crate::i18n::tr("settings-section-workspaces"),Self::Agents => crate::i18n::tr("settings-section-agents"),+ Self::Web => crate::i18n::tr("settings-section-web"),Self::Archived => crate::i18n::tr("settings-section-archived"),Self::Keymap => crate::i18n::tr("settings-section-keymap"),Self::CommandPalette => crate::i18n::tr("settings-section-command-palette"),@@ -428,6 +432,7 @@ impl SettingsSection {Self::Terminal => SettingsIcon::Terminal,Self::Workspaces => SettingsIcon::Workspaces,Self::Agents => SettingsIcon::Agents,+ Self::Web => SettingsIcon::Web,Self::Archived => SettingsIcon::Archived,Self::Keymap => SettingsIcon::Keymap,Self::CommandPalette => SettingsIcon::CommandPalette,@@ -459,6 +464,18 @@ impl SettingsSection {"Window Position","Configuration",],+ Self::Web => &[+ "Web",+ "Browser",+ "Browser Access",+ "Remote",+ "Link",+ "Token",+ "Share",+ "HTTP",+ "Port",+ "Listener",+ ],Self::Appearance => &["Theme Mode","Effective Color Scheme",@@ -646,6 +663,45 @@ mod settings_search_tests {}}+/// What the expiry dropdown offers, shortest first.+///+/// `None` last, because it is the one with no bound and reading the list in+/// order should make that the deliberate end of a scale.+const WEB_LINK_TTL_CHOICES: &[Option<u64>] = &[+ Some(60 * 60),+ Some(8 * 60 * 60),+ Some(24 * 60 * 60),+ Some(7 * 24 * 60 * 60),+ None,+];++/// A lifetime as words: hours below a day, days above it, and "until+/// revoked" for no expiry at all.+fn web_link_ttl_label(ttl: Option<u64>) -> String {+ let Some(secs) = ttl else {+ return crate::i18n::tr("settings-web-ttl-never");+ };+ let mut args = FluentArgs::new();+ if secs < 24 * 60 * 60 {+ args.set("hours", (secs / 3600).max(1) as i64);+ crate::i18n::tr_args("settings-web-ttl-hours", &args)+ } else {+ args.set("days", (secs / (24 * 60 * 60)).max(1) as i64);+ crate::i18n::tr_args("settings-web-ttl-days", &args)+ }+}++/// When a browser link stops working, in the viewer's own time zone.+fn format_web_token_when(secs: u64) -> String {+ chrono::DateTime::<chrono::Utc>::from_timestamp(secs as i64, 0)+ .map(|when| {+ when.with_timezone(&chrono::Local)+ .format("%Y-%m-%d %H:%M")+ .to_string()+ })+ .unwrap_or_else(|| secs.to_string())+}+fn localized_theme_mode_label(mode: NativeThemeMode) -> String {crate::i18n::tr(match mode {NativeThemeMode::System => "settings-theme-system",@@ -706,6 +762,15 @@ fn settings_tr(id: &'static str, values: &[(&'static str, String)]) -> String {crate::i18n::tr_args(id, &args)}+/// A token id as something a `Copy` action can carry. Ids are random, so a+/// 64-bit hash of one is as good as the id for telling rows apart.+fn web_token_key(id: &str) -> u64 {+ use std::hash::{Hash, Hasher};+ let mut hasher = std::collections::hash_map::DefaultHasher::new();+ id.hash(&mut hasher);+ hasher.finish()+}+#[derive(Debug, Clone, Copy, PartialEq, Eq)]enum SettingsAction {WindowHide,@@ -731,6 +796,18 @@ enum SettingsAction {/// Index into the archived rows cached at paint time.UnarchiveArchivedRow(usize),DeleteArchivedRow(usize),+ ToggleWebServer,+ ToggleWebLinkTtlMenu,+ /// Seconds, or `None` for a link that lasts until it is revoked.+ SetWebLinkTtl(Option<u64>),+ /// Mint a link and put it straight on the clipboard.+ CopyWebLink,+ /// Index into the token rows cached at paint time.+ /// Carries `web_token_key(id)`, not the row's index: the press is+ /// remembered at mouse-down and compared by value with the action under+ /// the pointer at release, and the list can be refreshed in between.+ RevokeWebToken(u64),+ RevokeAllWebTokens,ToggleDeveloperMode,ToggleFallbackContextMenu,ShowOnboardingNow,@@ -822,6 +899,7 @@ enum SettingsDropdown {MainRenderer,DefaultShell,CommandPaletteHotkey,+ WebLinkTtl,}#[derive(Debug, Clone, Copy, PartialEq, Eq)]@@ -1239,6 +1317,10 @@ struct SettingsUiState {/// The archived rows as last painted; row-action indices resolve here/// so a click acts on exactly what the user saw.archived_rows: Vec<crate::workspace_threads::ArchivedProjectRow>,+ /// The browser links as last painted, for the same reason: a revoke+ /// must cut off the row that was under the pointer, not whichever row+ /// holds that index after the list refreshed.+ web_tokens: Vec<codec::WebTokenInfo>,/// The shells found on this machine. Refreshed when the Terminal/// section is entered, never while painting: discovery touches the/// filesystem, and the paint path must not.@@ -1294,6 +1376,7 @@ impl SettingsUiState {main_window_resource_lines: Vec::new(),memory_snapshot_copied_until: None,archived_rows: Vec::new(),+ web_tokens: Vec::new(),shell_catalog: Vec::new(),confirm_delete_archived: None,input_diagnostics_copied_until: None,@@ -2240,6 +2323,8 @@ impl SettingsWindow {| SettingsAction::SetDefaultShell(_)| SettingsAction::ToggleCommandPaletteHotkeyMenu| SettingsAction::SetCommandPaletteHotkey(_)+ | SettingsAction::ToggleWebLinkTtlMenu+ | SettingsAction::SetWebLinkTtl(_)| SettingsAction::DropdownMenuBackdrop,) => {self.set_focused_input(None);@@ -2479,6 +2564,10 @@ impl SettingsWindow {settings.ui.update_checked_until = None;window.invalidate();}+ if crate::web_settings::state().copied {+ crate::web_settings::clear_copied();+ window.invalidate();+ }if settings.ui.version_info_copied_until@@ -3837,6 +3926,56 @@ impl SettingsWindow {}}}+ SettingsAction::ToggleWebServer => {+ self.ui.open_dropdown = None;+ let state = crate::web_settings::state();+ let on = state+ .status+ .as_ref()+ .is_some_and(|status| !status.listening.is_empty());+ // Turning it on with nothing configured is the ordinary+ // case, so fall back to the same loopback address a bare+ // `web_servers = { {} }` would have produced.+ let address = state+ .status+ .as_ref()+ .and_then(|status| status.configured.first().cloned())+ .or_else(|| Some(config::WebServer::default().bind_address));+ crate::web_settings::set_enabled(window.clone(), !on, address);+ }+ SettingsAction::ToggleWebLinkTtlMenu => {+ self.ui.open_dropdown = if self.ui.open_dropdown == Some(SettingsDropdown::WebLinkTtl)+ {+ None+ } else {+ Some(SettingsDropdown::WebLinkTtl)+ };+ }+ SettingsAction::SetWebLinkTtl(ttl) => {+ self.native_settings.web.link_ttl_secs = ttl;+ self.ui.open_dropdown = None;+ self.save_web_settings();+ }+ SettingsAction::CopyWebLink => {+ self.ui.open_dropdown = None;+ crate::web_settings::mint(window.clone(), self.native_settings.web.link_ttl_secs);+ self.schedule_copied_state_clear(window);+ }+ SettingsAction::RevokeWebToken(key) => {+ self.ui.open_dropdown = None;+ if let Some(token) = self+ .ui+ .web_tokens+ .iter()+ .find(|token| web_token_key(&token.id) == key)+ {+ crate::web_settings::revoke(window.clone(), Some(token.id.clone()));+ }+ }+ SettingsAction::RevokeAllWebTokens => {+ self.ui.open_dropdown = None;+ crate::web_settings::revoke(window.clone(), None);+ }SettingsAction::ToggleDeveloperMode => {self.ui.open_dropdown = None;self.native_settings.developer.developer_mode =@@ -5106,6 +5245,7 @@ impl SettingsWindow {SettingsSection::Terminal => self.paint_terminal(layers, x, max_width)?,SettingsSection::Workspaces => self.paint_workspaces(layers, x, max_width)?,SettingsSection::Agents => self.paint_agents(layers, x, max_width)?,+ SettingsSection::Web => self.paint_web(layers, x, max_width)?,SettingsSection::Archived => self.paint_archived(layers, x, max_width)?,SettingsSection::Keymap => self.paint_placeholder(layers,@@ -5464,6 +5604,315 @@ impl SettingsWindow {Ok(())}+ /// Browser access: whether the mux server is accepting browser clients,+ /// and the links that let one in.+ ///+ /// Two cards, because they answer different questions: the first is a+ /// switch and its state, the second is a list of credentials that+ /// outlive any one session. Putting a revoke button in the same card as+ /// the on/off switch read as though it were part of turning it off.+ ///+ /// Everything here is the *server's* state, not this window's, so it is+ /// read over the mux client and cached in `web_settings`; painting only+ /// ever reads that cache.+ fn paint_web(+ &mut self,+ layers: &mut TripleLayerQuadAllocator<'_>,+ x: f32,+ max_width: f32,+ ) -> anyhow::Result<()> {+ let palette = self.palette();+ let ui_font = Rc::clone(&self.ui_font);+ let body_font = Rc::clone(&self.body_font);+ let scroll = self.ui.content_scroll.offset;+ let section_y = self.ui_px(CONTENT_SECTION_Y) - scroll;++ let state = crate::web_settings::state();+ // Asked here rather than in `enter_section`, which has no window to+ // wake when the answer lands. One request: `refresh` refuses to+ // start a second while one is out.+ if let Some(window) = self.window.clone() {+ // The first read, and then every couple of seconds for as long+ // as this section is the one on screen: the live-connection+ // count is the server's news, not this window's, so nothing+ // else would ever bring it up to date.+ if !state.loaded || crate::web_settings::poll_is_due() {+ crate::web_settings::refresh(window.clone());+ }+ crate::web_settings::arm_poll(window);+ }+ let listening = state+ .status+ .as_ref()+ .is_some_and(|status| !status.listening.is_empty());+ let address = state+ .status+ .as_ref()+ .and_then(|status| status.listening.first().cloned());++ // Snapshotted for the row actions, exactly as the archived rows are.+ self.ui.web_tokens = state.tokens.clone();++ let padding = 36.0;+ let row_x = x + padding;+ let row_width = max_width - padding * 2.0;+ let row_step = self.settings_row_step();++ // --- the switch -------------------------------------------------+ self.draw_text(+ layers,+ &body_font,+ x,+ section_y,+ &crate::i18n::tr("settings-web-heading"),+ palette.muted_text,+ max_width,+ )?;+ let (card_y, first_row_y) = self.settings_card_geometry(section_y, 3);+ let card_height = self.settings_card_height(3);+ self.paint_group_card(layers, x, card_y, max_width, card_height)?;++ // The error takes the description slot rather than a line of its+ // own: it is always about the thing the toggle just tried to do,+ // and a row that appears and disappears moves everything below it.+ let description = match (&state.error, &address) {+ (Some(error), _) => error.clone(),+ (None, Some(address)) => {+ let mut args = FluentArgs::new();+ args.set("address", address.clone());+ crate::i18n::tr_args("settings-web-on-at", &args)+ }+ (None, None) => crate::i18n::tr("settings-web-enable-description"),+ };+ self.paint_toggle_setting_row(+ layers,+ row_x,+ first_row_y,+ row_width,+ &crate::i18n::tr("settings-web-enable"),+ &description,+ listening,+ SettingsAction::ToggleWebServer,+ false,+ )?;++ let ttl_y = first_row_y + row_step;+ self.paint_web_link_ttl_row(layers, row_x, ttl_y, row_width, true)?;++ let copy_y = first_row_y + row_step * 2.0;+ self.paint_separator(layers, row_x, copy_y - self.ui_px(28.0), row_width)?;+ let copy_label = if state.copied {+ crate::i18n::tr("settings-web-copied")+ } else {+ crate::i18n::tr("settings-web-copy")+ };+ let copy_width = self.button_width_for_label(©_label, 190.0);+ let copy_x = row_x + row_width - copy_width;+ let copy_text_width = copy_x - row_x - self.ui_px(24.0);+ self.draw_text(+ layers,+ &ui_font,+ row_x,+ copy_y,+ &crate::i18n::tr("settings-web-link"),+ palette.text,+ copy_text_width,+ )?;+ self.draw_text(+ layers,+ &body_font,+ row_x,+ self.settings_row_description_y(copy_y),+ &crate::i18n::tr("settings-web-link-description"),+ palette.secondary_text,+ copy_text_width,+ )?;+ self.draw_button(+ layers,+ copy_x,+ copy_y + self.ui_px(4.0),+ copy_width,+ ©_label,+ SettingsAction::CopyWebLink,+ )?;++ // --- the links --------------------------------------------------+ // One extra row for "every link" only when there is more than+ // nothing to revoke; an empty list gets the placeholder row alone.+ let link_rows = state.tokens.len().max(1) + usize::from(!state.tokens.is_empty());+ let links_title_y = card_y + card_height + self.settings_section_card_gap();+ let links_card_y = links_title_y + self.settings_section_card_gap().min(54.0);+ let links_first_row_y = links_card_y + self.settings_card_top_padding();+ let links_card_height = self.settings_card_height(link_rows);+ self.ui.content_scroll.set_extents(+ self.content_viewport_extent(),+ self.settings_content_extent(links_card_y + scroll + links_card_height),+ );+ self.draw_text(+ layers,+ &body_font,+ x,+ links_title_y,+ &crate::i18n::tr("settings-web-links-heading"),+ palette.muted_text,+ max_width,+ )?;+ self.paint_group_card(layers, x, links_card_y, max_width, links_card_height)?;++ let icon_gap = self.ui_px(12.0);+ let tile_for = |window: &Self, y: f32| {+ window.settings_row_description_y(y) - y + window.metrics.cell_size.height as f32+ };++ if state.tokens.is_empty() {+ let y = links_first_row_y;+ let tile = tile_for(self, y);+ self.draw_rounded_frame(+ layers,+ 0,+ row_x,+ y,+ tile,+ tile,+ palette.control_bg,+ palette.rule,+ self.ui_px(8.0),+ )?;+ let mark = tile * 0.62;+ self.draw_svg_icon(+ layers,+ SvgIcon::Globe,+ row_x + (tile - mark) / 2.0,+ y + (tile - mark) / 2.0,+ mark,+ palette.muted_text,+ )?;+ self.draw_text(+ layers,+ &body_font,+ row_x + tile + icon_gap,+ y,+ &crate::i18n::tr("settings-web-tokens-empty"),+ palette.muted_text,+ row_width - tile - icon_gap,+ )?;+ return Ok(());+ }++ let revoke_label = crate::i18n::tr("settings-web-revoke");+ let revoke_width = self.button_width_for_label(&revoke_label, 0.0);+ for (index, token) in state.tokens.iter().enumerate() {+ let y = links_first_row_y + row_step * index as f32;+ if index > 0 {+ self.paint_separator(layers, row_x, y - self.ui_px(28.0), row_width)?;+ }+ let controls_x = row_x + row_width - revoke_width;+ let tile = tile_for(self, y);+ self.draw_rounded_frame(+ layers,+ 0,+ row_x,+ y,+ tile,+ tile,+ palette.control_bg,+ palette.rule,+ self.ui_px(8.0),+ )?;+ let mark = tile * 0.62;+ self.draw_svg_icon(+ layers,+ SvgIcon::Globe,+ row_x + (tile - mark) / 2.0,+ y + (tile - mark) / 2.0,+ mark,+ palette.text,+ )?;+ let text_x = row_x + tile + icon_gap;+ let text_width = (controls_x - text_x - self.ui_px(24.0)).max(row_width * 0.3);+ // What this link is, in order of how much it actually tells+ // you: the name a person gave it, then what the browser that+ // used it said it was, then the honest admission that nobody+ // has used it yet. The label used to be stamped "Settings" for+ // every link minted here, so the list was a column of identical+ // rows -- a name that names nothing is worse than no name.+ let headline = token+ .label+ .clone()+ .or_else(|| token.last_device.clone())+ .unwrap_or_else(|| crate::i18n::tr("settings-web-token-unused"));+ self.draw_text(+ layers,+ &ui_font,+ text_x,+ y,+ &headline,+ palette.text,+ text_width,+ )?;+ let mut args = FluentArgs::new();+ args.set(+ "expires",+ match token.expires_at {+ Some(at) => format_web_token_when(at),+ None => crate::i18n::tr("settings-web-token-never"),+ },+ );+ args.set("connections", token.live_connections as i64);+ self.draw_text(+ layers,+ &body_font,+ text_x,+ self.settings_row_description_y(y),+ &crate::i18n::tr_args("settings-web-token-meta", &args),+ palette.secondary_text,+ text_width,+ )?;+ self.draw_button(+ layers,+ controls_x,+ y + (tile - self.ui_px(CONTROL_HEIGHT)) / 2.0,+ revoke_width,+ &revoke_label,+ SettingsAction::RevokeWebToken(web_token_key(&token.id)),+ )?;+ }++ let all_y = links_first_row_y + row_step * state.tokens.len() as f32;+ self.paint_separator(layers, row_x, all_y - self.ui_px(28.0), row_width)?;+ let all_label = crate::i18n::tr("settings-web-revoke-all");+ let all_width = self.button_width_for_label(&all_label, 190.0);+ let all_x = row_x + row_width - all_width;+ let all_text_width = all_x - row_x - self.ui_px(24.0);+ self.draw_text(+ layers,+ &ui_font,+ row_x,+ all_y,+ &crate::i18n::tr("settings-web-revoke-all-label"),+ palette.text,+ all_text_width,+ )?;+ self.draw_text(+ layers,+ &body_font,+ row_x,+ self.settings_row_description_y(all_y),+ &crate::i18n::tr("settings-web-revoke-all-description"),+ palette.secondary_text,+ all_text_width,+ )?;+ self.draw_button(+ layers,+ all_x,+ all_y + self.ui_px(4.0),+ all_width,+ &all_label,+ SettingsAction::RevokeAllWebTokens,+ )?;+ Ok(())+ }+fn paint_archived(&mut self,layers: &mut TripleLayerQuadAllocator<'_>,@@ -5886,6 +6335,17 @@ impl SettingsWindow {self.save_command_palette_settings();}+ /// The same merge-then-write dance as the palette's: another window+ /// may have written a different group while Settings was open.+ fn save_web_settings(&mut self) {+ let mut merged = crate::native_settings::load();+ merged.web = self.native_settings.web.clone();+ self.native_settings = merged;+ if let Err(err) = crate::native_settings::save(&self.native_settings) {+ log::error!("failed to save the browser link expiry: {err:#}");+ }+ }+fn save_command_palette_settings(&mut self) {// Merge into the freshest cached settings instead of writing this// window's whole clone: the palette writes appearance.color_scheme@@ -8980,6 +9440,122 @@ impl SettingsWindow {Ok(())}+ /// How long the next link lasts. A dropdown rather than a fixed value+ /// because both ends are legitimate: an afternoon on a borrowed phone,+ /// and a link in a password manager for a machine reached every day.+ fn paint_web_link_ttl_row(+ &mut self,+ layers: &mut TripleLayerQuadAllocator<'_>,+ x: f32,+ y: f32,+ width: f32,+ draw_top_rule: bool,+ ) -> anyhow::Result<()> {+ let palette = self.palette();+ let ui_font = Rc::clone(&self.ui_font);+ let body_font = Rc::clone(&self.body_font);+ if draw_top_rule {+ self.paint_separator(layers, x, y - self.ui_px(28.0), width)?;+ }++ let (control_x, control_y, control_width) = self.dropdown_control_geometry(x, y, width);+ let text_width = (control_x - x - 24.0).max(width * 0.45);+ let action = SettingsAction::ToggleWebLinkTtlMenu;+ let control_rect = rect(+ control_x,+ control_y,+ control_width,+ self.ui_px(CONTROL_HEIGHT),+ );+ let open = self.ui.open_dropdown == Some(SettingsDropdown::WebLinkTtl);+ let hovered = self.ui.interaction.hovered == Some(action);+ let pressed = self.ui.interaction.pressed == Some(action);+ let bg = if pressed || hovered {+ palette.control_hover_bg+ } else {+ palette.control_bg+ };+ let border = if open {+ palette.nav_selected_bg+ } else if hovered || pressed {+ palette.separator+ } else {+ palette.control_border+ };++ self.ui_context+ .push(control_rect, WidgetKind::Button, action);+ self.draw_text(+ layers,+ &ui_font,+ x,+ y,+ &crate::i18n::tr("settings-web-ttl"),+ palette.text,+ text_width,+ )?;+ self.draw_text(+ layers,+ &body_font,+ x,+ self.settings_row_description_y(y),+ &crate::i18n::tr("settings-web-ttl-description"),+ palette.secondary_text,+ text_width,+ )?;+ self.draw_rounded_frame(+ layers,+ 0,+ control_rect.origin.x,+ control_rect.origin.y,+ control_rect.size.width,+ control_rect.size.height,+ bg,+ border,+ self.ui_px(CONTROL_RADIUS),+ )?;+ self.draw_text(+ layers,+ &ui_font,+ control_x + self.ui_px(16.0),+ self.control_text_y(control_y, self.ui_px(CONTROL_HEIGHT)),+ &web_link_ttl_label(self.native_settings.web.link_ttl_secs),+ palette.text,+ control_width - self.ui_px(60.0),+ )?;+ self.draw_svg_icon(+ layers,+ SvgIcon::ChevronDown,+ control_x + control_width - self.ui_px(38.0),+ control_y + (self.ui_px(CONTROL_HEIGHT) - 22.0) / 2.0,+ self.ui_px(22.0),+ palette.secondary_text,+ )?;+ Ok(())+ }++ fn paint_web_link_ttl_menu(+ &mut self,+ layers: &mut TripleLayerQuadAllocator<'_>,+ x: f32,+ y: f32,+ width: f32,+ ) -> anyhow::Result<()> {+ let current = self.native_settings.web.link_ttl_secs;+ let options: Vec<(String, SettingsAction, bool)> = WEB_LINK_TTL_CHOICES+ .iter()+ .copied()+ .map(|ttl| {+ (+ web_link_ttl_label(ttl),+ SettingsAction::SetWebLinkTtl(ttl),+ current == ttl,+ )+ })+ .collect();+ self.paint_dropdown_menu(layers, x, y, width, &options)+ }+fn paint_command_palette_hotkey_row(&mut self,layers: &mut TripleLayerQuadAllocator<'_>,@@ -9733,6 +10309,7 @@ impl SettingsWindow {SettingsSection::Appearance => 4,SettingsSection::Terminal => 9,SettingsSection::CommandPalette => 4,+ SettingsSection::Web => 3,_ => 4,};let (_, first_row_y) = self.settings_card_geometry(section_y, row_count);@@ -9747,7 +10324,8 @@ impl SettingsWindow {SettingsDropdown::AppIcon => first_row_y + self.settings_row_step(),SettingsDropdown::MainRenderer| SettingsDropdown::DefaultShell- | SettingsDropdown::CommandPaletteHotkey => return Ok(()),+ | SettingsDropdown::CommandPaletteHotkey+ | SettingsDropdown::WebLinkTtl => return Ok(()),};(x + card_padding, row_y, max_width - card_padding * 2.0)}@@ -9758,7 +10336,8 @@ impl SettingsWindow {SettingsDropdown::MainRenderer => first_row_y + self.settings_row_step() * 4.0,SettingsDropdown::AppIcon| SettingsDropdown::DefaultShell- | SettingsDropdown::CommandPaletteHotkey => return Ok(()),+ | SettingsDropdown::CommandPaletteHotkey+ | SettingsDropdown::WebLinkTtl => return Ok(()),};(x + card_padding, row_y, max_width - card_padding * 2.0)}@@ -9771,7 +10350,8 @@ impl SettingsWindow {| SettingsDropdown::ThemeMode| SettingsDropdown::AppIcon| SettingsDropdown::MainRenderer- | SettingsDropdown::CommandPaletteHotkey => return Ok(()),+ | SettingsDropdown::CommandPaletteHotkey+ | SettingsDropdown::WebLinkTtl => return Ok(()),};(x + card_padding, row_y, max_width - card_padding * 2.0)}@@ -9783,6 +10363,14 @@ impl SettingsWindow {};(x + card_padding, row_y, max_width - card_padding * 2.0)}+ SettingsSection::Web => {+ let row_y = match dropdown {+ // Second row of the first card; see `paint_web`.+ SettingsDropdown::WebLinkTtl => first_row_y + self.settings_row_step(),+ _ => return Ok(()),+ };+ (x + card_padding, row_y, max_width - card_padding * 2.0)+ }_ => return Ok(()),};let (control_x, control_y, control_width) =@@ -9824,6 +10412,12 @@ impl SettingsWindow {control_y + self.ui_px(CONTROL_HEIGHT) + 8.0,control_width,),+ SettingsDropdown::WebLinkTtl => self.paint_web_link_ttl_menu(+ layers,+ control_x,+ control_y + self.ui_px(CONTROL_HEIGHT) + 8.0,+ control_width,+ ),}}diff --git a/wezterm-gui/src/ui/icons.rs b/wezterm-gui/src/ui/icons.rsindex 35ae056b..c49d29cf 100644--- a/wezterm-gui/src/ui/icons.rs+++ b/wezterm-gui/src/ui/icons.rs@@ -16,6 +16,7 @@ pub(crate) enum SettingsIcon {Update,About,Archived,+ Web,CommandPalette,Search,Clear,@@ -39,6 +40,7 @@ impl SettingsIcon {Self::Update => SvgIcon::RefreshCw,Self::About => SvgIcon::Info,Self::Archived => SvgIcon::Archive,+ Self::Web => SvgIcon::Globe,Self::CommandPalette => SvgIcon::SquareTerminal,Self::Search => SvgIcon::Search,Self::Clear => SvgIcon::X,diff --git a/wezterm-gui/src/web_settings.rs b/wezterm-gui/src/web_settings.rsnew file mode 100644index 00000000..d0603a0c--- /dev/null+++ b/wezterm-gui/src/web_settings.rs@@ -0,0 +1,357 @@+//! What the Web settings section knows, and how it asks the mux server.+//!+//! The settings window paints synchronously; the mux server answers over an+//! async client. So every answer lands in this cache first and the next+//! paint reads it, the way the update section reads its own cache rather+//! than blocking the UI thread on an HTTP request.+//!+//! One cache for the process: there is one mux connection, and a second+//! settings window would be asking the same server the same questions.++use codec::{WebServerStatus, WebTokenInfo};+use mux::Mux;+use std::sync::Mutex;+use std::time::{Duration, Instant};+use wezterm_client::client::Client;+use wezterm_client::domain::ClientDomain;+use window::{Clipboard, Window, WindowOps};++#[derive(Default, Clone)]+pub struct WebState {+ pub status: Option<WebServerStatus>,+ pub tokens: Vec<WebTokenInfo>,+ /// The last failure, shown until an answer replaces it.+ pub error: Option<String>,+ /// A user's request is out. Controls stay where they are rather than+ /// jumping between "on" and "off" while the answer is in flight.+ pub busy: bool,+ /// The background poll's own gate. Separate from `busy` because they+ /// mean different things: a poll in flight must never be a reason to+ /// drop a click, and a click must never wait for a poll.+ pub polling: bool,+ /// A link was just put on the clipboard. The URL itself is not kept:+ /// it carries a live token, and nothing here needs to read it back.+ pub copied: bool,+ /// Whether anything has been asked yet, so the first paint of the+ /// section can ask without a button.+ pub loaded: bool,+ /// When the last answer landed, so the page can go and ask again.+ pub refreshed_at: Option<Instant>,+ /// A wake-up is already scheduled; a second would double the rate+ /// every time the window repainted for an unrelated reason.+ pub poll_armed: bool,+ /// Bumped by every user action that lands. A poll that was already in+ /// flight when it did carries a picture from before the click, and is+ /// thrown away rather than painted over the result.+ pub generation: u64,+}++/// How often the open page re-reads the server.+///+/// "Is anyone looking at my terminal right now" is the question this page+/// exists to answer, and an answer that only updates when you leave and+/// come back is not one. Two seconds is slow enough to be invisible in+/// cost -- two small RPCs on an already-open connection -- and fast enough+/// that plugging in a phone shows up while you are still holding it.+pub const POLL_INTERVAL: Duration = Duration::from_secs(2);++static STATE: Mutex<Option<WebState>> = Mutex::new(None);++fn with_state<R>(f: impl FnOnce(&mut WebState) -> R) -> R {+ let mut guard = STATE.lock().unwrap_or_else(|e| e.into_inner());+ f(guard.get_or_insert_with(WebState::default))+}++pub fn state() -> WebState {+ with_state(|s| s.clone())+}++/// Forget everything, so reopening the section asks again rather than+/// showing what was true before the server was restarted.+pub fn reset() {+ *STATE.lock().unwrap_or_else(|e| e.into_inner()) = None;+}++/// The mux client, if this GUI has one. A GUI with only local panes and no+/// mux server has nothing to ask, and the section says so.+fn client() -> Option<Client> {+ for domain in Mux::get().iter_domains() {+ let is_client = domain.downcast_ref::<ClientDomain>().is_some();+ log::debug!(+ "web settings: domain {} ({}) client={is_client}",+ domain.domain_id(),+ domain.domain_name()+ );+ if is_client {+ match ClientDomain::get_client_inner_for_domain(domain.domain_id()) {+ Ok(inner) => return Some(inner.client.clone()),+ Err(err) => log::debug!("web settings: domain has no live client: {err:#}"),+ }+ }+ }+ None+}++/// Which gate an answer releases. They are separate on purpose: a poll+/// finishing must not release a user's action that is still out (a+/// "Copy link" could then be clicked twice and mint two tokens), and an+/// action finishing must not release a poll.+#[derive(Clone, Copy)]+enum Gate {+ Poll,+ Action,+}++fn finish(window: &Window, error: Option<String>, gate: Gate) {+ with_state(|s| {+ match gate {+ Gate::Poll => s.polling = false,+ Gate::Action => {+ s.busy = false;+ s.generation += 1;+ }+ }+ s.loaded = true;+ s.refreshed_at = Some(Instant::now());+ // A quiet poll does not clear what an action just said went wrong:+ // "the listener refused to start because ..." has to outlive the+ // next two-second tick, or it is never read.+ match (gate, error) {+ (Gate::Poll, None) => {}+ (_, error) => s.error = error,+ }+ });+ window.invalidate();+}++/// Whether enough time has passed to ask the server again.+pub fn poll_is_due() -> bool {+ with_state(|s| {+ !s.busy+ && !s.polling+ && s.refreshed_at+ .is_none_or(|at| at.elapsed() >= POLL_INTERVAL)+ })+}++/// Come back and repaint once the poll is due.+///+/// The page has nothing else to make it repaint -- a browser connecting is+/// news from the server, not from this window -- so the timer is what turns+/// a static page into a live one. Armed from the Web section's paint and+/// nowhere else, so leaving the section stops it after one last tick.+pub fn arm_poll(window: Window) {+ // Wait only for the time still owed. Sleeping a whole interval here and+ // then finding the poll due meant the pair took two intervals: a "2+ // second" refresh that actually ran every four, with every other wake+ // painting an identical frame.+ //+ // Nothing is armed while a request is out: `refreshed_at` is then the+ // *previous* answer's time, the wait owed reads as zero, and the window+ // would wake, paint, find the poll not due, and arm again at display+ // rate for as long as the request took. `finish` repaints when the+ // answer lands, and that paint arms the next wait.+ let due_in = with_state(|s| {+ if s.busy || s.polling || std::mem::replace(&mut s.poll_armed, true) {+ return None;+ }+ Some(+ s.refreshed_at+ .map(|at| POLL_INTERVAL.saturating_sub(at.elapsed()))+ .unwrap_or(POLL_INTERVAL),+ )+ });+ let Some(due_in) = due_in else {+ return;+ };+ promise::spawn::spawn_into_main_thread(async move {+ smol::Timer::after(due_in).await;+ with_state(|s| s.poll_armed = false);+ window.invalidate();+ })+ .detach();+}++/// Read the listener's state and the token list.+///+/// Both in one task: two answers arriving separately would paint a frame+/// where the listener is on and the tokens are still the old ones.+pub fn refresh(window: Window) {+ // The poll's gate, not the user's: a click that lands while a refresh+ // is in flight still goes through, and a refresh that never answers+ // does not lock the page.+ if with_state(|s| std::mem::replace(&mut s.polling, true)) {+ return;+ }+ let Some(client) = client() else {+ with_state(|s| {+ s.status = None;+ s.tokens.clear();+ });+ finish(&window, Some(crate::i18n::tr("settings-web-no-server")), Gate::Poll);+ return;+ };+ let asked_at = with_state(|s| s.generation);+ promise::spawn::spawn_into_main_thread(async move {+ let outcome = async {+ let status = client.get_web_server_status().await?;+ let tokens = client.web_token_list().await?;+ Ok::<_, anyhow::Error>((status, tokens.tokens))+ }+ .await;+ // An action landed while this was out. Its answer is the newer+ // truth and this one would paint the switch back the way it was;+ // ask again instead, now that the poll gate is free.+ if with_state(|s| s.generation) != asked_at {+ finish(&window, None, Gate::Poll);+ refresh(window);+ return;+ }+ match outcome {+ Ok((status, tokens)) => {+ log::debug!(+ "web settings: listening={:?} configured={:?} tokens={}",+ status.listening,+ status.configured,+ tokens.len()+ );+ with_state(|s| {+ s.status = Some(status);+ s.tokens = tokens;+ });+ finish(&window, None, Gate::Poll);+ }+ Err(err) => finish(&window, Some(format!("{err:#}")), Gate::Poll),+ }+ })+ .detach();+}++/// Turn the listener on or off, then re-read: the answer to `SetWebServer`+/// is the new status, but the token list can change with it (a listener+/// that has just come up configures the token store).+pub fn set_enabled(window: Window, enabled: bool, bind_address: Option<String>) {+ if with_state(|s| std::mem::replace(&mut s.busy, true)) {+ return;+ }+ let Some(client) = client() else {+ finish(&window, Some(crate::i18n::tr("settings-web-no-server")), Gate::Action);+ return;+ };+ promise::spawn::spawn_into_main_thread(async move {+ match client+ .set_web_server(codec::SetWebServer {+ enabled,+ bind_address,+ })+ .await+ {+ Ok(status) => {+ with_state(|s| s.status = Some(status));+ finish(&window, None, Gate::Action);+ refresh(window);+ }+ Err(err) => finish(&window, Some(format!("{err:#}")), Gate::Action),+ }+ })+ .detach();+}++/// Mint a link and put it on the clipboard.+///+/// Straight to the clipboard rather than onto the screen: a token on screen+/// is a token in every screenshot and screen share of this window.+///+/// `ttl_secs` is `None` for a link that lasts until it is revoked; the+/// section's dropdown chooses it and the server takes it at face value.+pub fn mint(window: Window, ttl_secs: Option<u64>) {+ if with_state(|s| std::mem::replace(&mut s.busy, true)) {+ return;+ }+ let Some(client) = client() else {+ finish(&window, Some(crate::i18n::tr("settings-web-no-server")), Gate::Action);+ return;+ };+ promise::spawn::spawn_into_main_thread(async move {+ match client+ .web_token_mint(codec::WebTokenMint {+ // Deliberately unnamed. There is nothing true to call it+ // yet -- the browser that will use it has not connected --+ // and a constant like "Settings" made every row in the list+ // identical. The row names itself from the device once one+ // turns up.+ label: None,+ ttl_secs,+ })+ .await+ {+ Ok(minted) => match minted.urls.first() {+ Some(url) => {+ window.set_clipboard(Clipboard::Clipboard, url.clone());+ with_state(|s| s.copied = true);+ finish(&window, None, Gate::Action);+ // The flash clears itself. The settings window schedules+ // its other copy-button timers when the click happens,+ // but this flag is set when the *answer* lands -- often+ // after that timer has already fired, which left the+ // button reading "Copied" on every later visit.+ clear_copied_soon(window.clone());+ refresh(window);+ }+ None => {+ // No listener, so no URL. Leaving the token alive would+ // be a credential nobody can see and nobody revokes.+ let _ = client+ .web_token_revoke(codec::WebTokenRevoke {+ id: Some(minted.id.clone()),+ })+ .await;+ finish(&window, Some(crate::i18n::tr("settings-web-no-listener")), Gate::Action);+ }+ },+ Err(err) => finish(&window, Some(format!("{err:#}")), Gate::Action),+ }+ })+ .detach();+}++/// Revoke one token, or every token when `id` is None.+pub fn revoke(window: Window, id: Option<String>) {+ if with_state(|s| std::mem::replace(&mut s.busy, true)) {+ return;+ }+ let Some(client) = client() else {+ finish(&window, Some(crate::i18n::tr("settings-web-no-server")), Gate::Action);+ return;+ };+ promise::spawn::spawn_into_main_thread(async move {+ match client.web_token_revoke(codec::WebTokenRevoke { id }).await {+ Ok(_) => {+ finish(&window, None, Gate::Action);+ refresh(window);+ }+ Err(err) => finish(&window, Some(format!("{err:#}")), Gate::Action),+ }+ })+ .detach();+}++/// Clear the "copied" flash. The window schedules this the way it does for+/// the other copy buttons.+pub fn clear_copied() {+ with_state(|s| s.copied = false);+}++/// How long "Copied" stays up. The same beat as the settings window's other+/// copy buttons.+const COPIED_FLASH: Duration = Duration::from_millis(1450);++/// Take the flash down again, counted from when it went up.+fn clear_copied_soon(window: Window) {+ promise::spawn::spawn_into_main_thread(async move {+ smol::Timer::after(COPIED_FLASH).await;+ clear_copied();+ window.invalidate();+ })+ .detach();+}