Skip to content

armgit / muxin

Public Imported from GitHub
0

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.

Windows: installer, theme-colored title bar, local agent setup, polish

Adib Hanna91c556503c14
diff --git a/Cargo.toml b/Cargo.toml
index fac0424..4e190af 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -57,7 +57,9 @@ winresource = "0.1"
# Starting without a console window (see main.rs `without_console_window`).
[target.'cfg(windows)'.dependencies]
-windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_System_Console", "Win32_UI_WindowsAndMessaging", "Win32_Security_Credentials"] }
+windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_System_Console", "Win32_UI_WindowsAndMessaging", "Win32_Security_Credentials", "Win32_Graphics_Dwm"] }
+# The window's handle, to color its title bar like the theme.
+raw-window-handle = { version = "0.6", optional = true }
[workspace]
members = [".", "agent"]
diff --git a/README.md b/README.md
index ce4daa0..a46697e 100644
--- a/README.md
+++ b/README.md
@@ -501,7 +501,7 @@ muxen cloud destroy dev-1
Not yet on Windows: Docker runners and Docker workspaces, adding virtual monitors.
-**The app on Windows** is built on Windows (GPUI compiles its shaders with the Windows SDK's `fxc.exe`): install Rust and Visual Studio's C++ build tools with the Windows SDK, run `scripts/build-agents.sh` on a Mac or Linux (it makes the Windows agent too, with `cargo-zigbuild`), then `scripts\package-windows.ps1` on Windows. That makes `dist\Muxen-windows-x64.zip`: `muxen.exe` and its `agents\`. Started from Explorer it shows no console window; from a terminal it's the same CLI as elsewhere. Secrets go in Windows' Credential Manager.
+**The app on Windows** is built on Windows (GPUI compiles its shaders with the Windows SDK's `fxc.exe`): install Rust and Visual Studio's C++ build tools with the Windows SDK, run `scripts/build-agents.sh` on a Mac or Linux (it makes the Windows agent too, with `cargo-zigbuild`), then `scripts\package-windows.ps1` on Windows. That makes `dist\Muxen-Setup-x64.exe` (an installer, with [Inno Setup](https://jrsoftware.org/isinfo.php): for this user, no administrator needed, a Start menu entry, optionally `muxen` on the PATH, an uninstaller) and `dist\Muxen-windows-x64.zip` (`muxen.exe` and its `agents\`). Started from Explorer it shows no console window; from a terminal it's the same CLI as elsewhere. Secrets go in Windows' Credential Manager.
## Develop
diff --git a/agent/src/sys.rs b/agent/src/sys.rs
index 635b3a3..768968a 100644
--- a/agent/src/sys.rs
+++ b/agent/src/sys.rs
@@ -137,11 +137,29 @@ pub fn spawn_background(args: &[&str], log: PathBuf) -> io::Result<()> {
}
#[cfg(windows)]
{
+ use std::os::windows::process::CommandExt;
+ use std::process::Stdio;
+ const CREATE_BREAKAWAY_FROM_JOB: u32 = 0x0100_0000;
let _ = log;
+ // Out of whatever job this runs in, without a window. That works
+ // unless the job forbids it (sshd's ends everything in it when the
+ // session closes): then through WMI, which starts it outside.
+ let direct = Command::new(&exe)
+ .args(args)
+ .current_dir(&home)
+ .stdin(Stdio::null())
+ .stdout(Stdio::null())
+ .stderr(Stdio::null())
+ .creation_flags(CREATE_NO_WINDOW | CREATE_NEW_PROCESS_GROUP | CREATE_BREAKAWAY_FROM_JOB)
+ .spawn();
+ if direct.is_ok() {
+ return Ok(());
+ }
let quote = |s: &str| s.replace('\'', "''");
let line = std::iter::once(format!("\"{}\"", exe.display())).chain(args.iter().map(|a| a.to_string())).collect::<Vec<_>>().join(" ");
+ // Hidden (ShowWindow 0), should this be a desktop session.
let script = format!(
- "$r = Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{{ CommandLine = '{}'; CurrentDirectory = '{}' }}; exit $r.ReturnValue",
+ "$startup = New-CimInstance -ClassName Win32_ProcessStartup -ClientOnly -Property @{{ ShowWindow = [uint16]0 }}; $r = Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{{ CommandLine = '{}'; CurrentDirectory = '{}'; ProcessStartupInformation = $startup }}; exit $r.ReturnValue",
quote(&line),
quote(&home.display().to_string())
);
diff --git a/scripts/muxen.iss b/scripts/muxen.iss
new file mode 100644
index 0000000..4b1660f
--- /dev/null
+++ b/scripts/muxen.iss
@@ -0,0 +1,103 @@
+; Muxen's Windows installer (Inno Setup 6), made by scripts\package-windows.ps1
+; from dist\windows\Muxen. Installs for this user (no administrator needed)
+; in %LOCALAPPDATA%\Programs\Muxen, with a Start menu entry, and optionally a
+; desktop shortcut and `muxen` on the PATH.
+
+#ifndef AppVersion
+ #define AppVersion "0.1.0"
+#endif
+
+[Setup]
+AppId={{6F0B8E52-3C8E-4C8C-9E5B-6C4D2A9B7E31}
+AppName=Muxen
+AppVersion={#AppVersion}
+AppVerName=Muxen {#AppVersion}
+AppPublisher=Lumary Labs
+AppPublisherURL=https://muxin.dev
+DefaultDirName={localappdata}\Programs\Muxen
+DefaultGroupName=Muxen
+DisableProgramGroupPage=yes
+PrivilegesRequired=lowest
+OutputDir=..\dist
+OutputBaseFilename=Muxen-Setup-x64
+SetupIconFile=..\assets\brand\muxen.ico
+UninstallDisplayIcon={app}\muxen.exe
+Compression=lzma2/max
+SolidCompression=yes
+ArchitecturesAllowed=x64compatible
+ArchitecturesInstallIn64BitMode=x64compatible
+WizardStyle=modern
+ChangesEnvironment=yes
+CloseApplications=yes
+
+[Tasks]
+Name: "desktopicon"; Description: "Add a desktop shortcut"; GroupDescription: "Shortcuts:"; Flags: unchecked
+Name: "addtopath"; Description: "Add the muxen command to the PATH (for terminals and AI agents)"; GroupDescription: "Command line:"
+
+[Files]
+Source: "..\dist\windows\Muxen\muxen.exe"; DestDir: "{app}"; Flags: ignoreversion
+Source: "..\dist\windows\Muxen\agents\*"; DestDir: "{app}\agents"; Flags: ignoreversion
+Source: "..\dist\windows\Muxen\README.md"; DestDir: "{app}"; Flags: ignoreversion
+Source: "..\dist\windows\Muxen\LICENSE"; DestDir: "{app}"; Flags: ignoreversion
+Source: "..\dist\windows\Muxen\THIRD_PARTY_NOTICES.md"; DestDir: "{app}"; Flags: ignoreversion
+
+[Icons]
+Name: "{autoprograms}\Muxen"; Filename: "{app}\muxen.exe"
+Name: "{autodesktop}\Muxen"; Filename: "{app}\muxen.exe"; Tasks: desktopicon
+
+[Run]
+Filename: "{app}\muxen.exe"; Description: "Open Muxen"; Flags: nowait postinstall skipifsilent
+
+[Code]
+const
+ EnvKey = 'Environment';
+
+function PathHas(Dir: string): Boolean;
+var
+ Path: string;
+begin
+ if not RegQueryStringValue(HKEY_CURRENT_USER, EnvKey, 'Path', Path) then
+ Path := '';
+ Result := Pos(';' + Uppercase(Dir) + ';', ';' + Uppercase(Path) + ';') > 0;
+end;
+
+procedure AddToPath(Dir: string);
+var
+ Path: string;
+begin
+ if PathHas(Dir) then
+ exit;
+ if not RegQueryStringValue(HKEY_CURRENT_USER, EnvKey, 'Path', Path) then
+ Path := '';
+ if (Path <> '') and (Copy(Path, Length(Path), 1) <> ';') then
+ Path := Path + ';';
+ RegWriteExpandStringValue(HKEY_CURRENT_USER, EnvKey, 'Path', Path + Dir);
+end;
+
+procedure RemoveFromPath(Dir: string);
+var
+ Path: string;
+ P: Integer;
+begin
+ if not RegQueryStringValue(HKEY_CURRENT_USER, EnvKey, 'Path', Path) then
+ exit;
+ P := Pos(';' + Uppercase(Dir) + ';', ';' + Uppercase(Path) + ';');
+ if P = 0 then
+ exit;
+ Delete(Path, P, Length(Dir) + 1);
+ if (Length(Path) > 0) and (Copy(Path, Length(Path), 1) = ';') then
+ Delete(Path, Length(Path), 1);
+ RegWriteExpandStringValue(HKEY_CURRENT_USER, EnvKey, 'Path', Path);
+end;
+
+procedure CurStepChanged(CurStep: TSetupStep);
+begin
+ if (CurStep = ssPostInstall) and WizardIsTaskSelected('addtopath') then
+ AddToPath(ExpandConstant('{app}'));
+end;
+
+procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
+begin
+ if CurUninstallStep = usPostUninstall then
+ RemoveFromPath(ExpandConstant('{app}'));
+end;
diff --git a/scripts/package-windows.ps1 b/scripts/package-windows.ps1
index 7bdd8f7..be89e06 100644
--- a/scripts/package-windows.ps1
+++ b/scripts/package-windows.ps1
@@ -1,4 +1,5 @@
-# Builds Muxen for Windows and packs it: dist\Muxen-windows-x64.zip, with
+# Builds Muxen for Windows and packs it: dist\Muxen-Setup-x64.exe (an
+# installer, with Inno Setup) and dist\Muxen-windows-x64.zip, both with
# muxen.exe and, beside it in agents\, the agent builds it sets up on each
# machine (made on a Mac or Linux by scripts/build-agents.sh).
#
@@ -29,3 +30,16 @@ Copy-Item README.md, LICENSE, THIRD_PARTY_NOTICES.md $out
$zip = 'dist\Muxen-windows-x64.zip'
Compress-Archive -Path $out -DestinationPath $zip -Force
"Built $zip ($([math]::Round((Get-Item $zip).Length / 1MB, 1)) MB)"
+
+# The installer, when Inno Setup is here (winget install JRSoftware.InnoSetup).
+$iscc = @(Get-Command ISCC.exe -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source) +
+ @("$env:LOCALAPPDATA\Programs\Inno Setup 6\ISCC.exe", "${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe") | Where-Object { $_ -and (Test-Path $_) } | Select-Object -First 1
+if ($iscc) {
+ $version = (Select-String -Path Cargo.toml -Pattern '^version = "(.+)"' | Select-Object -First 1).Matches[0].Groups[1].Value
+ & $iscc /Q "/DAppVersion=$version" scripts\muxen.iss
+ if ($LASTEXITCODE) { exit $LASTEXITCODE }
+ $setup = 'dist\Muxen-Setup-x64.exe'
+ "Built $setup ($([math]::Round((Get-Item $setup).Length / 1MB, 1)) MB)"
+} else {
+ 'No Inno Setup here, so no installer (winget install JRSoftware.InnoSetup).'
+}
diff --git a/src/fleet/sessions/agent.rs b/src/fleet/sessions/agent.rs
index b1dbeac..7030e06 100644
--- a/src/fleet/sessions/agent.rs
+++ b/src/fleet/sessions/agent.rs
@@ -208,15 +208,30 @@ async fn upload(spec: &MachineSpec, bytes: Vec<u8>) -> Result<String, String> {
tokio::time::timeout(UPLOAD_TIMEOUT, work).await.map_err(|_| format!("{} took too long to receive the agent.", spec.name))?
}
-/// Copies the build into place on Windows and prints its hash. The file goes
-/// over sftp (Windows' sshd stalls on a few hundred KB through a program's
-/// stdin), then PowerShell puts it in place. A running agent holds its file,
-/// but Windows lets it be renamed: the old one moves aside and goes once
-/// nothing runs it.
+/// Puts an uploaded build (`muxen-agent.upload.exe`) in place on Windows and
+/// prints its hash. A running agent holds its file, but Windows lets it be
+/// renamed: the old one moves aside and goes once nothing runs it; the
+/// desktop helper, running the old build, goes now.
+const SWAP_PS1: &str = "$ErrorActionPreference = 'Stop'\n\
+ $d = Join-Path $env:USERPROFILE '.muxen\\bin'\n\
+ $t = Join-Path $d 'muxen-agent.exe'\n\
+ if (Test-Path $t) { Move-Item -Force $t (Join-Path $d \"muxen-agent.old.$PID.exe\") }\n\
+ Move-Item -Force (Join-Path $d 'muxen-agent.upload.exe') $t\n\
+ Get-CimInstance Win32_Process -Filter \"Name='muxen-agent.exe'\" | Where-Object { $_.CommandLine -match ' gui-serve' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }\n\
+ Get-ChildItem $d -Filter 'muxen-agent.old.*.exe' | ForEach-Object { Remove-Item -Force $_.FullName -ErrorAction SilentlyContinue }\n\
+ & $t hash\n";
+
+/// Copies the build into place on Windows and prints its hash: over sftp
+/// (Windows' sshd stalls on a few hundred KB through a program's stdin), or
+/// a copy on this computer; then SWAP_PS1.
async fn upload_windows(spec: &MachineSpec, build: &std::path::Path) -> Result<String, String> {
let fail = |e: String| format!("couldn't install the agent on {}: {e}", spec.name);
if spec.is_local() {
- return Err(fail("Muxen doesn't set up its agent on this Windows computer yet.".into()));
+ // This computer: a copy, then the same swap.
+ let bin = dirs::home_dir().unwrap_or_default().join(".muxen").join("bin");
+ std::fs::create_dir_all(&bin).map_err(|e| fail(e.to_string()))?;
+ std::fs::copy(build, bin.join("muxen-agent.upload.exe")).map_err(|e| fail(e.to_string()))?;
+ return run_ps(spec, SWAP_PS1, CTL_TIMEOUT).await.map_err(fail);
}
// sftp takes ssh's options, but its own spelling of the port and user.
let mut args: Vec<String> = Vec::new();
@@ -243,15 +258,7 @@ async fn upload_windows(spec: &MachineSpec, build: &std::path::Path) -> Result<S
if status.success() { Ok(()) } else { Err(err.lines().last().unwrap_or("sftp failed").trim().to_string()) }
};
tokio::time::timeout(UPLOAD_TIMEOUT, sent).await.map_err(|_| fail("the copy took too long".into()))?.map_err(fail)?;
- let script = "$ErrorActionPreference = 'Stop'\n\
- $d = Join-Path $env:USERPROFILE '.muxen\\bin'\n\
- $t = Join-Path $d 'muxen-agent.exe'\n\
- if (Test-Path $t) { Move-Item -Force $t (Join-Path $d \"muxen-agent.old.$PID.exe\") }\n\
- Move-Item -Force (Join-Path $d 'muxen-agent.upload.exe') $t\n\
- Get-CimInstance Win32_Process -Filter \"Name='muxen-agent.exe'\" | Where-Object { $_.CommandLine -match ' gui-serve' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }\n\
- Get-ChildItem $d -Filter 'muxen-agent.old.*.exe' | ForEach-Object { Remove-Item -Force $_.FullName -ErrorAction SilentlyContinue }\n\
- & $t hash\n";
- run_ps(spec, script, CTL_TIMEOUT).await.map_err(fail)
+ run_ps(spec, SWAP_PS1, CTL_TIMEOUT).await.map_err(fail)
}
/// Runs a short PowerShell script on a Windows machine (with the user's profile, like workspace commands).
diff --git a/src/ui/terminal/render.rs b/src/ui/terminal/render.rs
index 58bbc95..59af35c 100644
--- a/src/ui/terminal/render.rs
+++ b/src/ui/terminal/render.rs
@@ -104,7 +104,13 @@ fn base_font(window: &Window) -> Font {
};
let mut font = gpui::font(family);
// Icons the font lacks (Nerd Font glyphs): from the bundled symbols font.
- font.fallbacks = Some(gpui::FontFallbacks::from_fonts(crate::ui::assets::NERD_SYMBOLS_NAMES.iter().map(|n| n.to_string()).collect()));
+ // On Windows, then its own monochrome symbols, before the system's
+ // fallback reaches Segoe UI Emoji (Claude Code's ⏺ as a blue square).
+ let mut fallbacks: Vec<String> = crate::ui::assets::NERD_SYMBOLS_NAMES.iter().map(|n| n.to_string()).collect();
+ if cfg!(windows) {
+ fallbacks.extend(["Segoe UI Symbol", "Cascadia Mono", "Consolas"].map(String::from));
+ }
+ font.fallbacks = Some(gpui::FontFallbacks::from_fonts(fallbacks));
// Ligatures would merge cells and break the grid.
font.features = FontFeatures(Arc::new(vec![("calt".into(), 0), ("liga".into(), 0)]));
font
diff --git a/src/ui/theme.rs b/src/ui/theme.rs
index c8ac0cc..9872a3a 100644
--- a/src/ui/theme.rs
+++ b/src/ui/theme.rs
@@ -200,13 +200,18 @@ impl Appearance {
}
}
- /// The theme to show given the system's light/dark appearance.
- pub fn resolve(&self, system: WindowAppearance) -> Theme {
- let dark = match self.mode {
+ /// Whether the dark theme shows, given the system's light/dark appearance.
+ pub fn is_dark(&self, system: WindowAppearance) -> bool {
+ match self.mode {
Mode::Dark => true,
Mode::Light => false,
Mode::System => matches!(system, WindowAppearance::Dark | WindowAppearance::VibrantDark),
- };
+ }
+ }
+
+ /// The theme to show given the system's light/dark appearance.
+ pub fn resolve(&self, system: WindowAppearance) -> Theme {
+ let dark = self.is_dark(system);
let (id, fallback) = if dark { (&self.dark, DEFAULT_DARK) } else { (&self.light, DEFAULT_LIGHT) };
themes::find(id).filter(|p| p.dark == dark).or_else(|| themes::find(fallback)).expect("default themes exist").theme()
}
@@ -230,9 +235,33 @@ pub fn apply(window: &Window, cx: &mut App) {
super::terminal::set_font(&cx.global::<Appearance>().terminal_font);
let style = super::kit::IconStyle::from_id(&cx.global::<Appearance>().icon_style);
super::kit::set_look(super::kit::Look::new(style, &theme));
+ #[cfg(windows)]
+ title_bar(window, cx.global::<Appearance>().is_dark(window.appearance()), &theme);
cx.set_global(theme);
}
+/// Windows draws the title bar: dark when the theme is, in the theme's own
+/// background and text colors (Windows 11; older versions keep theirs).
+#[cfg(windows)]
+fn title_bar(window: &Window, dark: bool, theme: &Theme) {
+ use raw_window_handle::{HasWindowHandle, RawWindowHandle};
+ use windows_sys::Win32::Graphics::Dwm::{DWMWA_CAPTION_COLOR, DWMWA_TEXT_COLOR, DWMWA_USE_IMMERSIVE_DARK_MODE, DwmSetWindowAttribute};
+ let Ok(handle) = HasWindowHandle::window_handle(window) else { return };
+ let RawWindowHandle::Win32(h) = handle.as_raw() else { return };
+ let hwnd = h.hwnd.get() as *mut std::ffi::c_void;
+ // COLORREF: 0x00BBGGRR.
+ let colorref = |c: gpui::Hsla| {
+ let c = gpui::Rgba::from(c);
+ ((c.b * 255.) as u32) << 16 | ((c.g * 255.) as u32) << 8 | (c.r * 255.) as u32
+ };
+ let set = |attribute: i32, value: u32| unsafe {
+ DwmSetWindowAttribute(hwnd, attribute as u32, &value as *const u32 as *const std::ffi::c_void, 4);
+ };
+ set(DWMWA_USE_IMMERSIVE_DARK_MODE as i32, dark as u32);
+ set(DWMWA_CAPTION_COLOR as i32, colorref(theme.sidebar));
+ set(DWMWA_TEXT_COLOR as i32, colorref(theme.text));
+}
+
pub const TERMINAL_FONT_SIZE: f32 = 13.;
pub const TERMINAL_LINE_HEIGHT: f32 = 1.3;
diff --git a/src/ui/usage.rs b/src/ui/usage.rs
index da05331..571c0f0 100644
--- a/src/ui/usage.rs
+++ b/src/ui/usage.rs
@@ -183,7 +183,8 @@ impl Root {
.p(px(16.))
.gap(px(6.))
.child(div().text_size(px(12.)).text_color(theme.text_placeholder).child(label.to_string()))
- .child(div().text_size(px(24.)).font_family(mono_font()).text_color(theme.text).child(value))
+ // A long value (a model's name) smaller, on one line.
+ .child(div().text_size(px(if value.chars().count() > 10 { 17. } else { 24. })).font_family(mono_font()).text_color(theme.text).overflow_hidden().whitespace_nowrap().child(value))
.child(div().text_size(px(12.)).text_color(theme.text_placeholder).overflow_hidden().whitespace_nowrap().child(sub))
};
body = body.child(