From 368d51a9d4bbb731265bba76a1a4ce07a694a4c7 Mon Sep 17 00:00:00 2001 From: henderkes Date: Mon, 9 Nov 2026 14:32:25 +0700 Subject: [PATCH 1/2] gkt window for linux --- README.md | 20 ++++-- VERSION | 2 +- e2e/global-setup.ts | 2 +- e2e/tests/native-window.spec.ts | 38 +++++++++++ server/Native/AppWindowManager.cs | 68 +++++++++++++++---- server/Native/LinuxDesktopIdentity.cs | 94 +++++++++++++++++++++++++++ server/Program.cs | 22 +++++-- web/src/App.tsx | 6 +- web/src/lib/photino.ts | 4 ++ 9 files changed, 226 insertions(+), 30 deletions(-) create mode 100644 e2e/tests/native-window.spec.ts create mode 100644 server/Native/LinuxDesktopIdentity.cs diff --git a/README.md b/README.md index fd1d097..b1c5d25 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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:/?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 @@ -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 diff --git a/VERSION b/VERSION index 74211de..eb6d306 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.1-beta.23 +0.0.1-beta.24 diff --git a/e2e/global-setup.ts b/e2e/global-setup.ts index af5ec84..163f155 100644 --- a/e2e/global-setup.ts +++ b/e2e/global-setup.ts @@ -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 diff --git a/e2e/tests/native-window.spec.ts b/e2e/tests/native-window.spec.ts new file mode 100644 index 0000000..ad1260c --- /dev/null +++ b/e2e/tests/native-window.spec.ts @@ -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) +}) diff --git a/server/Native/AppWindowManager.cs b/server/Native/AppWindowManager.cs index 29eac3b..f683a69 100644 --- a/server/Native/AppWindowManager.cs +++ b/server/Native/AppWindowManager.cs @@ -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) @@ -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 @@ -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) { @@ -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 { @@ -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 @@ -303,6 +343,8 @@ private static void OpenExternalLink(string payload) /// private static void EnableWebViewDraggableRegions() { + if (!OperatingSystem.IsWindows()) return; + const string variable = "WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS"; const string flag = "--enable-features=msWebView2EnableDraggableRegions"; diff --git a/server/Native/LinuxDesktopIdentity.cs b/server/Native/LinuxDesktopIdentity.cs new file mode 100644 index 0000000..cd18ab2 --- /dev/null +++ b/server/Native/LinuxDesktopIdentity.cs @@ -0,0 +1,94 @@ +using System.Reflection; +using System.Runtime.InteropServices; +using System.Runtime.Versioning; + +namespace Slopterm.Server.Native; + +/// +/// 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. +/// +[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); +} diff --git a/server/Program.cs b/server/Program.cs index 1d80c94..dd2337f 100644 --- a/server/Program.cs +++ b/server/Program.cs @@ -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; @@ -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). @@ -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"); diff --git a/web/src/App.tsx b/web/src/App.tsx index f4f7580..dba5dcc 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -8,7 +8,7 @@ import { ReconnectingPane } from './components/ReconnectingPane' import { SectionContent } from './components/SectionContent' import { ConfirmDialog } from './components/ConfirmDialog' import { TitleBar } from './components/TitleBar' -import { isDesktopApp } from './lib/photino' +import { hasCustomTitleBar } from './lib/photino' import { isAndroidApp } from './lib/androidBridge' import { checkForUpdate, @@ -502,7 +502,7 @@ function App() { return (
- {isDesktopApp && ( + {hasCustomTitleBar && ( setSidebarCollapsed((v) => !v)} @@ -517,7 +517,7 @@ function App() { collapsed={sidebarCollapsed} onToggleCollapsed={() => setSidebarCollapsed((v) => !v)} updateAvailable={updateAvailable} - hideChromeControls={isDesktopApp} + hideChromeControls={hasCustomTitleBar} />
Date: Mon, 9 Nov 2026 14:48:03 +0700 Subject: [PATCH 2/2] test: wait for toolbar panels and scope sidebar navigation --- e2e/tests/keyboard-toolbar.spec.ts | 6 +++++- e2e/tests/vault-helpers.ts | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/e2e/tests/keyboard-toolbar.spec.ts b/e2e/tests/keyboard-toolbar.spec.ts index 3f6a9a7..7259fae 100644 --- a/e2e/tests/keyboard-toolbar.spec.ts +++ b/e2e/tests/keyboard-toolbar.spec.ts @@ -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') diff --git a/e2e/tests/vault-helpers.ts b/e2e/tests/vault-helpers.ts index 64ed0b4..2440fc6 100644 --- a/e2e/tests/vault-helpers.ts +++ b/e2e/tests/vault-helpers.ts @@ -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.