Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ A cross-platform (Linux, macOS, Windows) SSH/FTP terminal client in the spirit o
[Termius](https://termius.com/), built by [gwdevhub](https://github.com/gwdevhub).

- React + xterm.js front-end
- .NET backend (SSH.NET) for SSH/SFTP, served locally — no bundled browser, point your own
browser at the printed `localhost` URL
- .NET backend (SSH.NET) for SSH/SFTP, served locally in a native desktop window on
Windows and Linux — no bundled browser
- End-to-end encrypted vault with cross-device sync
- No telemetry, no ads, no accounts — see [PRIVACY.md](./PRIVACY.md) for what's stored locally
and the handful of servers slopterm ever talks to
Expand All @@ -19,10 +19,11 @@ a single working terminal tab. No saved hosts, vault, or sync yet. See
```sh
cd web
npm install
npm run build # builds the React UI into ../server/wwwroot
npm run build # builds the React UI into ../core/wwwroot

cd ../server
dotnet run # prints a http://127.0.0.1:<port>/?token=... URL - open it in a browser
dotnet run # opens a native window on Windows/Linux desktops
# For browser-only use: dotnet run -- --no-window
```

## Building a standalone executable
Expand All @@ -39,8 +40,15 @@ with the .NET runtime, all dependencies, and the entire React UI embedded inside

**On Windows, the published exe has no console window** — look for a tray icon instead;
click it (or its right-click menu's "Open") to open the app in its own window (or bring
it back to focus if it's already open), and "Quit" to stop it. Linux/macOS builds still
print the URL to the console for now (see `AGENTS.md`'s System tray section).
it back to focus if it's already open), and "Quit" to stop it.

**On Linux, launching the executable opens a native GTK window** with the system's title
bar and window controls. Closing it quits the app; close-to-tray is Windows-only. Install
GTK 3, WebKitGTK 4.1 and libnotify using your distribution's package manager. If a native
webview dependency is missing, slopterm falls back to your browser. Headless Linux sessions
and macOS print the browser URL; `--no-window` explicitly selects browser-only mode.
On desktop startup, slopterm registers its icon and a hidden desktop entry under
`$XDG_DATA_HOME` (default `~/.local/share`) so Wayland displays the app icon correctly.

**Or just grab a prebuilt one:** every push to `main` automatically builds and publishes
Windows/Linux/macOS executables to the repo's
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1-beta.23
0.0.1-beta.24
2 changes: 1 addition & 1 deletion e2e/global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default async function globalSetup() {
const sshConfigPath = resolve(CONTEXT_DIR, 'ssh_config')
writeFileSync(sshConfigPath, `Host e2e-ssh-config-host\n HostName 127.0.0.1\n Port ${sshPort}\n User ${SSH_USERNAME}\n`)

const serverProcess = spawn('dotnet', ['run', '--no-launch-profile'], {
const serverProcess = spawn('dotnet', ['run', '--no-launch-profile', '--', '--no-window'], {
cwd: SERVER_DIR,
env: { ...process.env, SLOPTERM_VAULT_DIR: vaultDir, SLOPTERM_SSH_CONFIG_PATH: sshConfigPath },
}) as ChildProcessWithoutNullStreams
Expand Down
6 changes: 5 additions & 1 deletion e2e/tests/keyboard-toolbar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,12 @@ test.describe('with touch emulation', () => {
// toolbar - the sidebar has its own "Snippets" nav button.
const snippetsKey = page.locator('[aria-label="Terminal keys"]').getByRole('button', { name: 'Snippets' })
await snippetsKey.click()
expect(await hideCount()).toBe(2)
// Toolbar presses wait for the composition bridge before opening a panel.
await expect(snippetsKey).toHaveAttribute('aria-expanded', 'true')
await expect.poll(hideCount).toBe(2)
await snippetsKey.click()
await expect(snippetsKey).toHaveAttribute('aria-expanded', 'false')
expect(await hideCount()).toBe(2)

await closeTab(page, tabLabel)
await gotoSection(page, 'Hosts')
Expand Down
38 changes: 38 additions & 0 deletions e2e/tests/native-window.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { test, expect } from '@playwright/test'
import { readFileSync } from 'node:fs'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'

const HERE = dirname(fileURLToPath(import.meta.url))
const { baseUrl } = JSON.parse(readFileSync(resolve(HERE, '../.tmp/context.json'), 'utf8')) as { baseUrl: string }

for (const nativeFrame of [true, false]) {
test(`native window with ${nativeFrame ? 'system' : 'custom'} title bar keeps navigation accessible`, async ({ page }) => {
await page.addInitScript(() => {
Object.defineProperty(window, 'external', {
value: { sendMessage() {}, receiveMessage() {} },
configurable: true,
})
})
await page.goto(baseUrl + (nativeFrame ? '#nativeFrame=1' : ''))

if (nativeFrame) {
// The initial authentication redirect must preserve the frame hint, including on reload.
await expect(page).toHaveURL(/\/#nativeFrame=1$/)
await page.reload()
await expect(page.getByRole('button', { name: 'Minimize', exact: true })).toHaveCount(0)
await expect(page.getByRole('button', { name: 'Collapse sidebar', exact: true })).toBeVisible()
await expect(page.getByRole('button', { name: 'Settings', exact: true })).toBeVisible()
} else {
await expect(page.getByRole('button', { name: 'Minimize', exact: true })).toBeVisible()
await page.getByRole('button', { name: 'Menu', exact: true }).click()
await expect(page.getByRole('menuitem', { name: 'Settings', exact: true })).toBeVisible()
}
})
}

test('a browser URL cannot enable native window controls', async ({ page }) => {
await page.goto(baseUrl + '#nativeFrame=1')
await expect(page.getByRole('button', { name: 'Collapse sidebar', exact: true })).toBeVisible()
await expect(page.getByRole('button', { name: 'Minimize', exact: true })).toHaveCount(0)
})
6 changes: 3 additions & 3 deletions e2e/tests/vault-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { expect, type Page } from '@playwright/test'
export const E2E_VAULT_PASSWORD = 'e2e-shared-test-master-password'

export function gotoSection(page: Page, name: string) {
// Exact match avoids substring collisions; the mobile overlay's same-named button is
// excluded from the accessibility tree via display:none at the desktop test viewport.
return page.getByRole('button', { name, exact: true }).click()
// The terminal toolbar also has a Snippets button. Scope section navigation to the
// sidebar; its mobile counterpart is hidden at the desktop test viewport.
return page.getByRole('navigation').getByRole('button', { name, exact: true }).click()
}

// Closing a tab opens a ConfirmDialog (Close/Cancel), so every caller needs both clicks.
Expand Down
68 changes: 55 additions & 13 deletions server/Native/AppWindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,23 @@ private static void RunWindow(string url)

try
{
// Chromeless so the React app can draw its own Termius-style title bar; the window
// stays resizable and draggable via CSS -webkit-app-region: drag.
var window = new PhotinoWindow().SetTitle("slopterm").SetChromeless(true);
if (OperatingSystem.IsLinux())
{
LinuxDesktopIdentity.Configure();
// Photino calls gtk_init, which exits rather than throwing on an invalid
// display. Initialize safely on the same UI thread before entering Photino.
XInitThreads();
if (gtk_init_check(nint.Zero, nint.Zero) == 0)
{
Console.WriteLine("No usable Linux display. Use the browser URL printed above.");
return;
}
}

// WebKitGTK doesn't implement WebView2's draggable CSS regions or Win32 drag
// messages. Let the Linux window manager provide move/resize/window controls.
var nativeFrame = OperatingSystem.IsLinux();
var window = new PhotinoWindow().SetTitle("slopterm").SetChromeless(!nativeFrame);

var iconPath = EmbeddedIcon.ExtractToTempFile();
if (iconPath is not null)
Expand All @@ -152,11 +166,19 @@ private static void RunWindow(string url)
else
{
const int defaultWidth = 1100, defaultHeight = 720;
var screenW = OperatingSystem.IsWindows() ? GetSystemMetrics(SmCxScreen) : 1280;
var screenH = OperatingSystem.IsWindows() ? GetSystemMetrics(SmCyScreen) : 800;
var x = Math.Max(0, (screenW - defaultWidth) / 2);
var y = Math.Max(0, (screenH - defaultHeight) / 2);
window.SetLocation(new Point(x, y)).SetSize(new Size(defaultWidth, defaultHeight));
window.SetSize(new Size(defaultWidth, defaultHeight));
if (nativeFrame)
{
window.SetUseOsDefaultLocation(true);
}
else
{
var screenW = OperatingSystem.IsWindows() ? GetSystemMetrics(SmCxScreen) : 1280;
var screenH = OperatingSystem.IsWindows() ? GetSystemMetrics(SmCyScreen) : 800;
var x = Math.Max(0, (screenW - defaultWidth) / 2);
var y = Math.Max(0, (screenH - defaultHeight) / 2);
window.SetLocation(new Point(x, y));
}
}

// Shared by Alt+F4 and the title-bar close button; save before minimizing since
Expand Down Expand Up @@ -233,7 +255,9 @@ void HandleClose(PhotinoWindow w)
return true;
});

window.Load(new Uri(url));
// A fragment survives the authentication redirect that strips the token query.
// The renderer keeps its sidebar controls when the OS supplies the title bar.
window.Load(new Uri(nativeFrame ? url + "#nativeFrame=1" : url));

lock (Lock)
{
Expand Down Expand Up @@ -261,14 +285,21 @@ void HandleClose(PhotinoWindow w)

WindowReady.Set();
ReportMissingRuntime(ex);
var fallbackProcess = BrowserLauncher.Launch(url);
if (fallbackProcess is not null)
try
{
lock (Lock)
var fallbackProcess = BrowserLauncher.Launch(url);
if (fallbackProcess is not null)
{
FallbackBrowserProcesses.Add(fallbackProcess);
lock (Lock)
{
FallbackBrowserProcesses.Add(fallbackProcess);
}
}
}
catch (Exception browserException)
{
Console.WriteLine($"Couldn't open a browser: {browserException.Message}. Use the URL printed above.");
}
}
finally
{
Expand All @@ -277,9 +308,18 @@ void HandleClose(PhotinoWindow w)
_window = null;
_creating = false;
}
WindowReady.Set();
}
}

[SupportedOSPlatform("linux")]
[DllImport("libX11.so.6")]
private static extern int XInitThreads();

[SupportedOSPlatform("linux")]
[DllImport("libgtk-3.so.0")]
private static extern int gtk_init_check(nint argc, nint argv);

private static void OpenExternalLink(string payload)
{
try
Expand All @@ -303,6 +343,8 @@ private static void OpenExternalLink(string payload)
/// </summary>
private static void EnableWebViewDraggableRegions()
{
if (!OperatingSystem.IsWindows()) return;

const string variable = "WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS";
const string flag = "--enable-features=msWebView2EnableDraggableRegions";

Expand Down
94 changes: 94 additions & 0 deletions server/Native/LinuxDesktopIdentity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

namespace Slopterm.Server.Native;

/// <summary>
/// Wayland shells resolve icons from the desktop entry matching the window's app_id;
/// GTK's per-window PNG only supplies an icon on X11. Configure before GTK initializes.
/// </summary>
[SupportedOSPlatform("linux")]
internal static class LinuxDesktopIdentity
{
internal const string AppId = "com.gwdevhub.slopterm";

public static void Configure()
{
try
{
g_set_prgname(AppId);
g_set_application_name("slopterm");
gdk_set_program_class(AppId);

var dataHome = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
if (string.IsNullOrEmpty(dataHome) || !Path.IsPathFullyQualified(dataHome))
{
dataHome = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share");
}

// Persist the icon: a desktop shell may resolve it after the temporary files
// from this launch have gone away. Use the same embedded artwork as Windows.
var iconPath = Path.Combine(dataHome, "slopterm", "app.png");
using var icon = typeof(LinuxDesktopIdentity).Assembly.GetManifestResourceStream("Slopterm.Server.Native.app.png");
if (icon is null || Environment.ProcessPath is not { } executable) return;
using var bytes = new MemoryStream();
icon.CopyTo(bytes);
WriteIfChanged(iconPath, bytes.ToArray());

var command = QuoteArgument(executable);
// A development launch uses the dotnet host; a published app uses its apphost.
if (Path.GetFileName(executable) == "dotnet" && Assembly.GetEntryAssembly()?.Location is { Length: > 0 } assemblyPath)
{
command += " " + QuoteArgument(assemblyPath);
}

var entry = "[Desktop Entry]\n" +
"Type=Application\nName=slopterm\n" +
$"Exec={EscapeValue(command)}\n" +
$"Icon={EscapeValue(iconPath)}\n" +
$"StartupWMClass={AppId}\n" +
"Terminal=false\nNoDisplay=true\nCategories=Network;TerminalEmulator;\n";
// This is shell identity metadata, not an extra launcher in the user's menu.
WriteIfChanged(Path.Combine(dataHome, "applications", AppId + ".desktop"),
System.Text.Encoding.UTF8.GetBytes(entry));
}
catch (Exception ex)
{
// A read-only profile or missing GTK must not prevent the app from opening.
Console.WriteLine($"Couldn't register the Linux app icon: {ex.Message}");
}
}

private static string QuoteArgument(string value) => "\"" + value
.Replace("\\", "\\\\").Replace("\"", "\\\"").Replace("`", "\\`")
.Replace("$", "\\$").Replace("%", "%%") + "\"";

private static string EscapeValue(string value) => value.Replace("\\", "\\\\")
.Replace("\n", "\\n").Replace("\r", "\\r").Replace("\t", "\\t");

private static void WriteIfChanged(string path, byte[] contents)
{
if (File.Exists(path) && File.ReadAllBytes(path).AsSpan().SequenceEqual(contents)) return;
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
var temporary = path + "." + Guid.NewGuid().ToString("N") + ".tmp";
try
{
File.WriteAllBytes(temporary, contents);
File.Move(temporary, path, overwrite: true);
}
finally
{
File.Delete(temporary);
}
}

[DllImport("libglib-2.0.so.0")]
private static extern void g_set_prgname([MarshalAs(UnmanagedType.LPUTF8Str)] string name);

[DllImport("libglib-2.0.so.0")]
private static extern void g_set_application_name([MarshalAs(UnmanagedType.LPUTF8Str)] string name);

[DllImport("libgdk-3.so.0")]
private static extern void gdk_set_program_class([MarshalAs(UnmanagedType.LPUTF8Str)] string name);
}
22 changes: 16 additions & 6 deletions server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
CrashLogger.Install();
CrashLogger.LogPhase("process starting");

var host = SloptermHost.Start(args);
// Keep this desktop-only switch out of ASP.NET's key/value command-line parser.
var noWindow = args.Contains("--no-window", StringComparer.Ordinal);
var host = SloptermHost.Start(args.Where(arg => arg != "--no-window").ToArray());
var app = host.App;
var launchUrl = host.LaunchUrl;
var vault = host.Vault;
Expand Down Expand Up @@ -84,12 +86,12 @@ void Quit()
app.Lifetime.StopApplication();
}

// Closing the window quits by default; Settings CloseToTray opts into minimize-to-tray.
// Closing the window quits; Windows alone has a tray for the CloseToTray setting.
// The flag is read live at each close, so toggling it takes effect without a restart.
AppWindowManager.Configure(() => vault.GetSettings().CloseToTray, Quit);
AppWindowManager.Configure(() => OperatingSystem.IsWindows() && vault.GetSettings().CloseToTray, Quit);

WindowsTrayIcon? trayIcon = null;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (OperatingSystem.IsWindows() && !noWindow)
{
// No console window on the published build - the tray icon is the only way to reach
// the app (Open focuses/creates the window, Quit stops it).
Expand All @@ -104,12 +106,20 @@ void Quit()
}
else
{
// No tray icon on Linux/macOS yet (see AGENTS.md's system tray section) - printing
// the URL to the console is still the only way to reach the app there.
// Keep a browser entry point for headless runs and missing native dependencies.
Console.WriteLine();
Console.WriteLine("slopterm is running. Open this URL in your browser:");
Console.WriteLine($" {launchUrl}");
Console.WriteLine();

// GTK exits the process if it cannot connect to a display. Skip native startup on
// headless machines; AppWindowManager also checks stale/unreachable displays safely.
if (OperatingSystem.IsLinux() && !noWindow &&
(!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("DISPLAY")) ||
!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("WAYLAND_DISPLAY"))))
{
OpenWindow();
}
}

CrashLogger.LogPhase("running");
Expand Down
Loading
Loading