GitHub improvements
This commit is contained in:
@@ -51,11 +51,11 @@ Built with [Wails v2](https://wails.io/) (Go backend, HTML/CSS/JS frontend, [xte
|
||||
|
||||
### What You'll Need
|
||||
|
||||
| Tool | Version | Where to get it |
|
||||
|------|---------|-----------------|
|
||||
| Go | 1.23+ | [golang.org/dl](https://golang.org/dl/) |
|
||||
| Node.js | 18+ | [nodejs.org](https://nodejs.org/) |
|
||||
| Wails CLI | v2 | `go install github.com/wailsapp/wails/v2/cmd/wails@latest` |
|
||||
| Tool | Version | Where to get it |
|
||||
| --------- | ------- | ---------------------------------------------------------- |
|
||||
| Go | 1.23+ | [golang.org/dl](https://golang.org/dl/) |
|
||||
| Node.js | 18+ | [nodejs.org](https://nodejs.org/) |
|
||||
| Wails CLI | v2 | `go install github.com/wailsapp/wails/v2/cmd/wails@latest` |
|
||||
|
||||
> **Linux users:** you'll also need GTK and WebKit system libraries. Run `wails doctor` to check your setup.
|
||||
|
||||
@@ -80,23 +80,23 @@ If you just want to connect to a server without setting up a full profile, press
|
||||
|
||||
All shortcuts use **Cmd** on macOS and **Ctrl** on Windows/Linux.
|
||||
|
||||
| Shortcut | Action |
|
||||
|----------|--------|
|
||||
| Cmd + K | Open command palette |
|
||||
| Cmd + N | New connection |
|
||||
| Cmd + W | Close current tab |
|
||||
| Cmd + Tab | Next tab |
|
||||
| Cmd + Shift + Tab | Previous tab |
|
||||
| Cmd + 1–9 | Switch to tab by number |
|
||||
| Cmd + , | Open settings |
|
||||
| Cmd + F | Find in terminal |
|
||||
| Cmd + Shift + D | Split pane vertically |
|
||||
| Cmd + Shift + E | Split pane horizontally |
|
||||
| Cmd + Shift + R | Toggle session recording |
|
||||
| Cmd + Shift + B | Toggle broadcast input mode |
|
||||
| Cmd + Shift + S | Open snippet library |
|
||||
| Cmd + Shift + Q | Quick connect |
|
||||
| F11 | Toggle fullscreen (Windows/Linux) |
|
||||
| Shortcut | Action |
|
||||
| ----------------- | --------------------------------- |
|
||||
| Cmd + K | Open command palette |
|
||||
| Cmd + N | New connection |
|
||||
| Cmd + W | Close current tab |
|
||||
| Cmd + Tab | Next tab |
|
||||
| Cmd + Shift + Tab | Previous tab |
|
||||
| Cmd + 1–9 | Switch to tab by number |
|
||||
| Cmd + , | Open settings |
|
||||
| Cmd + F | Find in terminal |
|
||||
| Cmd + Shift + D | Split pane vertically |
|
||||
| Cmd + Shift + E | Split pane horizontally |
|
||||
| Cmd + Shift + R | Toggle session recording |
|
||||
| Cmd + Shift + B | Toggle broadcast input mode |
|
||||
| Cmd + Shift + S | Open snippet library |
|
||||
| Cmd + Shift + Q | Quick connect |
|
||||
| F11 | Toggle fullscreen (Windows/Linux) |
|
||||
|
||||
---
|
||||
|
||||
@@ -156,7 +156,7 @@ Press **Cmd+Shift+S** to open the snippet library. Save frequently-used commands
|
||||
Press **Cmd+F** to open the search overlay on the active terminal. Features include:
|
||||
|
||||
- Case-sensitive toggle (**Aa** button)
|
||||
- Regular expression toggle (**.*** button)
|
||||
- Regular expression toggle (**.\*** button)
|
||||
- Match count indicator
|
||||
- Navigate through matches with up/down arrows or Enter/Shift+Enter
|
||||
|
||||
@@ -203,13 +203,13 @@ Nexus Terminal takes credential storage seriously. Your passwords and private ke
|
||||
|
||||
### How the Encryption Works
|
||||
|
||||
| Detail | Value |
|
||||
|--------|-------|
|
||||
| Cipher | AES-256-GCM |
|
||||
| Detail | Value |
|
||||
| -------------- | -------------------------------------------------- |
|
||||
| Cipher | AES-256-GCM |
|
||||
| Key derivation | Argon2id — 128 MiB memory, 3 iterations, 4 threads |
|
||||
| Key length | 256 bits (32 bytes) |
|
||||
| Salt | 32 random bytes (unique per vault) |
|
||||
| Nonce | Random, prepended to ciphertext |
|
||||
| Key length | 256 bits (32 bytes) |
|
||||
| Salt | 32 random bytes (unique per vault) |
|
||||
| Nonce | Random, prepended to ciphertext |
|
||||
|
||||
### TOTP/2FA
|
||||
|
||||
@@ -272,13 +272,13 @@ frontend/
|
||||
|
||||
## Building & Testing
|
||||
|
||||
| Command | What it does |
|
||||
|---------|-------------|
|
||||
| `make deps` | Install Go modules and npm packages |
|
||||
| Command | What it does |
|
||||
| ------------ | --------------------------------------------------------- |
|
||||
| `make deps` | Install Go modules and npm packages |
|
||||
| `make build` | Production build → `build/bin/nexus-terminal.app` (macOS) |
|
||||
| `make dev` | Development mode with hot reload |
|
||||
| `make test` | Run all Go tests (`go test ./... -v -count=1`) |
|
||||
| `make lint` | Run golangci-lint |
|
||||
| `make dev` | Development mode with hot reload |
|
||||
| `make test` | Run all Go tests (`go test ./... -v -count=1`) |
|
||||
| `make lint` | Run golangci-lint |
|
||||
|
||||
To run tests for a single package:
|
||||
|
||||
@@ -322,11 +322,11 @@ Then reopen your terminal so `gcc` is on `PATH` and retry `build.ps1`.
|
||||
|
||||
## Data Locations
|
||||
|
||||
| Platform | Database | Vault | Recordings |
|
||||
|----------|----------|-------|------------|
|
||||
| macOS | `~/Library/Application Support/NexusTerminal/nexus.db` | `.../vault` | `.../recordings/` |
|
||||
| Linux | `~/.config/NexusTerminal/nexus.db` | `.../vault` | `.../recordings/` |
|
||||
| Windows | `%APPDATA%\NexusTerminal\nexus.db` | `...\vault` | `...\recordings\` |
|
||||
| Platform | Database | Vault | Recordings |
|
||||
| -------- | ------------------------------------------------------ | ----------- | ----------------- |
|
||||
| macOS | `~/Library/Application Support/NexusTerminal/nexus.db` | `.../vault` | `.../recordings/` |
|
||||
| Linux | `~/.config/NexusTerminal/nexus.db` | `.../vault` | `.../recordings/` |
|
||||
| Windows | `%APPDATA%\NexusTerminal\nexus.db` | `...\vault` | `...\recordings\` |
|
||||
|
||||
The database uses SQLite in WAL (Write-Ahead Logging) mode. Migrations are embedded at compile time and applied automatically on startup.
|
||||
|
||||
@@ -360,9 +360,11 @@ Check the character encoding setting on the connection profile. Most modern serv
|
||||
|
||||
**Build fails with "wails: command not found"**
|
||||
Install the Wails CLI:
|
||||
|
||||
```bash
|
||||
go install github.com/wailsapp/wails/v2/cmd/wails@latest
|
||||
```
|
||||
|
||||
Make sure `$GOPATH/bin` (or `$HOME/go/bin`) is in your `PATH`.
|
||||
|
||||
---
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"fixed": {
|
||||
"file_version": "{{.Info.ProductVersion}}"
|
||||
},
|
||||
"info": {
|
||||
"0000": {
|
||||
"ProductVersion": "{{.Info.ProductVersion}}",
|
||||
"CompanyName": "{{.Info.CompanyName}}",
|
||||
"FileDescription": "{{.Info.ProductName}}",
|
||||
"LegalCopyright": "{{.Info.Copyright}}",
|
||||
"ProductName": "{{.Info.ProductName}}",
|
||||
"Comments": "{{.Info.Comments}}"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
||||
<assemblyIdentity type="win32" name="com.wails.{{.Name}}" version="{{.Info.ProductVersion}}.0" processorArchitecture="*"/>
|
||||
<dependency>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
<asmv3:application>
|
||||
<asmv3:windowsSettings>
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware> <!-- fallback for Windows 7 and 8 -->
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">permonitorv2,permonitor</dpiAwareness> <!-- falls back to per-monitor if per-monitor v2 is not supported -->
|
||||
</asmv3:windowsSettings>
|
||||
</asmv3:application>
|
||||
</assembly>
|
||||
+236
-146
@@ -1,104 +1,166 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Nexus Terminal</title>
|
||||
|
||||
<!-- Vendor styles -->
|
||||
<link rel="stylesheet" href="/src/css/lib/xterm.css">
|
||||
<link rel="stylesheet" href="/src/css/lib/xterm.css" />
|
||||
|
||||
<!-- Design system -->
|
||||
<link rel="stylesheet" href="/src/css/tokens.css">
|
||||
<link rel="stylesheet" href="/src/css/base.css">
|
||||
<link rel="stylesheet" href="/src/css/components.css">
|
||||
<link rel="stylesheet" href="/src/css/layout.css">
|
||||
<link rel="stylesheet" href="/src/css/sidebar.css">
|
||||
<link rel="stylesheet" href="/src/css/tabs.css">
|
||||
<link rel="stylesheet" href="/src/css/terminal.css">
|
||||
<link rel="stylesheet" href="/src/css/splitpane.css">
|
||||
<link rel="stylesheet" href="/src/css/recordings.css">
|
||||
<link rel="stylesheet" href="/src/css/sftp.css">
|
||||
<link rel="stylesheet" href="/src/css/forms.css">
|
||||
<link rel="stylesheet" href="/src/css/modals.css">
|
||||
<link rel="stylesheet" href="/src/css/github.css">
|
||||
</head>
|
||||
<body>
|
||||
<link rel="stylesheet" href="/src/css/tokens.css" />
|
||||
<link rel="stylesheet" href="/src/css/base.css" />
|
||||
<link rel="stylesheet" href="/src/css/components.css" />
|
||||
<link rel="stylesheet" href="/src/css/layout.css" />
|
||||
<link rel="stylesheet" href="/src/css/sidebar.css" />
|
||||
<link rel="stylesheet" href="/src/css/tabs.css" />
|
||||
<link rel="stylesheet" href="/src/css/terminal.css" />
|
||||
<link rel="stylesheet" href="/src/css/splitpane.css" />
|
||||
<link rel="stylesheet" href="/src/css/recordings.css" />
|
||||
<link rel="stylesheet" href="/src/css/sftp.css" />
|
||||
<link rel="stylesheet" href="/src/css/forms.css" />
|
||||
<link rel="stylesheet" href="/src/css/modals.css" />
|
||||
<link rel="stylesheet" href="/src/css/github.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="app" class="app">
|
||||
|
||||
<!-- ============================================================
|
||||
<!-- ============================================================
|
||||
Sidebar — connection manager
|
||||
============================================================ -->
|
||||
<aside class="sidebar" id="sidebar">
|
||||
<div class="sidebar-header wails-drag">
|
||||
<div class="sidebar-logo">
|
||||
<!-- Terminal prompt icon -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"
|
||||
fill="none" stroke="currentColor" stroke-width="2"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<polyline points="4 17 10 11 4 5"></polyline>
|
||||
<line x1="12" y1="19" x2="20" y2="19"></line>
|
||||
</svg>
|
||||
<span class="sidebar-title">Nexus Terminal</span>
|
||||
</div>
|
||||
</div>
|
||||
<aside class="sidebar" id="sidebar">
|
||||
<div class="sidebar-header wails-drag">
|
||||
<div class="sidebar-logo">
|
||||
<!-- Terminal prompt icon -->
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="18"
|
||||
height="18"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<polyline points="4 17 10 11 4 5"></polyline>
|
||||
<line x1="12" y1="19" x2="20" y2="19"></line>
|
||||
</svg>
|
||||
<span class="sidebar-title">Nexus Terminal</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sidebar-search">
|
||||
<div class="search-wrapper">
|
||||
<input type="text"
|
||||
class="search-input"
|
||||
id="profile-search"
|
||||
placeholder="Search connections…"
|
||||
autocomplete="off"
|
||||
spellcheck="false">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sidebar-search">
|
||||
<div class="search-wrapper">
|
||||
<input
|
||||
type="text"
|
||||
class="search-input"
|
||||
id="profile-search"
|
||||
placeholder="Search connections…"
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav class="sidebar-nav" id="sidebar-nav">
|
||||
<!-- Dynamically managed by sidebar.js -->
|
||||
<div id="sidebar-profiles" class="sidebar-profiles"></div>
|
||||
</nav>
|
||||
<nav class="sidebar-nav" id="sidebar-nav">
|
||||
<!-- Dynamically managed by sidebar.js -->
|
||||
<div id="sidebar-profiles" class="sidebar-profiles"></div>
|
||||
</nav>
|
||||
|
||||
<div class="sidebar-footer">
|
||||
<button class="btn btn-ghost btn-sm" id="btn-new-connection" title="New Connection">
|
||||
<span>+ New</span>
|
||||
</button>
|
||||
<button class="btn btn-ghost btn-icon btn-sm" id="btn-import" title="Import Profiles">
|
||||
<!-- Upload icon -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24"
|
||||
fill="none" stroke="currentColor" stroke-width="2"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
|
||||
<polyline points="17 8 12 3 7 8"></polyline>
|
||||
<line x1="12" y1="3" x2="12" y2="15"></line>
|
||||
</svg>
|
||||
</button>
|
||||
<button class="btn btn-ghost btn-icon btn-sm" id="btn-export" title="Export Profiles">
|
||||
<!-- Download icon -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24"
|
||||
fill="none" stroke="currentColor" stroke-width="2"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
|
||||
<polyline points="7 10 12 15 17 10"></polyline>
|
||||
<line x1="12" y1="15" x2="12" y2="3"></line>
|
||||
</svg>
|
||||
</button>
|
||||
<button class="btn btn-ghost btn-icon btn-sm" id="btn-recordings" title="Session Recordings">
|
||||
<!-- Film icon -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24"
|
||||
fill="none" stroke="currentColor" stroke-width="2"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="12" cy="12" r="10"></circle>
|
||||
<circle cx="12" cy="12" r="3"></circle>
|
||||
</svg>
|
||||
</button>
|
||||
<button class="btn btn-ghost btn-icon btn-sm" id="btn-settings" title="Settings">
|
||||
<!-- Cog icon -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24"
|
||||
fill="none" stroke="currentColor" stroke-width="2"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="12" cy="12" r="3"></circle>
|
||||
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0
|
||||
<div class="sidebar-footer">
|
||||
<button
|
||||
class="btn btn-ghost btn-sm"
|
||||
id="btn-new-connection"
|
||||
title="New Connection"
|
||||
>
|
||||
<span>+ New</span>
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-ghost btn-icon btn-sm"
|
||||
id="btn-import"
|
||||
title="Import Profiles"
|
||||
>
|
||||
<!-- Upload icon -->
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
|
||||
<polyline points="17 8 12 3 7 8"></polyline>
|
||||
<line x1="12" y1="3" x2="12" y2="15"></line>
|
||||
</svg>
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-ghost btn-icon btn-sm"
|
||||
id="btn-export"
|
||||
title="Export Profiles"
|
||||
>
|
||||
<!-- Download icon -->
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
|
||||
<polyline points="7 10 12 15 17 10"></polyline>
|
||||
<line x1="12" y1="15" x2="12" y2="3"></line>
|
||||
</svg>
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-ghost btn-icon btn-sm"
|
||||
id="btn-recordings"
|
||||
title="Session Recordings"
|
||||
>
|
||||
<!-- Film icon -->
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<circle cx="12" cy="12" r="10"></circle>
|
||||
<circle cx="12" cy="12" r="3"></circle>
|
||||
</svg>
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-ghost btn-icon btn-sm"
|
||||
id="btn-settings"
|
||||
title="Settings"
|
||||
>
|
||||
<!-- Cog icon -->
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<circle cx="12" cy="12" r="3"></circle>
|
||||
<path
|
||||
d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0
|
||||
0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65
|
||||
0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0
|
||||
0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9
|
||||
@@ -114,73 +176,101 @@
|
||||
2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65
|
||||
1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51
|
||||
1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65
|
||||
1.65 0 0 0-1.51 1z"></path>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
1.65 0 0 0-1.51 1z"
|
||||
></path>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<!-- ============================================================
|
||||
<!-- ============================================================
|
||||
Tab bar — session tabs
|
||||
============================================================ -->
|
||||
<div class="tab-bar" id="tab-bar">
|
||||
<div class="tab-list" id="tab-list">
|
||||
<!-- Tabs are injected dynamically by JS -->
|
||||
</div>
|
||||
<button class="tab-new" id="btn-new-tab" title="New Tab">+</button>
|
||||
<button class="tab-broadcast" id="btn-broadcast" title="Toggle Broadcast Mode (Ctrl+Shift+B)">
|
||||
<!-- Broadcast icon (loudspeaker) -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24"
|
||||
fill="none" stroke="currentColor" stroke-width="2"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M19.69 14a6.9 6.9 0 0 0 .31-2 6.9 6.9 0 0 0-.31-2"></path>
|
||||
<path d="M22.82 16.18a10 10 0 0 0 0-8.36"></path>
|
||||
<path d="M1 12s3-7 9-7 9 7 9 7-3 7-9 7-9-7-9-7z"></path>
|
||||
<circle cx="12" cy="12" r="3"></circle>
|
||||
</svg>
|
||||
</button>
|
||||
<div class="tab-bar" id="tab-bar">
|
||||
<div class="tab-list" id="tab-list">
|
||||
<!-- Tabs are injected dynamically by JS -->
|
||||
</div>
|
||||
<button class="tab-new" id="btn-new-tab" title="New Tab">+</button>
|
||||
<button
|
||||
class="tab-broadcast"
|
||||
id="btn-broadcast"
|
||||
title="Toggle Broadcast Mode (Ctrl+Shift+B)"
|
||||
>
|
||||
<!-- Broadcast icon (loudspeaker) -->
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="12"
|
||||
height="12"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M19.69 14a6.9 6.9 0 0 0 .31-2 6.9 6.9 0 0 0-.31-2"></path>
|
||||
<path d="M22.82 16.18a10 10 0 0 0 0-8.36"></path>
|
||||
<path d="M1 12s3-7 9-7 9 7 9 7-3 7-9 7-9-7-9-7z"></path>
|
||||
<circle cx="12" cy="12" r="3"></circle>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- ============================================================
|
||||
<!-- ============================================================
|
||||
Workspace — terminal area
|
||||
============================================================ -->
|
||||
<main class="workspace" id="workspace">
|
||||
<!-- Empty state — shown when no sessions are active -->
|
||||
<div class="empty-state" id="empty-state">
|
||||
<div class="empty-state-icon">
|
||||
<!-- Terminal icon -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24"
|
||||
fill="none" stroke="currentColor" stroke-width="1.5"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<polyline points="4 17 10 11 4 5"></polyline>
|
||||
<line x1="12" y1="19" x2="20" y2="19"></line>
|
||||
</svg>
|
||||
</div>
|
||||
<h2>No active sessions</h2>
|
||||
<p>Select a connection from the sidebar or create a new one to get started.</p>
|
||||
<div class="empty-state-actions">
|
||||
<button class="btn btn-primary" id="btn-empty-connect">New Connection</button>
|
||||
<button class="btn btn-secondary" id="btn-empty-quick">Quick Connect</button>
|
||||
</div>
|
||||
</div>
|
||||
<main class="workspace" id="workspace">
|
||||
<!-- Empty state — shown when no sessions are active -->
|
||||
<div class="empty-state" id="empty-state">
|
||||
<div class="empty-state-icon">
|
||||
<!-- Terminal icon -->
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="48"
|
||||
height="48"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<polyline points="4 17 10 11 4 5"></polyline>
|
||||
<line x1="12" y1="19" x2="20" y2="19"></line>
|
||||
</svg>
|
||||
</div>
|
||||
<h2>No active sessions</h2>
|
||||
<p>
|
||||
Select a connection from the sidebar or create a new one to get
|
||||
started.
|
||||
</p>
|
||||
<div class="empty-state-actions">
|
||||
<button class="btn btn-primary" id="btn-empty-connect">
|
||||
New Connection
|
||||
</button>
|
||||
<button class="btn btn-secondary" id="btn-empty-quick">
|
||||
Quick Connect
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Session panels are injected here dynamically by tabs.js -->
|
||||
<div id="panel-container" class="panel-container"></div>
|
||||
</main>
|
||||
<!-- Session panels are injected here dynamically by tabs.js -->
|
||||
<div id="panel-container" class="panel-container"></div>
|
||||
</main>
|
||||
|
||||
<!-- ============================================================
|
||||
<!-- ============================================================
|
||||
Status bar
|
||||
============================================================ -->
|
||||
<footer class="status-bar" id="status-bar">
|
||||
<span id="status-connection">
|
||||
<span class="status-dot is-disconnected"></span>
|
||||
Disconnected
|
||||
</span>
|
||||
<span id="status-protocol"></span>
|
||||
<span id="status-session-count">0 sessions</span>
|
||||
<span class="status-spacer"></span>
|
||||
<span id="status-vault">🔒 Locked</span>
|
||||
</footer>
|
||||
<footer class="status-bar" id="status-bar">
|
||||
<span id="status-connection">
|
||||
<span class="status-dot is-disconnected"></span>
|
||||
Disconnected
|
||||
</span>
|
||||
<span id="status-protocol"></span>
|
||||
<span id="status-session-count">0 sessions</span>
|
||||
<span class="status-spacer"></span>
|
||||
<span id="status-vault">🔒 Locked</span>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<!-- Modal container (dynamically populated) -->
|
||||
@@ -215,5 +305,5 @@
|
||||
<script src="/src/js/splitpane.js"></script>
|
||||
<script src="/src/js/snippets.js"></script>
|
||||
<script src="/src/js/app.js"></script>
|
||||
</body>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -4,38 +4,38 @@
|
||||
*
|
||||
* Run automatically via the postinstall hook in package.json.
|
||||
*/
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const frontendDir = path.resolve(__dirname, '..');
|
||||
const frontendDir = path.resolve(__dirname, "..");
|
||||
|
||||
// Mapping: source (relative to node_modules) → destination (relative to frontend/)
|
||||
const assets = [
|
||||
{
|
||||
src: 'xterm/css/xterm.css',
|
||||
dest: 'src/css/lib/xterm.css',
|
||||
src: "xterm/css/xterm.css",
|
||||
dest: "src/css/lib/xterm.css",
|
||||
},
|
||||
{
|
||||
src: 'xterm/lib/xterm.js',
|
||||
dest: 'src/js/lib/xterm.min.js',
|
||||
src: "xterm/lib/xterm.js",
|
||||
dest: "src/js/lib/xterm.min.js",
|
||||
},
|
||||
{
|
||||
src: 'xterm-addon-fit/lib/xterm-addon-fit.js',
|
||||
dest: 'src/js/lib/xterm-addon-fit.min.js',
|
||||
src: "xterm-addon-fit/lib/xterm-addon-fit.js",
|
||||
dest: "src/js/lib/xterm-addon-fit.min.js",
|
||||
},
|
||||
{
|
||||
src: 'xterm-addon-search/lib/xterm-addon-search.js',
|
||||
dest: 'src/js/lib/xterm-addon-search.min.js',
|
||||
src: "xterm-addon-search/lib/xterm-addon-search.js",
|
||||
dest: "src/js/lib/xterm-addon-search.min.js",
|
||||
},
|
||||
{
|
||||
src: 'xterm-addon-unicode11/lib/xterm-addon-unicode11.js',
|
||||
dest: 'src/js/lib/xterm-addon-unicode11.min.js',
|
||||
src: "xterm-addon-unicode11/lib/xterm-addon-unicode11.js",
|
||||
dest: "src/js/lib/xterm-addon-unicode11.min.js",
|
||||
},
|
||||
{
|
||||
src: 'xterm-addon-web-links/lib/xterm-addon-web-links.js',
|
||||
dest: 'src/js/lib/xterm-addon-web-links.min.js',
|
||||
src: "xterm-addon-web-links/lib/xterm-addon-web-links.js",
|
||||
dest: "src/js/lib/xterm-addon-web-links.min.js",
|
||||
},
|
||||
];
|
||||
|
||||
@@ -53,7 +53,7 @@ function ensureDir(filePath) {
|
||||
* Copies a single asset, logging the result.
|
||||
*/
|
||||
function copyAsset(entry) {
|
||||
const srcPath = path.join(frontendDir, 'node_modules', entry.src);
|
||||
const srcPath = path.join(frontendDir, "node_modules", entry.src);
|
||||
const destPath = path.join(frontendDir, entry.dest);
|
||||
|
||||
if (!fs.existsSync(srcPath)) {
|
||||
@@ -69,7 +69,7 @@ function copyAsset(entry) {
|
||||
|
||||
// --- Main ---
|
||||
|
||||
console.log('[copy-assets] Copying xterm library files…');
|
||||
console.log("[copy-assets] Copying xterm library files…");
|
||||
|
||||
let failures = 0;
|
||||
for (const entry of assets) {
|
||||
@@ -84,4 +84,4 @@ if (failures > 0) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('[copy-assets] All assets copied successfully.');
|
||||
console.log("[copy-assets] All assets copied successfully.");
|
||||
|
||||
@@ -174,6 +174,12 @@
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.github-repo-commit {
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.github-repo-name {
|
||||
font-size: var(--font-size-sm);
|
||||
font-weight: 600;
|
||||
@@ -190,6 +196,35 @@
|
||||
letter-spacing: 0.03em;
|
||||
}
|
||||
|
||||
.github-repo-actions {
|
||||
margin-left: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.github-repo-download,
|
||||
.github-repo-visit {
|
||||
padding: 0 6px;
|
||||
height: 18px;
|
||||
border-radius: var(--radius-full);
|
||||
border: 1px solid var(--border-subtle);
|
||||
background: var(--bg-tertiary);
|
||||
color: var(--text-secondary);
|
||||
font-size: 10px;
|
||||
letter-spacing: 0.04em;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s, color 0.15s, border-color 0.15s;
|
||||
}
|
||||
|
||||
.github-repo-download:hover,
|
||||
.github-repo-visit:hover {
|
||||
background: var(--bg-hover);
|
||||
color: var(--protocol-github);
|
||||
border-color: var(--protocol-github);
|
||||
}
|
||||
|
||||
.github-repo-private {
|
||||
background: rgba(255, 167, 38, 0.12);
|
||||
color: #ffa726;
|
||||
|
||||
@@ -53,6 +53,34 @@
|
||||
padding-bottom: var(--space-2);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------
|
||||
Bulk actions bar (multi-select)
|
||||
----------------------------------------------------------------------- */
|
||||
.sidebar-bulk-actions {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 2;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: var(--space-2);
|
||||
padding: var(--space-2) var(--space-3);
|
||||
background: var(--bg-secondary);
|
||||
border-bottom: 1px solid var(--border-subtle);
|
||||
}
|
||||
|
||||
.sidebar-bulk-count {
|
||||
font-size: var(--text-xs);
|
||||
color: var(--text-secondary);
|
||||
font-weight: var(--weight-semibold);
|
||||
}
|
||||
|
||||
.sidebar-bulk-buttons {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-1);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------
|
||||
Sections (Favourites, Recent, All Connections)
|
||||
----------------------------------------------------------------------- */
|
||||
@@ -167,6 +195,15 @@
|
||||
background: var(--bg-active);
|
||||
}
|
||||
|
||||
.sidebar-item-selected {
|
||||
background: var(--accent-muted);
|
||||
box-shadow: inset 0 0 0 1px var(--accent);
|
||||
}
|
||||
|
||||
.sidebar-item-selected .sidebar-item-name {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
/* Active / selected state */
|
||||
.sidebar-item.active {
|
||||
background: var(--accent-muted);
|
||||
|
||||
+981
-705
File diff suppressed because it is too large
Load Diff
@@ -53,6 +53,18 @@ class GitHubViewer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the status line for a session.
|
||||
* @param {string} sessionID
|
||||
* @param {string} message
|
||||
*/
|
||||
setStatus(sessionID, message) {
|
||||
const viewer = this._viewers.get(sessionID);
|
||||
if (viewer) {
|
||||
viewer.setStatus(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles an error event for a session.
|
||||
* @param {string} sessionID
|
||||
@@ -165,6 +177,16 @@ class GitHubViewerInstance {
|
||||
this._renderList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the status line with a custom message.
|
||||
* @param {string} message
|
||||
*/
|
||||
setStatus(message) {
|
||||
if (!this._statusEl) return;
|
||||
this._statusEl.classList.remove('github-viewer-status-error');
|
||||
this._statusEl.textContent = message || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an error message in the status bar.
|
||||
* @param {string} message
|
||||
@@ -272,6 +294,7 @@ class GitHubViewerInstance {
|
||||
nameEl.textContent = repo.name;
|
||||
topRow.appendChild(nameEl);
|
||||
|
||||
|
||||
if (repo.private) {
|
||||
const badge = createElement('span', 'github-repo-badge github-repo-private');
|
||||
badge.textContent = 'Private';
|
||||
@@ -288,8 +311,46 @@ class GitHubViewerInstance {
|
||||
topRow.appendChild(badge);
|
||||
}
|
||||
|
||||
const actions = createElement('div', 'github-repo-actions');
|
||||
|
||||
const downloadBtn = createElement('button', 'github-repo-download', {
|
||||
textContent: 'ZIP',
|
||||
title: 'Download repository as zip',
|
||||
});
|
||||
downloadBtn.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
this._downloadRepo(repo);
|
||||
});
|
||||
actions.appendChild(downloadBtn);
|
||||
|
||||
const visitLink = createElement('button', 'github-repo-visit', {
|
||||
textContent: 'Visit',
|
||||
title: 'Open repository in browser',
|
||||
});
|
||||
visitLink.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
if (repo.htmlURL) {
|
||||
if (window.runtime && window.runtime.BrowserOpenURL) {
|
||||
window.runtime.BrowserOpenURL(repo.htmlURL);
|
||||
} else {
|
||||
window.open(repo.htmlURL, '_blank');
|
||||
}
|
||||
}
|
||||
});
|
||||
actions.appendChild(visitLink);
|
||||
|
||||
topRow.appendChild(actions);
|
||||
|
||||
card.appendChild(topRow);
|
||||
|
||||
if (repo.latestCommitter && repo.latestCommitAt) {
|
||||
const commitLine = createElement('div', 'github-repo-commit');
|
||||
const when = new Date(repo.latestCommitAt);
|
||||
const whenText = isNaN(when.getTime()) ? repo.latestCommitAt : when.toLocaleString();
|
||||
commitLine.textContent = `Last commit: ${whenText} by ${repo.latestCommitter}`;
|
||||
card.appendChild(commitLine);
|
||||
}
|
||||
|
||||
// Description
|
||||
if (repo.description) {
|
||||
const desc = createElement('div', 'github-repo-desc');
|
||||
@@ -324,6 +385,25 @@ class GitHubViewerInstance {
|
||||
return card;
|
||||
}
|
||||
|
||||
async _downloadRepo(repo) {
|
||||
if (!this._statusEl) return;
|
||||
const ref = repo.defaultBranch || '';
|
||||
this._statusEl.classList.remove('github-viewer-status-error');
|
||||
this._statusEl.textContent = `Downloading ${repo.fullName}...`;
|
||||
|
||||
try {
|
||||
await window.go.api.Service.DownloadGitHubRepoArchive(
|
||||
this.sessionID,
|
||||
repo.fullName,
|
||||
ref,
|
||||
);
|
||||
this._updateStatus();
|
||||
} catch (err) {
|
||||
this._statusEl.textContent = `⚠ Download failed: ${err}`;
|
||||
this._statusEl.classList.add('github-viewer-status-error');
|
||||
}
|
||||
}
|
||||
|
||||
async _manualRefresh() {
|
||||
if (!this._statusEl) return;
|
||||
this._statusEl.textContent = 'Refreshing…';
|
||||
|
||||
@@ -183,12 +183,19 @@ class ProfileEditor {
|
||||
const testBtn = createElement('button', 'btn btn-outline', { textContent: 'Test' });
|
||||
const saveBtn = createElement('button', 'btn btn-primary', { textContent: isNew ? 'Create' : 'Save' });
|
||||
const connectBtn = createElement('button', 'btn btn-accent', { textContent: isNew ? 'Create & Connect' : 'Save & Connect' });
|
||||
const deleteBtn = !isNew
|
||||
? createElement('button', 'btn btn-danger', { textContent: 'Delete' })
|
||||
: null;
|
||||
|
||||
cancelBtn.addEventListener('click', () => this.close());
|
||||
testBtn.addEventListener('click', () => this._testConnection());
|
||||
saveBtn.addEventListener('click', () => this._handleSave(false));
|
||||
connectBtn.addEventListener('click', () => this._handleSave(true));
|
||||
if (deleteBtn) {
|
||||
deleteBtn.addEventListener('click', () => this._handleDelete());
|
||||
}
|
||||
|
||||
if (deleteBtn) footer.appendChild(deleteBtn);
|
||||
footer.appendChild(cancelBtn);
|
||||
footer.appendChild(testBtn);
|
||||
footer.appendChild(saveBtn);
|
||||
@@ -1464,6 +1471,22 @@ class ProfileEditor {
|
||||
}
|
||||
}
|
||||
|
||||
/** @private */
|
||||
async _handleDelete() {
|
||||
const ok = await this._confirmDelete();
|
||||
if (!ok) return;
|
||||
|
||||
try {
|
||||
await window.go.api.Service.DeleteProfile(this._profile.id);
|
||||
this.app.state.removeProfile(this._profile.id);
|
||||
this.app.sidebar.render();
|
||||
this.app.notifications.success('Profile deleted');
|
||||
this.close();
|
||||
} catch (err) {
|
||||
this.app.notifications.error('Failed to delete profile: ' + err);
|
||||
}
|
||||
}
|
||||
|
||||
/** @private */
|
||||
async _testConnection() {
|
||||
this._collectFormValues();
|
||||
@@ -1485,6 +1508,51 @@ class ProfileEditor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a confirmation modal for profile deletion.
|
||||
* @returns {Promise<boolean>}
|
||||
* @private
|
||||
*/
|
||||
_confirmDelete() {
|
||||
return new Promise((resolve) => {
|
||||
const backdrop = createElement('div', 'modal-backdrop');
|
||||
const modal = createElement('div', 'modal modal-sm');
|
||||
const label = escapeHtml(this._profile.displayName || this._profile.host || 'Untitled');
|
||||
modal.innerHTML = `
|
||||
<div class="modal-header">
|
||||
<h3 class="modal-title">Delete Profile</h3>
|
||||
<button class="btn btn-icon btn-xs modal-close">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p style="font-size:var(--text-sm);color:var(--text-secondary)">
|
||||
Delete <strong>${label}</strong>? This cannot be undone.
|
||||
</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-sm confirm-cancel">Cancel</button>
|
||||
<button class="btn btn-sm btn-danger confirm-ok">Delete</button>
|
||||
</div>
|
||||
`;
|
||||
backdrop.appendChild(modal);
|
||||
document.body.appendChild(backdrop);
|
||||
requestAnimationFrame(() => {
|
||||
backdrop.classList.add('is-visible');
|
||||
modal.classList.add('is-visible');
|
||||
});
|
||||
|
||||
const close = (val) => {
|
||||
backdrop.classList.remove('is-visible');
|
||||
modal.classList.remove('is-visible');
|
||||
setTimeout(() => backdrop.remove(), 200);
|
||||
resolve(val);
|
||||
};
|
||||
modal.querySelector('.modal-close').addEventListener('click', () => close(false));
|
||||
modal.querySelector('.confirm-cancel').addEventListener('click', () => close(false));
|
||||
modal.querySelector('.confirm-ok').addEventListener('click', () => close(true));
|
||||
backdrop.addEventListener('click', (e) => { if (e.target === backdrop) close(false); });
|
||||
});
|
||||
}
|
||||
|
||||
// ── Utilities ────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,9 +42,9 @@ class Settings {
|
||||
/**
|
||||
* Opens the settings modal.
|
||||
*/
|
||||
async open() {
|
||||
async open(tabKey) {
|
||||
this._prefs = JSON.parse(JSON.stringify(this.app.state.preferences));
|
||||
this._activeTab = 'general';
|
||||
this._activeTab = tabKey || this._activeTab || 'general';
|
||||
|
||||
try {
|
||||
this._knownHosts = await window.go.api.Service.ListKnownHosts() || [];
|
||||
@@ -55,6 +55,15 @@ class Settings {
|
||||
this._render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the settings modal on a specific tab.
|
||||
* @param {string} tabKey
|
||||
*/
|
||||
async openTab(tabKey) {
|
||||
this._activeTab = tabKey || 'general';
|
||||
return this.open(this._activeTab);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the settings modal.
|
||||
*/
|
||||
|
||||
+314
-2
@@ -19,11 +19,22 @@ class Sidebar {
|
||||
this.el = document.getElementById('sidebar-profiles');
|
||||
this.searchQuery = '';
|
||||
|
||||
/** @type {Set<string>} */
|
||||
this.selectedProfiles = new Set();
|
||||
|
||||
// Section collapse state
|
||||
this.collapsedSections = new Set();
|
||||
|
||||
// Dismiss context menus on any outside click
|
||||
document.addEventListener('click', () => dismissContextMenus());
|
||||
|
||||
if (this.el) {
|
||||
this.el.addEventListener('click', (e) => {
|
||||
if (!e.target.closest('.sidebar-item') && this.selectedProfiles.size > 0) {
|
||||
this._clearSelection();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ── Public API ───────────────────────────────────────────────────
|
||||
@@ -41,6 +52,11 @@ class Sidebar {
|
||||
this.el.innerHTML = '';
|
||||
|
||||
const profiles = this._filteredProfiles();
|
||||
this._syncSelection(profiles);
|
||||
|
||||
if (this.selectedProfiles.size > 0) {
|
||||
this.el.appendChild(this._renderBulkActions());
|
||||
}
|
||||
|
||||
// Favourites
|
||||
const favourites = profiles.filter((p) => p.favourite);
|
||||
@@ -178,6 +194,10 @@ class Sidebar {
|
||||
dataset: { profileId: profile.id },
|
||||
});
|
||||
|
||||
if (this.selectedProfiles.has(profile.id)) {
|
||||
item.classList.add('sidebar-item-selected');
|
||||
}
|
||||
|
||||
// Highlight if this profile's session is active
|
||||
const activeSession = this.app.state.activeSessionId
|
||||
? this.app.state.getSession(this.app.state.activeSessionId)
|
||||
@@ -227,8 +247,21 @@ class Sidebar {
|
||||
item.appendChild(star);
|
||||
}
|
||||
|
||||
// Click → connect
|
||||
item.addEventListener('click', () => {
|
||||
// Prevent mousedown text selection in WKWebView
|
||||
item.addEventListener('mousedown', (e) => e.preventDefault());
|
||||
|
||||
// Click → connect / multi-select
|
||||
item.addEventListener('click', (e) => {
|
||||
const multi = e.metaKey || e.ctrlKey;
|
||||
if (multi) {
|
||||
e.preventDefault();
|
||||
this._toggleSelection(profile.id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.selectedProfiles.size > 0) {
|
||||
this._clearSelection();
|
||||
}
|
||||
this.app.connectProfile(profile.id);
|
||||
});
|
||||
|
||||
@@ -406,6 +439,285 @@ class Sidebar {
|
||||
});
|
||||
}
|
||||
|
||||
// ── Multi-select + bulk actions ─────────────────────────────────
|
||||
|
||||
/**
|
||||
* Removes selections that are no longer visible in the filtered list.
|
||||
* @param {Array<Object>} profiles
|
||||
* @private
|
||||
*/
|
||||
_syncSelection(profiles) {
|
||||
const valid = new Set(profiles.map((p) => p.id));
|
||||
for (const id of [...this.selectedProfiles]) {
|
||||
if (!valid.has(id)) this.selectedProfiles.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
/** @private */
|
||||
_toggleSelection(profileId) {
|
||||
if (this.selectedProfiles.has(profileId)) {
|
||||
this.selectedProfiles.delete(profileId);
|
||||
} else {
|
||||
this.selectedProfiles.add(profileId);
|
||||
}
|
||||
this.render();
|
||||
}
|
||||
|
||||
/** @private */
|
||||
_clearSelection() {
|
||||
if (this.selectedProfiles.size === 0) return;
|
||||
this.selectedProfiles.clear();
|
||||
this.render();
|
||||
}
|
||||
|
||||
/** @private */
|
||||
_getSelectedProfiles() {
|
||||
return this.app.state.profiles.filter((p) => this.selectedProfiles.has(p.id));
|
||||
}
|
||||
|
||||
/** @private */
|
||||
_renderBulkActions() {
|
||||
const bar = createElement('div', 'sidebar-bulk-actions');
|
||||
const count = createElement('span', 'sidebar-bulk-count', {
|
||||
textContent: `${this.selectedProfiles.size} selected`,
|
||||
});
|
||||
bar.appendChild(count);
|
||||
|
||||
const actions = createElement('div', 'sidebar-bulk-buttons');
|
||||
const makeBtn = (label, handler, className) => {
|
||||
const btn = createElement('button', `btn btn-xs ${className || ''}`.trim(), {
|
||||
textContent: label,
|
||||
});
|
||||
btn.addEventListener('click', handler);
|
||||
actions.appendChild(btn);
|
||||
};
|
||||
|
||||
makeBtn('Connect', () => this._bulkConnect());
|
||||
makeBtn('Disconnect', () => this._bulkDisconnect(), 'btn-outline');
|
||||
makeBtn('Tags', () => this._bulkEditTags(), 'btn-outline');
|
||||
makeBtn('Move Group', () => this._bulkMoveGroup(), 'btn-outline');
|
||||
makeBtn('Clear', () => this._clearSelection(), 'btn-ghost');
|
||||
|
||||
bar.appendChild(actions);
|
||||
return bar;
|
||||
}
|
||||
|
||||
/** @private */
|
||||
_bulkConnect() {
|
||||
const profiles = this._getSelectedProfiles();
|
||||
for (const p of profiles) {
|
||||
this.app.connectProfile(p.id);
|
||||
}
|
||||
this._clearSelection();
|
||||
}
|
||||
|
||||
/** @private */
|
||||
async _bulkDisconnect() {
|
||||
const sessions = this.app.state.getAllSessions()
|
||||
.filter((s) => this.selectedProfiles.has(s.profileId));
|
||||
if (sessions.length === 0) {
|
||||
this.app.notifications.info('No active sessions to disconnect');
|
||||
return;
|
||||
}
|
||||
|
||||
const ok = await this._confirmBulkDisconnect(sessions.length);
|
||||
if (!ok) return;
|
||||
|
||||
for (const s of sessions) {
|
||||
await this.app.closeSessionImmediate(s.id);
|
||||
}
|
||||
this._clearSelection();
|
||||
}
|
||||
|
||||
/** @private */
|
||||
async _bulkEditTags() {
|
||||
const result = await this._promptTagEdit();
|
||||
if (!result) return;
|
||||
|
||||
const profiles = this._getSelectedProfiles();
|
||||
for (const p of profiles) {
|
||||
const updated = JSON.parse(JSON.stringify(p));
|
||||
const existing = updated.tags || [];
|
||||
if (result.mode === 'replace') {
|
||||
updated.tags = result.tags;
|
||||
} else {
|
||||
const merged = new Set([...existing, ...result.tags]);
|
||||
updated.tags = [...merged];
|
||||
}
|
||||
|
||||
try {
|
||||
const saved = await window.go.api.Service.UpdateProfile(updated);
|
||||
this.app.state.updateProfile(saved);
|
||||
} catch (err) {
|
||||
this.app.notifications.error('Failed to update tags: ' + err);
|
||||
}
|
||||
}
|
||||
|
||||
this.render();
|
||||
this._clearSelection();
|
||||
}
|
||||
|
||||
/** @private */
|
||||
async _bulkMoveGroup() {
|
||||
const folder = await this._promptGroupMove();
|
||||
if (folder === null) return;
|
||||
|
||||
const profiles = this._getSelectedProfiles();
|
||||
for (const p of profiles) {
|
||||
const updated = JSON.parse(JSON.stringify(p));
|
||||
updated.folder = folder;
|
||||
try {
|
||||
const saved = await window.go.api.Service.UpdateProfile(updated);
|
||||
this.app.state.updateProfile(saved);
|
||||
} catch (err) {
|
||||
this.app.notifications.error('Failed to move group: ' + err);
|
||||
}
|
||||
}
|
||||
|
||||
this.render();
|
||||
this._clearSelection();
|
||||
}
|
||||
|
||||
/** @private */
|
||||
_confirmBulkDisconnect(count) {
|
||||
return new Promise((resolve) => {
|
||||
const backdrop = createElement('div', 'modal-backdrop');
|
||||
const modal = createElement('div', 'modal modal-sm');
|
||||
modal.innerHTML = `
|
||||
<div class="modal-header">
|
||||
<h3 class="modal-title">Disconnect Sessions</h3>
|
||||
<button class="btn btn-icon btn-xs modal-close">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p style="font-size:var(--text-sm);color:var(--text-secondary)">
|
||||
Disconnect ${count} active ${count === 1 ? 'session' : 'sessions'}?
|
||||
</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-sm confirm-cancel">Cancel</button>
|
||||
<button class="btn btn-sm btn-danger confirm-ok">Disconnect</button>
|
||||
</div>
|
||||
`;
|
||||
backdrop.appendChild(modal);
|
||||
document.body.appendChild(backdrop);
|
||||
requestAnimationFrame(() => {
|
||||
backdrop.classList.add('is-visible');
|
||||
modal.classList.add('is-visible');
|
||||
});
|
||||
|
||||
const close = (val) => {
|
||||
backdrop.classList.remove('is-visible');
|
||||
modal.classList.remove('is-visible');
|
||||
setTimeout(() => backdrop.remove(), 200);
|
||||
resolve(val);
|
||||
};
|
||||
modal.querySelector('.modal-close').addEventListener('click', () => close(false));
|
||||
modal.querySelector('.confirm-cancel').addEventListener('click', () => close(false));
|
||||
modal.querySelector('.confirm-ok').addEventListener('click', () => close(true));
|
||||
backdrop.addEventListener('click', (e) => { if (e.target === backdrop) close(false); });
|
||||
});
|
||||
}
|
||||
|
||||
/** @private */
|
||||
_promptTagEdit() {
|
||||
return new Promise((resolve) => {
|
||||
const backdrop = createElement('div', 'modal-backdrop');
|
||||
const modal = createElement('div', 'modal modal-sm');
|
||||
modal.innerHTML = `
|
||||
<div class="modal-header">
|
||||
<h3 class="modal-title">Edit Tags</h3>
|
||||
<button class="btn btn-icon btn-xs modal-close">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Tags (comma separated)</label>
|
||||
<input class="form-input tag-input" type="text" placeholder="prod, linux, db" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-sm confirm-cancel">Cancel</button>
|
||||
<button class="btn btn-sm btn-outline confirm-add">Add Tags</button>
|
||||
<button class="btn btn-sm btn-primary confirm-replace">Replace Tags</button>
|
||||
</div>
|
||||
`;
|
||||
backdrop.appendChild(modal);
|
||||
document.body.appendChild(backdrop);
|
||||
requestAnimationFrame(() => {
|
||||
backdrop.classList.add('is-visible');
|
||||
modal.classList.add('is-visible');
|
||||
});
|
||||
|
||||
const input = modal.querySelector('.tag-input');
|
||||
const parseTags = () => {
|
||||
const raw = (input.value || '').split(',');
|
||||
return raw.map((t) => t.trim()).filter((t) => t.length > 0);
|
||||
};
|
||||
|
||||
const close = (val) => {
|
||||
backdrop.classList.remove('is-visible');
|
||||
modal.classList.remove('is-visible');
|
||||
setTimeout(() => backdrop.remove(), 200);
|
||||
resolve(val);
|
||||
};
|
||||
modal.querySelector('.modal-close').addEventListener('click', () => close(null));
|
||||
modal.querySelector('.confirm-cancel').addEventListener('click', () => close(null));
|
||||
modal.querySelector('.confirm-add').addEventListener('click', () => {
|
||||
close({ mode: 'add', tags: parseTags() });
|
||||
});
|
||||
modal.querySelector('.confirm-replace').addEventListener('click', () => {
|
||||
close({ mode: 'replace', tags: parseTags() });
|
||||
});
|
||||
backdrop.addEventListener('click', (e) => { if (e.target === backdrop) close(null); });
|
||||
setTimeout(() => input.focus(), 50);
|
||||
});
|
||||
}
|
||||
|
||||
/** @private */
|
||||
_promptGroupMove() {
|
||||
return new Promise((resolve) => {
|
||||
const backdrop = createElement('div', 'modal-backdrop');
|
||||
const modal = createElement('div', 'modal modal-sm');
|
||||
modal.innerHTML = `
|
||||
<div class="modal-header">
|
||||
<h3 class="modal-title">Move to Group</h3>
|
||||
<button class="btn btn-icon btn-xs modal-close">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Group name</label>
|
||||
<input class="form-input group-input" type="text" placeholder="e.g. Production" />
|
||||
<p style="font-size:var(--text-xs);color:var(--text-secondary);margin-top:6px;">
|
||||
Leave blank to remove the group.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-sm confirm-cancel">Cancel</button>
|
||||
<button class="btn btn-sm btn-primary confirm-ok">Move</button>
|
||||
</div>
|
||||
`;
|
||||
backdrop.appendChild(modal);
|
||||
document.body.appendChild(backdrop);
|
||||
requestAnimationFrame(() => {
|
||||
backdrop.classList.add('is-visible');
|
||||
modal.classList.add('is-visible');
|
||||
});
|
||||
|
||||
const input = modal.querySelector('.group-input');
|
||||
const close = (val) => {
|
||||
backdrop.classList.remove('is-visible');
|
||||
modal.classList.remove('is-visible');
|
||||
setTimeout(() => backdrop.remove(), 200);
|
||||
resolve(val);
|
||||
};
|
||||
modal.querySelector('.modal-close').addEventListener('click', () => close(null));
|
||||
modal.querySelector('.confirm-cancel').addEventListener('click', () => close(null));
|
||||
modal.querySelector('.confirm-ok').addEventListener('click', () => close(input.value.trim()));
|
||||
backdrop.addEventListener('click', (e) => { if (e.target === backdrop) close(null); });
|
||||
setTimeout(() => input.focus(), 50);
|
||||
});
|
||||
}
|
||||
|
||||
// ── Filtering ────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
|
||||
+356
-321
@@ -1,24 +1,24 @@
|
||||
(function() {
|
||||
/**
|
||||
* Nexus Terminal — xterm.js terminal manager.
|
||||
* Creates, manages, and destroys xterm.js instances for SSH and Telnet sessions.
|
||||
* Handles data routing, resizing, and search.
|
||||
*/
|
||||
(function () {
|
||||
/**
|
||||
* Nexus Terminal — xterm.js terminal manager.
|
||||
* Creates, manages, and destroys xterm.js instances for SSH and Telnet sessions.
|
||||
* Handles data routing, resizing, and search.
|
||||
*/
|
||||
|
||||
/* global Terminal, FitAddon, SearchAddon, WebLinksAddon, Unicode11Addon */
|
||||
/* global Terminal, FitAddon, SearchAddon, WebLinksAddon, Unicode11Addon */
|
||||
|
||||
class TerminalManager {
|
||||
class TerminalManager {
|
||||
/**
|
||||
* @param {App} app
|
||||
*/
|
||||
constructor(app) {
|
||||
this.app = app;
|
||||
this.app = app;
|
||||
|
||||
/**
|
||||
* Map of sessionId → { term, fitAddon, searchAddon, observer }.
|
||||
* @type {Map<string, Object>}
|
||||
*/
|
||||
this.terminals = new Map();
|
||||
/**
|
||||
* Map of sessionId → { term, fitAddon, searchAddon, observer }.
|
||||
* @type {Map<string, Object>}
|
||||
*/
|
||||
this.terminals = new Map();
|
||||
}
|
||||
|
||||
// ── Public API ───────────────────────────────────────────────────
|
||||
@@ -33,171 +33,190 @@ class TerminalManager {
|
||||
* @returns {Terminal} The xterm.js Terminal instance.
|
||||
*/
|
||||
createTerminal(sessionId, containerId, profile) {
|
||||
const themeName = (this.app.state.preferences || {}).terminalTheme || 'charcoal';
|
||||
const term = new Terminal({
|
||||
theme: window.NexusTerminal.getTerminalTheme(themeName),
|
||||
fontFamily: profile.terminalFontFamily || 'JetBrains Mono, Menlo, Monaco, Consolas, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", monospace',
|
||||
fontSize: profile.terminalFontSize || 14,
|
||||
scrollback: profile.terminalScrollback || 10000,
|
||||
cursorStyle: profile.terminalCursorStyle || 'block',
|
||||
cursorBlink: true,
|
||||
allowProposedApi: true,
|
||||
convertEol: false,
|
||||
windowsMode: false,
|
||||
const themeName =
|
||||
(this.app.state.preferences || {}).terminalTheme || "charcoal";
|
||||
const term = new Terminal({
|
||||
theme: window.NexusTerminal.getTerminalTheme(themeName),
|
||||
fontFamily:
|
||||
profile.terminalFontFamily ||
|
||||
'JetBrains Mono, Menlo, Monaco, Consolas, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", monospace',
|
||||
fontSize: profile.terminalFontSize || 14,
|
||||
scrollback: profile.terminalScrollback || 10000,
|
||||
cursorStyle: profile.terminalCursorStyle || "block",
|
||||
cursorBlink: true,
|
||||
allowProposedApi: true,
|
||||
convertEol: false,
|
||||
windowsMode: false,
|
||||
});
|
||||
|
||||
// Load addons
|
||||
const fitAddon = new FitAddon.FitAddon();
|
||||
const searchAddon = new SearchAddon.SearchAddon();
|
||||
let webLinksAddon = null;
|
||||
let unicode11Addon = null;
|
||||
|
||||
term.loadAddon(fitAddon);
|
||||
term.loadAddon(searchAddon);
|
||||
|
||||
try {
|
||||
unicode11Addon = new Unicode11Addon.Unicode11Addon();
|
||||
term.loadAddon(unicode11Addon);
|
||||
term.unicode.activeVersion = "11";
|
||||
} catch (_) {
|
||||
// Unicode 11 addon is optional; fall back to default unicode handling.
|
||||
}
|
||||
|
||||
// WebLinksAddon may not always be available
|
||||
try {
|
||||
webLinksAddon = new WebLinksAddon.WebLinksAddon((_event, uri) => {
|
||||
window.runtime.BrowserOpenURL(uri);
|
||||
});
|
||||
term.loadAddon(webLinksAddon);
|
||||
} catch (_) {
|
||||
// Not critical — links just won't be clickable
|
||||
}
|
||||
|
||||
// Load addons
|
||||
const fitAddon = new FitAddon.FitAddon();
|
||||
const searchAddon = new SearchAddon.SearchAddon();
|
||||
let webLinksAddon = null;
|
||||
let unicode11Addon = null;
|
||||
// Open the terminal in the DOM container
|
||||
const container = document.getElementById(containerId);
|
||||
term.open(container);
|
||||
|
||||
term.loadAddon(fitAddon);
|
||||
term.loadAddon(searchAddon);
|
||||
let suppressPasteEvent = false;
|
||||
const attachPasteGuard = () => {
|
||||
const inputEl = term.textarea || container.querySelector("textarea");
|
||||
if (!inputEl) return;
|
||||
inputEl.addEventListener("paste", (e) => {
|
||||
if (!suppressPasteEvent) return;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
suppressPasteEvent = false;
|
||||
});
|
||||
};
|
||||
attachPasteGuard();
|
||||
|
||||
// Right-click context menu on the terminal viewport
|
||||
const termEl = container.querySelector(".xterm");
|
||||
if (termEl) {
|
||||
termEl.addEventListener("contextmenu", (e) => {
|
||||
e.preventDefault();
|
||||
this._showTerminalContextMenu(sessionId, term, e.clientX, e.clientY);
|
||||
});
|
||||
}
|
||||
|
||||
// Force a synchronous layout reflow so the container reports its
|
||||
// true dimensions, then fit the terminal to fill the space.
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
container.offsetHeight;
|
||||
const doFit = () => {
|
||||
try {
|
||||
unicode11Addon = new Unicode11Addon.Unicode11Addon();
|
||||
term.loadAddon(unicode11Addon);
|
||||
term.unicode.activeVersion = '11';
|
||||
fitAddon.fit();
|
||||
} catch (_) {
|
||||
// Unicode 11 addon is optional; fall back to default unicode handling.
|
||||
/* noop */
|
||||
}
|
||||
};
|
||||
doFit();
|
||||
// Belt-and-braces: retry once after a paint in case the initial
|
||||
// reflow dimensions were still stale.
|
||||
requestAnimationFrame(doFit);
|
||||
|
||||
// WebLinksAddon may not always be available
|
||||
// Forward user keystrokes to the backend
|
||||
term.onData((data) => {
|
||||
try {
|
||||
webLinksAddon = new WebLinksAddon.WebLinksAddon((_event, uri) => {
|
||||
window.runtime.BrowserOpenURL(uri);
|
||||
});
|
||||
term.loadAddon(webLinksAddon);
|
||||
const b64 = btoa(data);
|
||||
window.go.api.Service.WriteSession(sessionId, b64);
|
||||
|
||||
// Broadcast to all other connected sessions if enabled
|
||||
if (this.app.state.broadcastMode) {
|
||||
for (const [otherId] of this.terminals) {
|
||||
if (otherId === sessionId) continue;
|
||||
const otherSession = this.app.state.getSession(otherId);
|
||||
if (otherSession && otherSession.state === "connected") {
|
||||
try {
|
||||
window.go.api.Service.WriteSession(otherId, b64);
|
||||
} catch (_) {
|
||||
/* non-critical */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("WriteSession error:", err);
|
||||
}
|
||||
});
|
||||
|
||||
// Clipboard: copy selection on Cmd/Ctrl+C, paste on Cmd/Ctrl+V
|
||||
term.attachCustomKeyEventHandler((e) => {
|
||||
const mod = e.ctrlKey || e.metaKey;
|
||||
|
||||
// Cmd/Ctrl+C — copy selected text (let xterm handle it normally if no selection)
|
||||
if (mod && e.key === "c" && e.type === "keydown") {
|
||||
const selection = term.getSelection();
|
||||
if (selection) {
|
||||
if (window.runtime && window.runtime.ClipboardSetText) {
|
||||
window.runtime.ClipboardSetText(selection);
|
||||
} else {
|
||||
navigator.clipboard.writeText(selection).catch(function () {});
|
||||
}
|
||||
return false; // Prevent xterm from sending Ctrl+C
|
||||
}
|
||||
// No selection — let Ctrl+C pass through as SIGINT
|
||||
return true;
|
||||
}
|
||||
|
||||
// Cmd/Ctrl+V — paste from clipboard
|
||||
if (mod && e.key === "v" && e.type === "keydown") {
|
||||
suppressPasteEvent = true;
|
||||
setTimeout(() => {
|
||||
suppressPasteEvent = false;
|
||||
}, 250);
|
||||
if (window.runtime && window.runtime.ClipboardGetText) {
|
||||
window.runtime
|
||||
.ClipboardGetText()
|
||||
.then(function (text) {
|
||||
if (text) term.paste(text);
|
||||
})
|
||||
.catch(function () {});
|
||||
} else {
|
||||
navigator.clipboard
|
||||
.readText()
|
||||
.then(function (text) {
|
||||
if (text) term.paste(text);
|
||||
})
|
||||
.catch(function () {});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
// Notify backend when terminal dimensions change
|
||||
term.onResize(({ cols, rows }) => {
|
||||
try {
|
||||
window.go.api.Service.ResizeSession(sessionId, cols, rows);
|
||||
} catch (err) {
|
||||
console.error("ResizeSession error:", err);
|
||||
}
|
||||
});
|
||||
|
||||
// Re-fit when the container itself resizes
|
||||
const observer = new ResizeObserver(() => {
|
||||
try {
|
||||
fitAddon.fit();
|
||||
} catch (_) {
|
||||
// Not critical — links just won't be clickable
|
||||
// Ignore transient errors during layout shifts
|
||||
}
|
||||
});
|
||||
observer.observe(container);
|
||||
|
||||
// Open the terminal in the DOM container
|
||||
const container = document.getElementById(containerId);
|
||||
term.open(container);
|
||||
this.terminals.set(sessionId, {
|
||||
term,
|
||||
fitAddon,
|
||||
searchAddon,
|
||||
webLinksAddon,
|
||||
observer,
|
||||
});
|
||||
|
||||
let suppressPasteEvent = false;
|
||||
const attachPasteGuard = () => {
|
||||
const inputEl = term.textarea || container.querySelector('textarea');
|
||||
if (!inputEl) return;
|
||||
inputEl.addEventListener('paste', (e) => {
|
||||
if (!suppressPasteEvent) return;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
suppressPasteEvent = false;
|
||||
});
|
||||
};
|
||||
attachPasteGuard();
|
||||
|
||||
// Right-click context menu on the terminal viewport
|
||||
const termEl = container.querySelector('.xterm');
|
||||
if (termEl) {
|
||||
termEl.addEventListener('contextmenu', (e) => {
|
||||
e.preventDefault();
|
||||
this._showTerminalContextMenu(sessionId, term, e.clientX, e.clientY);
|
||||
});
|
||||
}
|
||||
|
||||
// Force a synchronous layout reflow so the container reports its
|
||||
// true dimensions, then fit the terminal to fill the space.
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
container.offsetHeight;
|
||||
const doFit = () => { try { fitAddon.fit(); } catch (_) { /* noop */ } };
|
||||
doFit();
|
||||
// Belt-and-braces: retry once after a paint in case the initial
|
||||
// reflow dimensions were still stale.
|
||||
requestAnimationFrame(doFit);
|
||||
|
||||
// Forward user keystrokes to the backend
|
||||
term.onData((data) => {
|
||||
try {
|
||||
const b64 = btoa(data);
|
||||
window.go.api.Service.WriteSession(sessionId, b64);
|
||||
|
||||
// Broadcast to all other connected sessions if enabled
|
||||
if (this.app.state.broadcastMode) {
|
||||
for (const [otherId] of this.terminals) {
|
||||
if (otherId === sessionId) continue;
|
||||
const otherSession = this.app.state.getSession(otherId);
|
||||
if (otherSession && otherSession.state === 'connected') {
|
||||
try {
|
||||
window.go.api.Service.WriteSession(otherId, b64);
|
||||
} catch (_) { /* non-critical */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('WriteSession error:', err);
|
||||
}
|
||||
});
|
||||
|
||||
// Clipboard: copy selection on Cmd/Ctrl+C, paste on Cmd/Ctrl+V
|
||||
term.attachCustomKeyEventHandler((e) => {
|
||||
const mod = e.ctrlKey || e.metaKey;
|
||||
|
||||
// Cmd/Ctrl+C — copy selected text (let xterm handle it normally if no selection)
|
||||
if (mod && e.key === 'c' && e.type === 'keydown') {
|
||||
const selection = term.getSelection();
|
||||
if (selection) {
|
||||
if (window.runtime && window.runtime.ClipboardSetText) {
|
||||
window.runtime.ClipboardSetText(selection);
|
||||
} else {
|
||||
navigator.clipboard.writeText(selection).catch(function() {});
|
||||
}
|
||||
return false; // Prevent xterm from sending Ctrl+C
|
||||
}
|
||||
// No selection — let Ctrl+C pass through as SIGINT
|
||||
return true;
|
||||
}
|
||||
|
||||
// Cmd/Ctrl+V — paste from clipboard
|
||||
if (mod && e.key === 'v' && e.type === 'keydown') {
|
||||
suppressPasteEvent = true;
|
||||
setTimeout(() => { suppressPasteEvent = false; }, 250);
|
||||
if (window.runtime && window.runtime.ClipboardGetText) {
|
||||
window.runtime.ClipboardGetText().then(function(text) {
|
||||
if (text) term.paste(text);
|
||||
}).catch(function() {});
|
||||
} else {
|
||||
navigator.clipboard.readText().then(function(text) {
|
||||
if (text) term.paste(text);
|
||||
}).catch(function() {});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
// Notify backend when terminal dimensions change
|
||||
term.onResize(({ cols, rows }) => {
|
||||
try {
|
||||
window.go.api.Service.ResizeSession(sessionId, cols, rows);
|
||||
} catch (err) {
|
||||
console.error('ResizeSession error:', err);
|
||||
}
|
||||
});
|
||||
|
||||
// Re-fit when the container itself resizes
|
||||
const observer = new ResizeObserver(() => {
|
||||
try {
|
||||
fitAddon.fit();
|
||||
} catch (_) {
|
||||
// Ignore transient errors during layout shifts
|
||||
}
|
||||
});
|
||||
observer.observe(container);
|
||||
|
||||
this.terminals.set(sessionId, {
|
||||
term,
|
||||
fitAddon,
|
||||
searchAddon,
|
||||
webLinksAddon,
|
||||
observer,
|
||||
});
|
||||
|
||||
return term;
|
||||
return term;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,15 +225,15 @@ class TerminalManager {
|
||||
* @param {string} base64Data
|
||||
*/
|
||||
handleData(sessionId, base64Data) {
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (!entry) return;
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (!entry) return;
|
||||
|
||||
try {
|
||||
const raw = atob(base64Data);
|
||||
entry.term.write(raw);
|
||||
} catch (err) {
|
||||
console.error('Failed to decode session data:', err);
|
||||
}
|
||||
try {
|
||||
const raw = atob(base64Data);
|
||||
entry.term.write(raw);
|
||||
} catch (err) {
|
||||
console.error("Failed to decode session data:", err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,12 +241,12 @@ class TerminalManager {
|
||||
* @param {string} sessionId
|
||||
*/
|
||||
destroyTerminal(sessionId) {
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (!entry) return;
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (!entry) return;
|
||||
|
||||
entry.observer.disconnect();
|
||||
entry.term.dispose();
|
||||
this.terminals.delete(sessionId);
|
||||
entry.observer.disconnect();
|
||||
entry.term.dispose();
|
||||
this.terminals.delete(sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,28 +254,32 @@ class TerminalManager {
|
||||
* @param {string} sessionId
|
||||
*/
|
||||
showTerminal(sessionId) {
|
||||
for (const [id, entry] of this.terminals) {
|
||||
const panel = document.getElementById(`panel-${id}`);
|
||||
if (panel) {
|
||||
panel.style.display = id === sessionId ? 'flex' : 'none';
|
||||
}
|
||||
for (const [id, entry] of this.terminals) {
|
||||
const panel = document.getElementById(`panel-${id}`);
|
||||
if (panel) {
|
||||
panel.style.display = id === sessionId ? "flex" : "none";
|
||||
}
|
||||
}
|
||||
|
||||
// Re-fit the newly visible terminal
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (entry) {
|
||||
requestAnimationFrame(() => {
|
||||
try { entry.fitAddon.fit(); } catch (_) { /* noop */ }
|
||||
});
|
||||
}
|
||||
// Re-fit the newly visible terminal
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (entry) {
|
||||
requestAnimationFrame(() => {
|
||||
try {
|
||||
entry.fitAddon.fit();
|
||||
} catch (_) {
|
||||
/* noop */
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-fits the currently active terminal to its container.
|
||||
*/
|
||||
fitActive() {
|
||||
const id = this.app.state.activeSessionId;
|
||||
if (id) this.fitSession(id);
|
||||
const id = this.app.state.activeSessionId;
|
||||
if (id) this.fitSession(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -264,12 +287,16 @@ class TerminalManager {
|
||||
* @param {string} sessionId
|
||||
*/
|
||||
fitSession(sessionId) {
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (entry) {
|
||||
requestAnimationFrame(() => {
|
||||
try { entry.fitAddon.fit(); } catch (_) { /* noop */ }
|
||||
});
|
||||
}
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (entry) {
|
||||
requestAnimationFrame(() => {
|
||||
try {
|
||||
entry.fitAddon.fit();
|
||||
} catch (_) {
|
||||
/* noop */
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,25 +310,25 @@ class TerminalManager {
|
||||
* @returns {boolean} Whether a match was found.
|
||||
*/
|
||||
search(sessionId, query, options = {}) {
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (!entry) return false;
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (!entry) return false;
|
||||
|
||||
if (!query) {
|
||||
entry.searchAddon.clearDecorations();
|
||||
return false;
|
||||
}
|
||||
if (!query) {
|
||||
entry.searchAddon.clearDecorations();
|
||||
return false;
|
||||
}
|
||||
|
||||
return entry.searchAddon.findNext(query, {
|
||||
regex: options.regex || false,
|
||||
caseSensitive: options.caseSensitive || false,
|
||||
wholeWord: options.wholeWord || false,
|
||||
decorations: {
|
||||
matchBackground: '#ffa72633',
|
||||
activeMatchBackground: '#4ecdc466',
|
||||
matchBorder: '#ffa726',
|
||||
activeMatchBorder: '#4ecdc4',
|
||||
},
|
||||
});
|
||||
return entry.searchAddon.findNext(query, {
|
||||
regex: options.regex || false,
|
||||
caseSensitive: options.caseSensitive || false,
|
||||
wholeWord: options.wholeWord || false,
|
||||
decorations: {
|
||||
matchBackground: "#ffa72633",
|
||||
activeMatchBackground: "#4ecdc466",
|
||||
matchBorder: "#ffa726",
|
||||
activeMatchBorder: "#4ecdc4",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,13 +339,13 @@ class TerminalManager {
|
||||
* @returns {boolean}
|
||||
*/
|
||||
searchPrevious(sessionId, query, options = {}) {
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (!entry || !query) return false;
|
||||
return entry.searchAddon.findPrevious(query, {
|
||||
regex: options.regex || false,
|
||||
caseSensitive: options.caseSensitive || false,
|
||||
wholeWord: options.wholeWord || false,
|
||||
});
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (!entry || !query) return false;
|
||||
return entry.searchAddon.findPrevious(query, {
|
||||
regex: options.regex || false,
|
||||
caseSensitive: options.caseSensitive || false,
|
||||
wholeWord: options.wholeWord || false,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -326,8 +353,8 @@ class TerminalManager {
|
||||
* @param {string} sessionId
|
||||
*/
|
||||
clearTerminal(sessionId) {
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (entry) entry.term.clear();
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (entry) entry.term.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -335,8 +362,8 @@ class TerminalManager {
|
||||
* @param {string} sessionId
|
||||
*/
|
||||
resetTerminal(sessionId) {
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (entry) entry.term.reset();
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (entry) entry.term.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -344,8 +371,8 @@ class TerminalManager {
|
||||
* @param {string} sessionId
|
||||
*/
|
||||
focusTerminal(sessionId) {
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (entry) entry.term.focus();
|
||||
const entry = this.terminals.get(sessionId);
|
||||
if (entry) entry.term.focus();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -353,10 +380,10 @@ class TerminalManager {
|
||||
* @param {string} themeName
|
||||
*/
|
||||
applyTheme(themeName) {
|
||||
const themeObj = window.NexusTerminal.getTerminalTheme(themeName);
|
||||
for (const [, entry] of this.terminals) {
|
||||
entry.term.options.theme = themeObj;
|
||||
}
|
||||
const themeObj = window.NexusTerminal.getTerminalTheme(themeName);
|
||||
for (const [, entry] of this.terminals) {
|
||||
entry.term.options.theme = themeObj;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Private helpers ──────────────────────────────────────────────
|
||||
@@ -370,95 +397,103 @@ class TerminalManager {
|
||||
* @private
|
||||
*/
|
||||
_showTerminalContextMenu(sessionId, term, x, y) {
|
||||
const { createElement, dismissContextMenus } = window.NexusTerminal;
|
||||
dismissContextMenus();
|
||||
const { createElement, dismissContextMenus } = window.NexusTerminal;
|
||||
dismissContextMenus();
|
||||
|
||||
const hasSelection = term.hasSelection();
|
||||
const menu = createElement('div', 'context-menu');
|
||||
menu.style.left = `${x}px`;
|
||||
menu.style.top = `${y}px`;
|
||||
const hasSelection = term.hasSelection();
|
||||
const menu = createElement("div", "context-menu");
|
||||
menu.style.left = `${x}px`;
|
||||
menu.style.top = `${y}px`;
|
||||
|
||||
const items = [
|
||||
{
|
||||
label: 'Copy',
|
||||
disabled: !hasSelection,
|
||||
action: () => {
|
||||
const text = term.getSelection();
|
||||
if (text) {
|
||||
if (window.runtime && window.runtime.ClipboardSetText) {
|
||||
window.runtime.ClipboardSetText(text);
|
||||
} else {
|
||||
navigator.clipboard.writeText(text).catch(function() {});
|
||||
}
|
||||
this.app.notifications.info('Copied to clipboard');
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Paste',
|
||||
action: () => {
|
||||
if (window.runtime && window.runtime.ClipboardGetText) {
|
||||
window.runtime.ClipboardGetText().then((text) => {
|
||||
if (text) term.paste(text);
|
||||
}).catch(function() {});
|
||||
} else {
|
||||
navigator.clipboard.readText().then((text) => {
|
||||
if (text) term.paste(text);
|
||||
}).catch(function() {});
|
||||
}
|
||||
},
|
||||
},
|
||||
{ divider: true },
|
||||
{
|
||||
label: 'Select All',
|
||||
action: () => term.selectAll(),
|
||||
},
|
||||
{
|
||||
label: 'Find…',
|
||||
action: () => this.app._openTerminalSearch(),
|
||||
},
|
||||
{
|
||||
label: 'Send Snippet…',
|
||||
action: () => this.app.snippets.open(),
|
||||
},
|
||||
{ divider: true },
|
||||
{
|
||||
label: 'Clear Terminal',
|
||||
action: () => term.clear(),
|
||||
},
|
||||
{
|
||||
label: 'Reset Terminal',
|
||||
action: () => term.reset(),
|
||||
},
|
||||
];
|
||||
|
||||
for (const entry of items) {
|
||||
if (entry.divider) {
|
||||
menu.appendChild(createElement('div', 'context-menu-divider'));
|
||||
continue;
|
||||
const items = [
|
||||
{
|
||||
label: "Copy",
|
||||
disabled: !hasSelection,
|
||||
action: () => {
|
||||
const text = term.getSelection();
|
||||
if (text) {
|
||||
if (window.runtime && window.runtime.ClipboardSetText) {
|
||||
window.runtime.ClipboardSetText(text);
|
||||
} else {
|
||||
navigator.clipboard.writeText(text).catch(function () {});
|
||||
}
|
||||
this.app.notifications.info("Copied to clipboard");
|
||||
}
|
||||
const btn = createElement('button', 'context-menu-item', {
|
||||
textContent: entry.label,
|
||||
});
|
||||
if (entry.disabled) {
|
||||
btn.disabled = true;
|
||||
btn.classList.add('context-menu-disabled');
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Paste",
|
||||
action: () => {
|
||||
if (window.runtime && window.runtime.ClipboardGetText) {
|
||||
window.runtime
|
||||
.ClipboardGetText()
|
||||
.then((text) => {
|
||||
if (text) term.paste(text);
|
||||
})
|
||||
.catch(function () {});
|
||||
} else {
|
||||
navigator.clipboard
|
||||
.readText()
|
||||
.then((text) => {
|
||||
if (text) term.paste(text);
|
||||
})
|
||||
.catch(function () {});
|
||||
}
|
||||
btn.addEventListener('click', () => {
|
||||
dismissContextMenus();
|
||||
entry.action();
|
||||
});
|
||||
// Prevent mousedown from causing text deselection in WKWebView
|
||||
btn.addEventListener('mousedown', (e) => e.preventDefault());
|
||||
menu.appendChild(btn);
|
||||
},
|
||||
},
|
||||
{ divider: true },
|
||||
{
|
||||
label: "Select All",
|
||||
action: () => term.selectAll(),
|
||||
},
|
||||
{
|
||||
label: "Find…",
|
||||
action: () => this.app._openTerminalSearch(),
|
||||
},
|
||||
{
|
||||
label: "Send Snippet…",
|
||||
action: () => this.app.snippets.open(),
|
||||
},
|
||||
{ divider: true },
|
||||
{
|
||||
label: "Clear Terminal",
|
||||
action: () => term.clear(),
|
||||
},
|
||||
{
|
||||
label: "Reset Terminal",
|
||||
action: () => term.reset(),
|
||||
},
|
||||
];
|
||||
|
||||
for (const entry of items) {
|
||||
if (entry.divider) {
|
||||
menu.appendChild(createElement("div", "context-menu-divider"));
|
||||
continue;
|
||||
}
|
||||
const btn = createElement("button", "context-menu-item", {
|
||||
textContent: entry.label,
|
||||
});
|
||||
if (entry.disabled) {
|
||||
btn.disabled = true;
|
||||
btn.classList.add("context-menu-disabled");
|
||||
}
|
||||
btn.addEventListener("click", () => {
|
||||
dismissContextMenus();
|
||||
entry.action();
|
||||
});
|
||||
// Prevent mousedown from causing text deselection in WKWebView
|
||||
btn.addEventListener("mousedown", (e) => e.preventDefault());
|
||||
menu.appendChild(btn);
|
||||
}
|
||||
|
||||
document.body.appendChild(menu);
|
||||
document.body.appendChild(menu);
|
||||
|
||||
// Keep within viewport
|
||||
const rect = menu.getBoundingClientRect();
|
||||
if (rect.right > window.innerWidth) menu.style.left = `${window.innerWidth - rect.width - 8}px`;
|
||||
if (rect.bottom > window.innerHeight) menu.style.top = `${window.innerHeight - rect.height - 8}px`;
|
||||
// Keep within viewport
|
||||
const rect = menu.getBoundingClientRect();
|
||||
if (rect.right > window.innerWidth)
|
||||
menu.style.left = `${window.innerWidth - rect.width - 8}px`;
|
||||
if (rect.bottom > window.innerHeight)
|
||||
menu.style.top = `${window.innerHeight - rect.height - 8}px`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -467,12 +502,12 @@ class TerminalManager {
|
||||
* @private
|
||||
*/
|
||||
_buildTheme() {
|
||||
const themeName = (this.app.state.preferences || {}).terminalTheme || 'charcoal';
|
||||
return window.NexusTerminal.getTerminalTheme(themeName);
|
||||
const themeName =
|
||||
(this.app.state.preferences || {}).terminalTheme || "charcoal";
|
||||
return window.NexusTerminal.getTerminalTheme(themeName);
|
||||
}
|
||||
}
|
||||
|
||||
window.NexusTerminal = window.NexusTerminal || {};
|
||||
window.NexusTerminal.TerminalManager = TerminalManager;
|
||||
}
|
||||
|
||||
window.NexusTerminal = window.NexusTerminal || {};
|
||||
window.NexusTerminal.TerminalManager = TerminalManager;
|
||||
})();
|
||||
|
||||
Vendored
+2
@@ -33,6 +33,8 @@ export function DeleteTOTPSecret(arg1:string):Promise<void>;
|
||||
|
||||
export function DisconnectSession(arg1:string):Promise<void>;
|
||||
|
||||
export function DownloadGitHubRepoArchive(arg1:string,arg2:string,arg3:string):Promise<string>;
|
||||
|
||||
export function DuplicateProfile(arg1:string):Promise<models.Profile>;
|
||||
|
||||
export function ExportProfiles(arg1:boolean):Promise<string>;
|
||||
|
||||
@@ -62,6 +62,10 @@ export function DisconnectSession(arg1) {
|
||||
return window['go']['api']['Service']['DisconnectSession'](arg1);
|
||||
}
|
||||
|
||||
export function DownloadGitHubRepoArchive(arg1, arg2, arg3) {
|
||||
return window['go']['api']['Service']['DownloadGitHubRepoArchive'](arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
export function DuplicateProfile(arg1) {
|
||||
return window['go']['api']['Service']['DuplicateProfile'](arg1);
|
||||
}
|
||||
|
||||
@@ -95,6 +95,9 @@ export namespace models {
|
||||
owner: string;
|
||||
description: string;
|
||||
htmlURL: string;
|
||||
defaultBranch: string;
|
||||
latestCommitter: string;
|
||||
latestCommitAt: string;
|
||||
private: boolean;
|
||||
fork: boolean;
|
||||
archived: boolean;
|
||||
@@ -114,6 +117,9 @@ export namespace models {
|
||||
this.owner = source["owner"];
|
||||
this.description = source["description"];
|
||||
this.htmlURL = source["htmlURL"];
|
||||
this.defaultBranch = source["defaultBranch"];
|
||||
this.latestCommitter = source["latestCommitter"];
|
||||
this.latestCommitAt = source["latestCommitAt"];
|
||||
this.private = source["private"];
|
||||
this.fork = source["fork"];
|
||||
this.archived = source["archived"];
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"net"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -748,6 +749,46 @@ func (s *Service) RefreshGitHubRepos(sessionID string) ([]models.GitHubRepo, err
|
||||
return s.sessions.FetchGitHubRepos(sessionID)
|
||||
}
|
||||
|
||||
// DownloadGitHubRepoArchive downloads a repository zip archive to a local file.
|
||||
func (s *Service) DownloadGitHubRepoArchive(sessionID string, fullName string, ref string) (string, error) {
|
||||
if s.ctx == nil {
|
||||
return "", fmt.Errorf("application context not set")
|
||||
}
|
||||
if fullName == "" {
|
||||
return "", fmt.Errorf("repository name cannot be empty")
|
||||
}
|
||||
|
||||
parts := strings.Split(fullName, "/")
|
||||
repoName := parts[len(parts)-1]
|
||||
defaultName := repoName + ".zip"
|
||||
if ref != "" {
|
||||
safeRef := strings.ReplaceAll(ref, "/", "-")
|
||||
defaultName = fmt.Sprintf("%s-%s.zip", repoName, safeRef)
|
||||
}
|
||||
|
||||
path, err := wailsRuntime.SaveFileDialog(s.ctx, wailsRuntime.SaveDialogOptions{
|
||||
Title: "Download Repository",
|
||||
DefaultFilename: defaultName,
|
||||
Filters: []wailsRuntime.FileFilter{
|
||||
{DisplayName: "Zip Archive (*.zip)", Pattern: "*.zip"},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("save dialog failed: %w", err)
|
||||
}
|
||||
if path == "" {
|
||||
return "", fmt.Errorf("download cancelled")
|
||||
}
|
||||
if filepath.Ext(path) != ".zip" {
|
||||
path += ".zip"
|
||||
}
|
||||
|
||||
if err := s.sessions.DownloadGitHubArchive(sessionID, fullName, ref, path); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return path, nil
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Port forwarding
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -9,8 +9,11 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/andydixon/nexus/internal/models"
|
||||
@@ -42,6 +45,7 @@ type apiRepo struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
DefaultBranch string `json:"default_branch"`
|
||||
Private bool `json:"private"`
|
||||
Fork bool `json:"fork"`
|
||||
Archived bool `json:"archived"`
|
||||
@@ -58,6 +62,15 @@ type apiRepo struct {
|
||||
// paginating through the API. Results are sorted by pushed_at descending
|
||||
// (most recently active first).
|
||||
func (c *Client) FetchRepos(ctx context.Context) ([]models.GitHubRepo, error) {
|
||||
return c.fetchRepos(ctx, nil)
|
||||
}
|
||||
|
||||
// FetchReposWithProgress fetches repositories and reports enrichment progress.
|
||||
func (c *Client) FetchReposWithProgress(ctx context.Context, progress func(done int, total int)) ([]models.GitHubRepo, error) {
|
||||
return c.fetchRepos(ctx, progress)
|
||||
}
|
||||
|
||||
func (c *Client) fetchRepos(ctx context.Context, progress func(done int, total int)) ([]models.GitHubRepo, error) {
|
||||
var all []apiRepo
|
||||
|
||||
page := 1
|
||||
@@ -120,6 +133,7 @@ func (c *Client) FetchRepos(ctx context.Context) ([]models.GitHubRepo, error) {
|
||||
Owner: r.Owner.Login,
|
||||
Description: r.Description,
|
||||
HTMLURL: r.HTMLURL,
|
||||
DefaultBranch: r.DefaultBranch,
|
||||
Private: r.Private,
|
||||
Fork: r.Fork,
|
||||
Archived: r.Archived,
|
||||
@@ -129,9 +143,149 @@ func (c *Client) FetchRepos(ctx context.Context) ([]models.GitHubRepo, error) {
|
||||
UpdatedAt: r.UpdatedAt.Format(time.RFC3339),
|
||||
}
|
||||
}
|
||||
|
||||
if progress != nil {
|
||||
progress(0, len(result))
|
||||
}
|
||||
|
||||
// Enrich with latest commit metadata (best-effort).
|
||||
sem := make(chan struct{}, 5)
|
||||
var wg sync.WaitGroup
|
||||
var done int32
|
||||
for i := range result {
|
||||
wg.Add(1)
|
||||
go func(idx int) {
|
||||
defer wg.Done()
|
||||
sem <- struct{}{}
|
||||
defer func() { <-sem }()
|
||||
|
||||
ref := result[idx].DefaultBranch
|
||||
if ref == "" {
|
||||
ref = "HEAD"
|
||||
}
|
||||
committer, committedAt, err := c.FetchLatestCommit(ctx, result[idx].FullName, ref)
|
||||
if err != nil {
|
||||
if progress != nil {
|
||||
current := int(atomic.AddInt32(&done, 1))
|
||||
progress(current, len(result))
|
||||
}
|
||||
return
|
||||
}
|
||||
result[idx].LatestCommitter = committer
|
||||
result[idx].LatestCommitAt = committedAt
|
||||
if progress != nil {
|
||||
current := int(atomic.AddInt32(&done, 1))
|
||||
progress(current, len(result))
|
||||
}
|
||||
}(i)
|
||||
}
|
||||
wg.Wait()
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// FetchLatestCommit returns the committer name and commit time for a repo/ref.
|
||||
func (c *Client) FetchLatestCommit(ctx context.Context, fullName string, ref string) (string, string, error) {
|
||||
url := fmt.Sprintf("%s/repos/%s/commits/%s", c.baseURL, fullName, ref)
|
||||
if ref == "" {
|
||||
url = fmt.Sprintf("%s/repos/%s/commits/HEAD", c.baseURL, fullName)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("building request: %w", err)
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer "+c.token)
|
||||
req.Header.Set("Accept", "application/vnd.github+json")
|
||||
req.Header.Set("User-Agent", "NexusTerminal/1.0")
|
||||
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("fetching commit: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden {
|
||||
return "", "", fmt.Errorf("authentication failed (HTTP %d)", resp.StatusCode)
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return "", "", fmt.Errorf("GitHub API returned HTTP %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
|
||||
var payload struct {
|
||||
Commit struct {
|
||||
Committer struct {
|
||||
Name string `json:"name"`
|
||||
Date time.Time `json:"date"`
|
||||
} `json:"committer"`
|
||||
Author struct {
|
||||
Name string `json:"name"`
|
||||
Date time.Time `json:"date"`
|
||||
} `json:"author"`
|
||||
} `json:"commit"`
|
||||
}
|
||||
|
||||
if err := json.NewDecoder(resp.Body).Decode(&payload); err != nil {
|
||||
return "", "", fmt.Errorf("decoding commit: %w", err)
|
||||
}
|
||||
|
||||
name := payload.Commit.Committer.Name
|
||||
date := payload.Commit.Committer.Date
|
||||
if name == "" {
|
||||
name = payload.Commit.Author.Name
|
||||
date = payload.Commit.Author.Date
|
||||
}
|
||||
if name == "" || date.IsZero() {
|
||||
return "", "", fmt.Errorf("commit metadata missing")
|
||||
}
|
||||
|
||||
return name, date.Format(time.RFC3339), nil
|
||||
}
|
||||
|
||||
// DownloadRepoArchive downloads a repository zip archive to the given path.
|
||||
func (c *Client) DownloadRepoArchive(ctx context.Context, fullName string, ref string, destPath string) error {
|
||||
if fullName == "" {
|
||||
return fmt.Errorf("repository name cannot be empty")
|
||||
}
|
||||
url := fmt.Sprintf("%s/repos/%s/zipball", c.baseURL, fullName)
|
||||
if ref != "" {
|
||||
url = url + "/" + ref
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("building request: %w", err)
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer "+c.token)
|
||||
req.Header.Set("Accept", "application/vnd.github+json")
|
||||
req.Header.Set("User-Agent", "NexusTerminal/1.0")
|
||||
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("downloading archive: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden {
|
||||
return fmt.Errorf("authentication failed (HTTP %d) — check your access token", resp.StatusCode)
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return fmt.Errorf("GitHub API returned HTTP %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
|
||||
file, err := os.Create(destPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating file: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
if _, err := io.Copy(file, resp.Body); err != nil {
|
||||
return fmt.Errorf("writing archive: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateToken makes a lightweight call to /user to confirm the token works.
|
||||
func (c *Client) ValidateToken(ctx context.Context) (string, error) {
|
||||
url := c.baseURL + "/user"
|
||||
|
||||
@@ -199,6 +199,9 @@ type GitHubRepo struct {
|
||||
Owner string `json:"owner"`
|
||||
Description string `json:"description"`
|
||||
HTMLURL string `json:"htmlURL"`
|
||||
DefaultBranch string `json:"defaultBranch"`
|
||||
LatestCommitter string `json:"latestCommitter"`
|
||||
LatestCommitAt string `json:"latestCommitAt"`
|
||||
Private bool `json:"private"`
|
||||
Fork bool `json:"fork"`
|
||||
Archived bool `json:"archived"`
|
||||
|
||||
@@ -703,13 +703,40 @@ func (m *Manager) connectGitHub(sess *Session, getSecret func(prompt string) (st
|
||||
// Validate the token.
|
||||
login, err := client.ValidateToken(context.Background())
|
||||
if err != nil {
|
||||
return fmt.Errorf("GitHub authentication failed: %w", err)
|
||||
if m.isGitHubAuthError(err) && getSecret != nil {
|
||||
retryToken, retryErr := m.promptAndStoreSecret(
|
||||
profile.ID,
|
||||
"github-token",
|
||||
ghConf.SecretMode,
|
||||
getSecret,
|
||||
"GitHub token did not work. Please enter a valid token:",
|
||||
)
|
||||
if retryErr == nil && retryToken != "" {
|
||||
client = githubclient.New(ghConf.BaseURL, retryToken)
|
||||
login, err = client.ValidateToken(context.Background())
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("GitHub authentication failed: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
sess.githubClient = client
|
||||
|
||||
// Perform the initial fetch.
|
||||
repos, err := client.FetchRepos(context.Background())
|
||||
m.emitEvent("session:github:status", map[string]interface{}{
|
||||
"sessionID": sess.Info.ID,
|
||||
"status": "Loading repositories...",
|
||||
})
|
||||
repos, err := client.FetchReposWithProgress(context.Background(), func(done int, total int) {
|
||||
if total <= 0 {
|
||||
return
|
||||
}
|
||||
m.emitEvent("session:github:status", map[string]interface{}{
|
||||
"sessionID": sess.Info.ID,
|
||||
"status": fmt.Sprintf("Loading commit info (%d/%d)", done, total),
|
||||
})
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("fetching repositories: %w", err)
|
||||
}
|
||||
@@ -739,7 +766,19 @@ func (m *Manager) connectGitHub(sess *Session, getSecret func(prompt string) (st
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
updated, fetchErr := client.FetchRepos(ctx)
|
||||
m.emitEvent("session:github:status", map[string]interface{}{
|
||||
"sessionID": sess.Info.ID,
|
||||
"status": "Refreshing repositories...",
|
||||
})
|
||||
updated, fetchErr := client.FetchReposWithProgress(ctx, func(done int, total int) {
|
||||
if total <= 0 {
|
||||
return
|
||||
}
|
||||
m.emitEvent("session:github:status", map[string]interface{}{
|
||||
"sessionID": sess.Info.ID,
|
||||
"status": fmt.Sprintf("Loading commit info (%d/%d)", done, total),
|
||||
})
|
||||
})
|
||||
if fetchErr != nil {
|
||||
m.emitEvent("session:github:error", map[string]interface{}{
|
||||
"sessionID": sess.Info.ID,
|
||||
@@ -785,6 +824,29 @@ func (m *Manager) FetchGitHubRepos(sessionID string) ([]models.GitHubRepo, error
|
||||
return repos, nil
|
||||
}
|
||||
|
||||
// DownloadGitHubArchive downloads a repository zip archive for a GitHub session.
|
||||
func (m *Manager) DownloadGitHubArchive(sessionID string, fullName string, ref string, destPath string) error {
|
||||
m.mu.RLock()
|
||||
sess, ok := m.sessions[sessionID]
|
||||
m.mu.RUnlock()
|
||||
|
||||
if !ok {
|
||||
return fmt.Errorf("sessions: session %q not found", sessionID)
|
||||
}
|
||||
if sess.githubClient == nil {
|
||||
return fmt.Errorf("sessions: session %q is not a GitHub connection", sessionID)
|
||||
}
|
||||
|
||||
if ref == "" {
|
||||
ref = "HEAD"
|
||||
}
|
||||
|
||||
if err := sess.githubClient.DownloadRepoArchive(context.Background(), fullName, ref, destPath); err != nil {
|
||||
return fmt.Errorf("downloading archive: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Session recording
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -1179,6 +1241,47 @@ func (m *Manager) buildSecretCallback(profileID string, secretType string, mode
|
||||
}
|
||||
}
|
||||
|
||||
// promptAndStoreSecret asks the user for a secret and stores it based on the mode.
|
||||
func (m *Manager) promptAndStoreSecret(profileID string, secretType string, mode models.SecretMode, getSecret func(prompt string) (string, error), prompt string) (string, error) {
|
||||
if getSecret == nil {
|
||||
return "", fmt.Errorf("no %s available and no prompt callback provided", secretType)
|
||||
}
|
||||
val, err := getSecret(prompt)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if val == "" {
|
||||
return "", fmt.Errorf("%s cannot be empty", secretType)
|
||||
}
|
||||
|
||||
if mode == models.SecretModeSaved {
|
||||
stored := false
|
||||
secretKey := fmt.Sprintf("profile:%s:%s", profileID, secretType)
|
||||
if m.keychainStore != nil {
|
||||
if sErr := m.keychainStore.SetSecret(secretKey, val); sErr == nil {
|
||||
stored = true
|
||||
}
|
||||
}
|
||||
if !stored && m.secretStore != nil && m.secretStore.IsUnlocked() {
|
||||
_ = m.secretStore.SetSecret(secretKey, val)
|
||||
}
|
||||
}
|
||||
|
||||
return val, nil
|
||||
}
|
||||
|
||||
// isGitHubAuthError checks whether an error indicates authentication failure.
|
||||
func (m *Manager) isGitHubAuthError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
msg := strings.ToLower(err.Error())
|
||||
return strings.Contains(msg, "token validation failed") ||
|
||||
strings.Contains(msg, "authentication failed") ||
|
||||
strings.Contains(msg, "http 401") ||
|
||||
strings.Contains(msg, "http 403")
|
||||
}
|
||||
|
||||
// closeSession shuts down the protocol client for a session.
|
||||
func (m *Manager) closeSession(sess *Session) {
|
||||
// Cancel any in-progress reconnect backoff.
|
||||
|
||||
Reference in New Issue
Block a user