All your machines, one app. For you and your AI agents: agent sessions, desktops, files, logs and GitHub across your Macs, Linux and Windows machines, with an MCP server.
Update check, our own window frame on Wayland, and a better GitHub page
Adib Hannab00fb401f1ed
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.ymlnew file mode 100644index 0000000..d1988fb--- /dev/null+++ b/.github/ISSUE_TEMPLATE/bug_report.yml@@ -0,0 +1,50 @@+name: Bug report+description: Something in Muxin doesn't work as it should.+labels: [bug]+body:+ - type: markdown+ attributes:+ value: Thanks for reporting it. The more we know, the sooner it's fixed.+ - type: textarea+ id: what+ attributes:+ label: What happened+ description: What you did, what you expected, and what happened instead.+ validations:+ required: true+ - type: input+ id: version+ attributes:+ label: Muxin version+ description: On the About page, or from `muxin --version`.+ placeholder: "0.5.3"+ validations:+ required: true+ - type: dropdown+ id: platform+ attributes:+ label: Muxin runs on+ options:+ - macOS, Apple silicon+ - macOS, Intel+ - Linux, x86_64+ - Linux, arm64+ - Windows, x64+ - Windows, Arm+ validations:+ required: true+ - type: input+ id: installed+ attributes:+ label: Installed with+ placeholder: The DMG, Homebrew, the .deb, the .rpm, the AUR, the AppImage, the Windows installer…+ - type: textarea+ id: machines+ attributes:+ label: The machines it's about+ description: Their systems (macOS 26, Ubuntu 24.04, Windows 11…) and how Muxin reaches them (local network, Tailscale, a jump host), if it's about a machine.+ - type: textarea+ id: logs+ attributes:+ label: Logs or screenshots+ description: Anything that helps. Leave out hostnames, addresses or tokens you'd rather not share.diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.ymlnew file mode 100644index 0000000..d9c5492--- /dev/null+++ b/.github/ISSUE_TEMPLATE/config.yml@@ -0,0 +1,8 @@+blank_issues_enabled: false+contact_links:+ - name: Questions+ url: https://github.com/LumaryLabsLLC/muxin/discussions+ about: Ask how to do something in Discussions.+ - name: A security problem+ url: https://github.com/LumaryLabsLLC/muxin/security/policy+ about: Please report security problems privately.diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.ymlnew file mode 100644index 0000000..ae29852--- /dev/null+++ b/.github/ISSUE_TEMPLATE/feature_request.yml@@ -0,0 +1,16 @@+name: Idea+description: Something Muxin could do, or do better.+labels: [enhancement]+body:+ - type: textarea+ id: idea+ attributes:+ label: What you'd like+ description: What you want to do, and what gets in the way today.+ validations:+ required: true+ - type: textarea+ id: why+ attributes:+ label: Why it matters to you+ description: "The work it's for: your machines, your agents, your team."diff --git a/AGENTS.md b/AGENTS.mdindex 8512b19..fabddaf 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -206,6 +206,10 @@ The CLI equivalents are `muxin schedule ls|add|rm|run|log`.- The CLI equivalents are `muxin files <machine>:<folder>` and `muxin cp <machine>:<path>... <machine>:<folder>`.- Text copied on the user's Mac is shared with machines that have a desktop, and back, when the user has that on (Settings › Clipboard). Don't rely on it to move data; use `copy_files`.+## Muxin itself++- `muxin updates` (`--json`) says whether a newer Muxin is out and how to update this copy: a command (Homebrew, the AUR) or the file to download. Read-only; installing is the user's call.+## Don'ts- Don't edit `config.toml` or `state.json` by hand while the tools can do it.diff --git a/README.md b/README.mdindex 1dfd794..374401a 100644--- a/README.md+++ b/README.md@@ -7,6 +7,11 @@<p align="center">One app for all your machines, run by you <b>or by your AI agents</b>.<br><a href="https://muxin.dev">muxin.dev</a> · free and open source (Apache-2.0)</p>+<picture>+ <source media="(prefers-color-scheme: dark)" srcset="assets/readme/overview-dark.webp">+ <img src="assets/readme/overview-light.webp" alt="Muxin's overview: each machine, what's running on it, its CPU, memory and disk, and what needs a look.">+</picture>+Point it at the machines you own (a Mac Studio under the desk, a NUC, a Linux box, a few MacBooks, a Windows laptop) and Muxin becomes the hub for all of them:- **Agent sessions:** Claude Code, Codex, OpenCode, Gemini CLI, Amp, Pi or a shell on any machine, in a real terminal, still running after you close the app.@@ -43,6 +48,8 @@ brew install --cask lumarylabsllc/tap/muxin`SHA256SUMS.txt` in each release has the files' checksums.+Muxin tells you when a new version is out: the sidebar says so, and About shows how to update the copy you have (with Homebrew or the AUR, or the new file to download). It asks GitHub for the latest release when it opens and twice a day; turn that off in **Settings › General › Updates**. `muxin updates` checks from a terminal.+Muxin was called Muxen before 0.5.1. Updating keeps your settings, machines and sessions, and the `muxen` command still works. On a Mac, the old Muxen app goes to the Trash the first time Muxin opens.### Build from sourcediff --git a/assets/readme/overview-dark.webp b/assets/readme/overview-dark.webpnew file mode 100644index 0000000..c315104Binary files /dev/null and b/assets/readme/overview-dark.webp differdiff --git a/assets/readme/overview-light.webp b/assets/readme/overview-light.webpnew file mode 100644index 0000000..dc05869Binary files /dev/null and b/assets/readme/overview-light.webp differdiff --git a/src/config.rs b/src/config.rsindex 8e871d0..29838d1 100644--- a/src/config.rs+++ b/src/config.rs@@ -536,6 +536,8 @@ pub struct Settings {pub favorite_repos: Vec<String>,/// Text copied here can be pasted on the machines (Linux desktops, Macs), and back.pub share_clipboard: bool,+ /// Ask GitHub now and then whether a newer Muxin is out (see crate::update).+ pub check_updates: bool,/// The editor machines' folders open in: "zed", "cursor", "vscode", or "" for the first one installed.pub editor: String,/// Cloud machines: how Muxin signs in, what new ones come with, what happens when they sit idle.@@ -607,6 +609,7 @@ impl Default for Settings {code_folders: default_code_folders(),favorite_repos: Vec::new(),share_clipboard: true,+ check_updates: true,editor: String::new(),cloud: CloudSettings::default(),prompts: Default::default(),diff --git a/src/main.rs b/src/main.rsindex f1a59aa..88fde5c 100644--- a/src/main.rs+++ b/src/main.rs@@ -11,6 +11,7 @@ mod probe;#[cfg(feature = "gui")]mod renamed;mod shell_command;+mod update;#[cfg(feature = "gui")]mod ui;mod util;@@ -145,6 +146,15 @@ enum Command {/// Put `muxin` in your PATH (macOS: /usr/local/bin, Linux: ~/.local/bin,/// Windows: this folder in your user PATH), or take it outShellCommand(ShellCommandArgs),+ /// Whether a newer Muxin is out, and how to update this copy+ Updates(UpdatesArgs),+}++#[derive(Args)]+struct UpdatesArgs {+ /// Print machine-readable JSON+ #[arg(long)]+ json: bool,}#[derive(Args)]@@ -1622,6 +1632,37 @@ fn main() -> ExitCode {println!("state {}", display_path(&p.state));0}+ Some(Command::Updates(args)) => {+ let current = env!("CARGO_PKG_VERSION");+ match (runtime.block_on(update::check()), args.json) {+ (Ok(latest), true) => {+ println!("{}", serde_json::to_string_pretty(&serde_json::json!({ "current": current, "update": latest })).unwrap_or_default());+ 0+ }+ (Ok(None), false) => {+ println!("Muxin {current} is the latest version.");+ 0+ }+ (Ok(Some(u)), false) => {+ println!("Muxin {} is out (you have {current}).", u.version);+ match (&u.command, &u.download) {+ (Some(command), _) => println!("Update it with: {command}"),+ (None, Some(url)) => println!("Download: {url}"),+ (None, None) => {}+ }+ println!("What's new: {}", u.page);+ 0+ }+ (Err(e), true) => {+ println!("{}", serde_json::json!({ "error": { "code": "unreachable", "message": e } }));+ 1+ }+ (Err(e), false) => {+ eprintln!("error: {e}");+ 1+ }+ }+ }Some(Command::ShellCommand(args)) => {let result = match args.action {ShellCommandAction::Status => Ok(shell_command::status()),diff --git a/src/ui/about.rs b/src/ui/about.rsindex ad6cfe2..c12001c 100644--- a/src/ui/about.rs+++ b/src/ui/about.rs@@ -17,6 +17,49 @@ fn version() -> String {format!("Version {v} ({})", option_env!("MUXEN_BUILD").unwrap_or(v))}+/// What the last look at GitHub found: a newer version and how to get it, or+/// that this is the latest. Nothing before the first look.+fn update_card(theme: &Theme, updates: &super::updates::Updates) -> Option<AnyElement> {+ let line = |text: String, color| div().text_size(px(13.)).text_color(color).child(text);+ let body = match (&updates.latest, &updates.error) {+ (Some(u), _) => {+ let (page, download) = (u.page.clone(), u.download.clone());+ let how = match (&u.command, &u.download) {+ (Some(_), _) => "Update it the way you installed it:",+ (None, Some(_)) => "Download it, then install it over this one. Your settings stay.",+ (None, None) => "Get it from its release page.",+ };+ div()+ .flex()+ .flex_col()+ .gap(px(10.))+ .child(div().text_size(px(15.)).font_weight(FontWeight::SEMIBOLD).text_color(theme.text).child(format!("Muxin {} is out", u.version)))+ .child(line(how.into(), theme.text_muted))+ .children(u.command.clone().map(|command| {+ let copy = command.clone();+ div()+ .flex()+ .items_center()+ .gap(px(8.))+ .child(div().px(px(10.)).py(px(6.)).rounded(px(6.)).bg(theme.element).font_family(super::theme::mono_font()).text_size(px(12.5)).text_color(theme.text).child(command))+ .child(Button::new("update-copy", "Copy").icon("copy").on_click(move |_, _, cx| cx.write_to_clipboard(gpui::ClipboardItem::new_string(copy.clone()))))+ }))+ .child(+ div()+ .flex()+ .gap(px(8.))+ .children(download.map(|url| Button::new("update-download", "Download").style(ButtonStyle::Primary).icon("arrow-down").on_click(move |_, _, cx| cx.open_url(&url))))+ .child(Button::new("update-notes", "What's new").on_click(move |_, _, cx| cx.open_url(&page))),+ )+ .into_any_element()+ }+ (None, Some(e)) => line(e.clone(), theme.text_muted).into_any_element(),+ (None, None) if updates.checked => line(format!("You have the latest version, {}.", env!("CARGO_PKG_VERSION")), theme.text_muted).into_any_element(),+ (None, None) => return None,+ };+ Some(card(theme).px(px(24.)).py(px(18.)).child(body).into_any_element())+}+/// What Muxin includes from others, and under which license.const COMPONENTS: &[(&str, &str, &str)] = &[("GPUI", "Zed Industries", "Apache-2.0"),@@ -52,7 +95,13 @@ impl Root {.child(div().text_size(px(20.)).font_weight(FontWeight::SEMIBOLD).text_color(theme.text).child("Muxin")).child(div().text_size(px(14.)).text_color(theme.text_muted).child(version())),)- .child(Button::new("about-updates", "Check for Updates…").on_click(|_, _, cx| cx.open_url(WEBSITE)));+ .child({+ let engine = self.engine.clone();+ Button::new("about-updates", "Check for Updates…")+ .loading(super::updates::get(cx).checking)+ .on_click(move |_, _, cx| super::updates::check_now(engine.clone(), cx))+ });+ let update = update_card(&theme, &super::updates::get(cx));let row = |i: usize, title: &'static str, detail: &'static str, action: AnyElement| {div()@@ -113,7 +162,7 @@ impl Root {.items_center().px(px(28.)).py(px(32.))- .child(div().w_full().max_w(px(620.)).flex().flex_col().gap(px(16.)).child(header).child(links).child(built_by))+ .child(div().w_full().max_w(px(620.)).flex().flex_col().gap(px(16.)).child(header).children(update).child(links).child(built_by)).into_any_element()}}diff --git a/src/ui/desktop.rs b/src/ui/desktop.rsindex fc7a02b..9fb7118 100644--- a/src/ui/desktop.rs+++ b/src/ui/desktop.rs@@ -923,15 +923,30 @@ impl Render for DesktopWindow {.icon(if full { "minimize" } else { "maximize" }).on_click(|_, window, _| window.toggle_fullscreen()).into_any_element();+ let mut extra = vec![button];+ extra.extend(super::frame::window_buttons(window, cx));+ // When the app draws the frame (Linux on Wayland), the toolbar is the+ // title bar: it moves the window and opens the window menu.+ let title_bar = super::frame::ours(window);div()+ .relative().size_full().flex().flex_col().bg(cx.theme().canvas)+ .when(super::frame::bordered(window), |d| d.border_1().border_color(cx.theme().border))// Room for the traffic lights on macOS..when(cfg!(target_os = "macos") && !full, |d| d.pt(px(28.)))- .child(toolbar(&self.view, vec![button], cx))+ .child(+ div()+ .when(title_bar, |d| {+ d.on_mouse_down(MouseButton::Left, |e: &MouseDownEvent, window, _| super::title_bar_press(e, window))+ .on_mouse_down(MouseButton::Right, |e: &MouseDownEvent, window, _| super::frame::title_bar_menu(e, window))+ })+ .child(toolbar(&self.view, extra, cx)),+ ).child(div().flex_1().min_h(px(0.)).child(self.view.clone()))+ .children(super::frame::resize_edges(window))}}@@ -943,6 +958,7 @@ pub fn open_window(engine: Arc<Engine>, machine_id: String, display: Option<Strititlebar: Some(gpui::TitlebarOptions { title: Some(format!("{name} · Desktop").into()), appears_transparent: cfg!(target_os = "macos"), traffic_light_position: None }),window_min_size: Some(gpui::size(px(480.), px(320.))),app_id: Some("muxin".into()),+ window_decorations: super::frame::requested(),..Default::default()};let opened = cx.open_window(options, |window, cx| {diff --git a/src/ui/frame.rs b/src/ui/frame.rsnew file mode 100644index 0000000..580a1e2--- /dev/null+++ b/src/ui/frame.rs@@ -0,0 +1,112 @@+//! A window's frame when the app draws it: Linux on Wayland, where we ask+//! for it (GNOME draws no title bars for apps). Then our own top bar is the+//! title bar, with minimize, maximize and close at its end and the system's+//! window menu on right-click, and the window resizes from thin edges along+//! its sides. Where the system draws the frame (macOS, Windows, X11) none of+//! this shows.++use gpui::{AnyElement, App, CursorStyle, Decorations, ElementId, MouseButton, MouseDownEvent, ResizeEdge, Tiling, Window, WindowDecorations, div, prelude::*, px};++use super::kit::Button;++/// How far in from a side the window resizes, and how big a corner is.+const EDGE: f32 = 5.;+const CORNER: f32 = 12.;++/// What to ask for when opening a window: on Wayland, our own frame (GNOME+/// has no other; GPUI can't tell when the compositor gives none), the way Zed+/// does; elsewhere the system's.+pub fn requested() -> Option<WindowDecorations> {+ let wayland = cfg!(target_os = "linux") && std::env::var_os("WAYLAND_DISPLAY").is_some_and(|d| !d.is_empty());+ wayland.then_some(WindowDecorations::Client)+}++/// The app draws the frame.+pub fn ours(window: &Window) -> bool {+ cfg!(target_os = "linux") && matches!(window.window_decorations(), Decorations::Client { .. })+}++/// Draw a border round the window: our frame, not filling the screen.+pub fn bordered(window: &Window) -> bool {+ ours(window) && !window.is_maximized() && !window.is_fullscreen()+}++/// Minimize, maximize (or restore) and close, for the end of the top bar.+pub fn window_buttons(window: &Window, _cx: &App) -> Option<AnyElement> {+ if !ours(window) {+ return None;+ }+ let controls = window.window_controls();+ let maximized = window.is_maximized();+ Some(+ div()+ .flex()+ .flex_none()+ .items_center()+ .gap(px(2.))+ .ml(px(4.))+ .when(controls.minimize, |d| {+ d.child(Button::icon_only("window-minimize", "minus").tooltip("Minimize").on_click(|_, window, _| window.minimize_window()))+ })+ .when(controls.maximize, |d| {+ d.child(+ Button::icon_only("window-maximize", if maximized { "copy" } else { "square" })+ .tooltip(if maximized { "Restore" } else { "Maximize" })+ .on_click(|_, window, _| window.zoom_window()),+ )+ })+ .child(Button::icon_only("window-close", "x").tooltip("Close").on_click(|_, window, _| window.remove_window()))+ .into_any_element(),+ )+}++/// A right-click on the top bar: the system's window menu, when it has one.+pub fn title_bar_menu(e: &MouseDownEvent, window: &mut Window) {+ if ours(window) && window.window_controls().window_menu {+ window.show_window_menu(e.position);+ }+}++/// The edges and corners to resize from, laid over the window (its root must+/// be `relative`): none when it fills the screen, or along a side it's tiled+/// against.+pub fn resize_edges(window: &Window) -> Vec<AnyElement> {+ let Decorations::Client { tiling } = window.window_decorations() else { return Vec::new() };+ if !cfg!(target_os = "linux") || window.is_maximized() || window.is_fullscreen() {+ return Vec::new();+ }+ let Tiling { top, left, right, bottom } = tiling;+ let grip = |id: &'static str, edge: ResizeEdge, cursor: CursorStyle| {+ div().id(ElementId::Name(id.into())).absolute().occlude().cursor(cursor).on_mouse_down(MouseButton::Left, move |_, window, cx| {+ cx.stop_propagation();+ window.start_window_resize(edge);+ })+ };+ let mut out = Vec::new();+ if !top {+ out.push(grip("resize-top", ResizeEdge::Top, CursorStyle::ResizeUpDown).top_0().left(px(CORNER)).right(px(CORNER)).h(px(EDGE)).into_any_element());+ }+ if !bottom {+ out.push(grip("resize-bottom", ResizeEdge::Bottom, CursorStyle::ResizeUpDown).bottom_0().left(px(CORNER)).right(px(CORNER)).h(px(EDGE)).into_any_element());+ }+ if !left {+ out.push(grip("resize-left", ResizeEdge::Left, CursorStyle::ResizeLeftRight).left_0().top(px(CORNER)).bottom(px(CORNER)).w(px(EDGE)).into_any_element());+ }+ if !right {+ out.push(grip("resize-right", ResizeEdge::Right, CursorStyle::ResizeLeftRight).right_0().top(px(CORNER)).bottom(px(CORNER)).w(px(EDGE)).into_any_element());+ }+ let corner = |id, edge, cursor| grip(id, edge, cursor).size(px(CORNER));+ if !top && !left {+ out.push(corner("resize-top-left", ResizeEdge::TopLeft, CursorStyle::ResizeUpLeftDownRight).top_0().left_0().into_any_element());+ }+ if !top && !right {+ out.push(corner("resize-top-right", ResizeEdge::TopRight, CursorStyle::ResizeUpRightDownLeft).top_0().right_0().into_any_element());+ }+ if !bottom && !left {+ out.push(corner("resize-bottom-left", ResizeEdge::BottomLeft, CursorStyle::ResizeUpRightDownLeft).bottom_0().left_0().into_any_element());+ }+ if !bottom && !right {+ out.push(corner("resize-bottom-right", ResizeEdge::BottomRight, CursorStyle::ResizeUpLeftDownRight).bottom_0().right_0().into_any_element());+ }+ out+}diff --git a/src/ui/kit.rs b/src/ui/kit.rsindex d712b09..84d3531 100644--- a/src/ui/kit.rs+++ b/src/ui/kit.rs@@ -510,6 +510,8 @@ impl RenderOnce for Button {ButtonStyle::Danger => (gpui::transparent_black(), theme.error.opacity(0.14), theme.error, None),};let disabled = self.disabled || self.loading;+ // A theme with two brand colors fills primary buttons with both, as the icon does.+ let gradient = (self.style == ButtonStyle::Primary && theme.accent2 != theme.accent).then_some((theme.accent, theme.accent2));let mut el = div().id(self.id.clone()).flex()@@ -527,10 +529,10 @@ impl RenderOnce for Button {.font_weight(FontWeight::MEDIUM).when_some(border, |d, b| d.border_1().border_color(b)).when(disabled, |d| d.opacity(0.5))- .when(!disabled, |d| d.cursor_pointer().hover(move |s| s.bg(hover)));- // A theme with two brand colors fills primary buttons with both, as the icon does.- if self.style == ButtonStyle::Primary && theme.accent2 != theme.accent {- let (a, b) = (theme.accent, theme.accent2);+ .when(!disabled, |d| d.cursor_pointer())+ // One hover style per element (GPUI checks in debug builds).+ .when(!disabled && gradient.is_none(), |d| d.hover(move |s| s.bg(hover)));+ if let Some((a, b)) = gradient {el = el.bg(gpui::linear_gradient(90., gpui::linear_color_stop(a, 0.), gpui::linear_color_stop(b, 1.)));if !disabled {el = el.hover(move |s| s.bg(gpui::linear_gradient(90., gpui::linear_color_stop(a.opacity(0.85), 0.), gpui::linear_color_stop(b.opacity(0.85), 1.))));diff --git a/src/ui/mod.rs b/src/ui/mod.rsindex 3b95546..be06024 100644--- a/src/ui/mod.rs+++ b/src/ui/mod.rs@@ -8,6 +8,7 @@ mod detail;mod dialogs;mod files;mod format;+mod frame;mod github;mod hosted;mod input;@@ -29,6 +30,7 @@ mod theme;mod run;mod schedule_dialog;mod schedules;+mod updates;mod usage;mod vm_dialog;mod themes;@@ -61,6 +63,7 @@ pub fn run(engine: Arc<Engine>, initial_view: Option<String>) {root::bind_keys(cx);cx.on_action(|_: &Quit, cx| cx.quit());cx.set_menus(root::menus());+ updates::start(engine.clone(), cx);// `--view size:960x640` (screenshots and layout checks) overrides the default size.let (w, h) = initial_view@@ -93,6 +96,7 @@ pub fn run(engine: Arc<Engine>, initial_view: Option<String>) {titlebar: Some(titlebar),window_min_size: Some(size(px(960.), px(600.))),app_id: Some("muxin".into()),+ window_decorations: frame::requested(),// A test window (on the laptop's screen) doesn't take the keyboard// from whatever the user is typing in.focus: !wants_builtin,@@ -195,13 +199,17 @@ fn builtin_display(_: &App) -> Option<gpui::DisplayId> {None}-/// A press on our own title bar: a double click zooms (or whatever the system-/// setting says); otherwise the window follows the mouse. On macOS GPUI only-/// does this in the top 28 points, so we ask AppKit to drag from the event.+/// A press on our own title bar: a double click zooms (on macOS, whatever the+/// system setting says); otherwise the window follows the mouse. On macOS GPUI+/// only does this in the top 28 points, so we ask AppKit to drag from the event.#[allow(unexpected_cfgs)] // objc's msg_send! checks a cfg this crate doesn't declarepub(crate) fn title_bar_press(e: &gpui::MouseDownEvent, window: &mut gpui::Window) {if e.click_count == 2 {- window.titlebar_double_click();+ if cfg!(target_os = "macos") {+ window.titlebar_double_click();+ } else {+ window.zoom_window();+ }return;}#[cfg(target_os = "macos")]diff --git a/src/ui/root.rs b/src/ui/root.rsindex 34d7a24..1ea6ccc 100644--- a/src/ui/root.rs+++ b/src/ui/root.rs@@ -2563,7 +2563,27 @@ impl Root {.child(footer_button("footer-settings", "settings", "Settings", Route::Settings, cx)).child(footer_button("footer-about", "info", "About", Route::About, cx)).child(div().flex_1())- .child(div().pr(px(6.)).font_family(mono_font()).text_size(px(11.)).text_color(theme.text_placeholder).child(format!("v{}", env!("CARGO_PKG_VERSION"))));+ .child(match super::updates::get(cx).latest {+ // A newer version: says so, and About says how to get it.+ Some(update) => div()+ .id("footer-update")+ .flex()+ .items_center()+ .gap(px(5.))+ .px(px(6.))+ .py(px(3.))+ .rounded(px(5.))+ .cursor_pointer()+ .text_size(px(11.5))+ .text_color(theme.text_accent)+ .hover(|st| st.bg(theme.ghost_hover))+ .child(kit::dot(theme.accent, 6.))+ .child(format!("{} is out", update.version))+ .tooltip(move |window, cx| kit::Tooltip::view(format!("Muxin {} is out. See how to update.", update.version).into(), window, cx))+ .on_click(cx.listener(|this, _, window, cx| this.navigate(Route::About, window, cx)))+ .into_any_element(),+ None => div().pr(px(6.)).font_family(mono_font()).text_size(px(11.)).text_color(theme.text_placeholder).child(format!("v{}", env!("CARGO_PKG_VERSION"))).into_any_element(),+ });div().flex_none().px(px(10.)).pb(px(10.)).border_t_1().border_color(theme.border_variant).child(footer)}@@ -2597,6 +2617,7 @@ impl Root {.border_color(theme.border_variant)// The whole bar moves the window (except its buttons), like a title bar..on_mouse_down(gpui::MouseButton::Left, |e: &gpui::MouseDownEvent, window, _| super::title_bar_press(e, window))+ .on_mouse_down(gpui::MouseButton::Right, |e: &gpui::MouseDownEvent, window, _| super::frame::title_bar_menu(e, window)).child(Button::icon_only("toggle-sidebar", "panel-left").tooltip(tip(if self.sidebar_hidden { "Show sidebar" } else { "Hide sidebar" }, &super::shortcuts::label_for(cx, "sidebar")))@@ -2643,7 +2664,7 @@ impl Root {}).on_click(cx.listener(|this, _, window, cx| this.show_add_machine(window, cx))),)-+ .children(super::frame::window_buttons(window, cx))}fn render_notice(&self, theme: &Theme) -> Option<AnyElement> {@@ -3122,6 +3143,7 @@ impl Render for Root {.flex().size_full().bg(theme.canvas)+ .when(super::frame::bordered(window), |d| d.border_1().border_color(theme.border)).text_color(theme.text).font_family(ui_font()).text_size(px(13.))@@ -3167,6 +3189,8 @@ impl Render for Root {),)})+ // Over everything, dialogs too: the edges to resize the window from.+ .children(super::frame::resize_edges(window))}}diff --git a/src/ui/settings.rs b/src/ui/settings.rsindex b0db73d..fbd5cf7 100644--- a/src/ui/settings.rs+++ b/src/ui/settings.rs@@ -893,6 +893,30 @@ impl SettingsPage {)}+ /// Whether Muxin asks GitHub for its latest release (crate::update).+ fn updates_section(&self, theme: &Theme) -> impl IntoElement {+ let on = self.engine.settings().check_updates;+ let engine = self.engine.clone();+ div()+ .flex()+ .flex_col()+ .gap(px(10.))+ .child(section_title(theme, "Updates", None))+ .child(+ card(theme)+ .px(px(14.))+ .py(px(12.))+ .gap(px(6.))+ .child(kit::checkbox(theme, "check-updates", on, "Tell me when a new version is out", move |on, _, cx| {+ let mut s = engine.settings();+ s.check_updates = *on;+ let _ = engine.update_settings(s);+ cx.refresh_windows();+ }))+ .child(div().text_size(px(11.5)).text_color(theme.text_placeholder).child("Muxin asks GitHub for its latest release when it opens and twice a day. Nothing about you is sent.")),+ )+ }+/// The editor machines' folders open in.fn editor_section(&self, theme: &Theme) -> impl IntoElement {let chosen = self.engine.settings().editor;@@ -1014,6 +1038,7 @@ impl Render for SettingsPage {.child(self.shell_section(&theme, cx)).child(self.clipboard_section(&theme)).child(self.editor_section(&theme))+ .child(self.updates_section(&theme)).children(self.tailscale_section(&theme)).child(self.checks_section(&theme, false, cx)).child(self.inventory_section(&theme)),diff --git a/src/ui/updates.rs b/src/ui/updates.rsnew file mode 100644index 0000000..bdac759--- /dev/null+++ b/src/ui/updates.rs@@ -0,0 +1,77 @@+//! The app's side of crate::update: a look at GitHub soon after launch and+//! every twelve hours (while Settings › General › Updates allows it), kept for+//! the sidebar's footer and the About page.++use std::sync::Arc;+use std::time::Duration;++use gpui::{App, AsyncApp, Global};++use crate::fleet::Engine;+use crate::update::Update;++const FIRST: Duration = Duration::from_secs(8);+const EVERY: Duration = Duration::from_secs(12 * 60 * 60);++#[derive(Default, Clone)]+pub struct Updates {+ /// A newer version, when there is one.+ pub latest: Option<Update>,+ /// A look finished since Muxin opened.+ pub checked: bool,+ pub checking: bool,+ pub error: Option<String>,+}++impl Global for Updates {}++/// Starts looking (not in demo mode: it shows what the app does, offline).+pub fn start(engine: Arc<Engine>, cx: &mut App) {+ cx.set_global(Updates::default());+ if engine.is_demo() {+ return;+ }+ cx.spawn(async move |cx| {+ cx.background_executor().timer(FIRST).await;+ loop {+ if engine.settings().check_updates {+ look(&engine, cx).await;+ }+ cx.background_executor().timer(EVERY).await;+ }+ })+ .detach();+}++/// Looks now: the About page's Check for Updates.+pub fn check_now(engine: Arc<Engine>, cx: &mut App) {+ if get(cx).checking {+ return;+ }+ cx.spawn(async move |cx| look(&engine, cx).await).detach();+}++pub fn get(cx: &App) -> Updates {+ cx.try_global::<Updates>().cloned().unwrap_or_default()+}++async fn look(engine: &Arc<Engine>, cx: &mut AsyncApp) {+ let _ = cx.update(|cx| {+ cx.default_global::<Updates>().checking = true;+ cx.refresh_windows();+ });+ let result = engine.runtime().spawn(crate::update::check()).await.unwrap_or_else(|e| Err(e.to_string()));+ let _ = cx.update(|cx| {+ let u = cx.default_global::<Updates>();+ u.checking = false;+ u.checked = true;+ match result {+ Ok(latest) => {+ u.latest = latest;+ u.error = None;+ }+ Err(e) => u.error = Some(e),+ }+ cx.refresh_windows();+ });+}diff --git a/src/update.rs b/src/update.rsnew file mode 100644index 0000000..63705e5--- /dev/null+++ b/src/update.rs@@ -0,0 +1,189 @@+//! Whether a newer Muxin is out: GitHub's latest release of+//! LumaryLabsLLC/muxin against this build's version, and how this copy is+//! best updated: Homebrew or the AUR update it, else the release's file for+//! this computer (the DMG, the Windows installer, the .deb or .rpm, the+//! AppImage or the tarball). Only GitHub is asked, and nothing about the user+//! goes with it.++use std::path::Path;+use std::time::Duration;++use serde::Serialize;++const LATEST: &str = "https://api.github.com/repos/LumaryLabsLLC/muxin/releases/latest";++/// A newer version, and how to get it.+#[derive(Debug, Clone, Serialize, PartialEq)]+pub struct Update {+ /// "0.5.3".+ pub version: String,+ /// Its release page: what's new, and every file.+ pub page: String,+ /// The file for this computer, when one fits and no package manager owns this copy.+ pub download: Option<String>,+ /// The command that updates this copy, when a package manager owns it.+ pub command: Option<String>,+}++/// Asks GitHub. None when this is the latest (or newer: a build from source).+pub async fn check() -> Result<Option<Update>, String> {+ let client = reqwest::Client::builder()+ .timeout(Duration::from_secs(10))+ .user_agent(concat!("muxin/", env!("CARGO_PKG_VERSION")))+ .build()+ .map_err(|e| e.to_string())?;+ let reply = client.get(LATEST).header("Accept", "application/vnd.github+json").send().await.map_err(|e| format!("Couldn't reach GitHub: {e}"))?;+ if !reply.status().is_success() {+ return Err(format!("GitHub answered {}.", reply.status()));+ }+ let release: serde_json::Value = reply.json().await.map_err(|e| format!("GitHub's answer didn't make sense: {e}"))?;+ Ok(read(&release, env!("CARGO_PKG_VERSION"), &how_installed()))+}++/// The newer version in GitHub's answer, if it's newer than `current`.+fn read(release: &serde_json::Value, current: &str, how: &Installed) -> Option<Update> {+ let version = release["tag_name"].as_str()?.trim_start_matches('v').to_string();+ if !newer(&version, current) {+ return None;+ }+ let assets: Vec<(&str, &str)> = release["assets"]+ .as_array()+ .into_iter()+ .flatten()+ .filter_map(|a| Some((a["name"].as_str()?, a["browser_download_url"].as_str()?)))+ .collect();+ let file = |ending: &str| assets.iter().find(|(name, _)| name.ends_with(ending)).map(|(_, url)| url.to_string());+ let arch = if cfg!(target_arch = "aarch64") { "aarch64" } else { "x86_64" };+ let (download, command) = match how {+ Installed::Homebrew => (None, Some("brew upgrade --cask muxin".to_string())),+ Installed::Aur => (None, Some("yay -S muxin-bin".to_string())),+ Installed::Package(ending) => (file(&format!("-linux-{arch}.{ending}")), None),+ Installed::AppImage => (file(&format!("-linux-{arch}.AppImage")), None),+ Installed::Tarball => (file(&format!("-linux-{arch}.tar.gz")), None),+ Installed::App if cfg!(target_os = "macos") => (file("-macos.dmg"), None),+ Installed::App if cfg!(windows) => (file(&format!("-windows-{}-setup.exe", if cfg!(target_arch = "aarch64") { "arm64" } else { "x64" })), None),+ Installed::App => (None, None),+ };+ Some(Update { version, page: release["html_url"].as_str().unwrap_or("https://github.com/LumaryLabsLLC/muxin/releases/latest").to_string(), download, command })+}++/// `a` comes after `b`: their numbers compared in order ("0.10.0" after+/// "0.9.2"); a pre-release ("0.6.0-rc.1") counts as its numbers.+fn newer(a: &str, b: &str) -> bool {+ let parts = |v: &str| -> Vec<u64> { v.split(['-', '+']).next().unwrap_or("").split('.').map(|p| p.parse().unwrap_or(0)).collect() };+ let (a, b) = (parts(a), parts(b));+ for i in 0..a.len().max(b.len()) {+ let (x, y) = (a.get(i).copied().unwrap_or(0), b.get(i).copied().unwrap_or(0));+ if x != y {+ return x > y;+ }+ }+ false+}++/// How this copy got here, which decides how it's updated.+#[derive(Debug, PartialEq)]+enum Installed {+ Homebrew,+ /// The AUR's muxin-bin.+ Aur,+ /// The release's Linux package: "deb", "rpm" or "pkg.tar.zst".+ Package(&'static str),+ AppImage,+ /// The tarball's install.sh (~/.local/share/muxin-app).+ Tarball,+ /// The macOS app or the Windows installer (or a build of its own).+ App,+}++fn how_installed() -> Installed {+ if cfg!(target_os = "linux") && std::env::var_os("APPIMAGE").is_some() {+ return Installed::AppImage;+ }+ let exe = std::env::current_exe().ok().and_then(|e| e.canonicalize().ok()).unwrap_or_default();+ let homebrew = ["/opt/homebrew", "/usr/local", "/home/linuxbrew/.linuxbrew"].iter().any(|p| Path::new(p).join("Caskroom/muxin").is_dir());+ if exe.to_string_lossy().contains("/Caskroom/muxin/") || (cfg!(target_os = "macos") && homebrew && exe.starts_with("/Applications/Muxin.app")) {+ return Installed::Homebrew;+ }+ if !cfg!(target_os = "linux") {+ return Installed::App;+ }+ if exe.starts_with("/usr/lib/muxin") {+ return linux_package(Path::new("/"));+ }+ if exe.to_string_lossy().contains("/.local/share/muxin-app/") {+ return Installed::Tarball;+ }+ Installed::App+}++/// Which Linux package put the app in /usr/lib/muxin: the AUR's, or the+/// release's for this system (by its package database, then /etc/os-release).+fn linux_package(root: &Path) -> Installed {+ let pacman = root.join("var/lib/pacman/local");+ if let Ok(dir) = std::fs::read_dir(&pacman) {+ let names: Vec<String> = dir.flatten().map(|e| e.file_name().to_string_lossy().into_owned()).collect();+ if names.iter().any(|n| n.starts_with("muxin-bin-")) {+ return Installed::Aur;+ }+ return Installed::Package("pkg.tar.zst");+ }+ let release = std::fs::read_to_string(root.join("etc/os-release")).unwrap_or_default();+ let ids: String = release.lines().filter(|l| l.starts_with("ID=") || l.starts_with("ID_LIKE=")).collect::<Vec<_>>().join(" ").to_lowercase();+ if ["fedora", "rhel", "suse", "centos"].iter().any(|d| ids.contains(d)) || root.join("var/lib/rpm").is_dir() && !root.join("var/lib/dpkg").is_dir() {+ Installed::Package("rpm")+ } else {+ Installed::Package("deb")+ }+}++#[cfg(test)]+mod tests {+ use super::*;+ use serde_json::json;++ #[test]+ fn compares_versions() {+ assert!(newer("0.5.3", "0.5.2") && newer("0.10.0", "0.9.9") && newer("1.0", "0.99.99"));+ assert!(!newer("0.5.2", "0.5.2") && !newer("0.5.1", "0.5.2") && !newer("0.6.0-rc.1", "0.6.0"));+ }++ #[test]+ fn picks_how_to_update() {+ let release = json!({+ "tag_name": "v0.5.3", "html_url": "https://github.com/LumaryLabsLLC/muxin/releases/tag/v0.5.3",+ "assets": [+ { "name": "Muxin-0.5.3-macos.dmg", "browser_download_url": "https://x/Muxin-0.5.3-macos.dmg" },+ { "name": "Muxin-0.5.3-linux-x86_64.deb", "browser_download_url": "https://x/Muxin-0.5.3-linux-x86_64.deb" },+ { "name": "Muxin-0.5.3-linux-aarch64.deb", "browser_download_url": "https://x/Muxin-0.5.3-linux-aarch64.deb" },+ ],+ });+ assert_eq!(read(&release, "0.5.3", &Installed::App), None, "the same version");+ let brew = read(&release, "0.5.2", &Installed::Homebrew).unwrap();+ assert_eq!((brew.version.as_str(), brew.command.as_deref(), brew.download), ("0.5.3", Some("brew upgrade --cask muxin"), None));+ let deb = read(&release, "0.5.2", &Installed::Package("deb")).unwrap();+ let arch = if cfg!(target_arch = "aarch64") { "aarch64" } else { "x86_64" };+ assert_eq!(deb.download.as_deref(), Some(format!("https://x/Muxin-0.5.3-linux-{arch}.deb").as_str()));+ if cfg!(target_os = "macos") {+ assert_eq!(read(&release, "0.5.2", &Installed::App).unwrap().download.as_deref(), Some("https://x/Muxin-0.5.3-macos.dmg"));+ }+ }++ #[test]+ fn knows_the_linux_package() {+ let root = std::env::temp_dir().join(format!("muxin-update-{}", std::process::id()));+ let _ = std::fs::remove_dir_all(&root);+ std::fs::create_dir_all(root.join("etc")).unwrap();+ std::fs::write(root.join("etc/os-release"), "ID=ubuntu\nID_LIKE=debian\n").unwrap();+ assert_eq!(linux_package(&root), Installed::Package("deb"));+ std::fs::write(root.join("etc/os-release"), "ID=fedora\n").unwrap();+ assert_eq!(linux_package(&root), Installed::Package("rpm"));+ std::fs::write(root.join("etc/os-release"), "ID=opensuse-tumbleweed\nID_LIKE=\"opensuse suse\"\n").unwrap();+ assert_eq!(linux_package(&root), Installed::Package("rpm"));+ std::fs::create_dir_all(root.join("var/lib/pacman/local/muxin-0.5.2-1")).unwrap();+ assert_eq!(linux_package(&root), Installed::Package("pkg.tar.zst"));+ std::fs::create_dir_all(root.join("var/lib/pacman/local/muxin-bin-0.5.2-1")).unwrap();+ assert_eq!(linux_package(&root), Installed::Aur);+ let _ = std::fs::remove_dir_all(&root);+ }+}