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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,21 @@ jobs:
- uses: gradle/actions/setup-gradle@v6

- uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
cache-dependency-path: client/package-lock.json

- name: Set version
run: node .github/scripts/set-version.mjs "$VERSION"

# 远程终端的页面用 client/node_modules 里的 xterm.js(和桌面控制台同一个版本,见 app/build.gradle.kts 的 terminalAssets):
# 只要运行时的依赖
- name: xterm.js
working-directory: client
run: npm ci --no-audit --no-fund --omit=dev --ignore-scripts

- name: Signing key
env:
KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
Expand Down Expand Up @@ -384,9 +396,20 @@ jobs:
- name: Install XcodeGen
run: brew install xcodegen

- uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
cache-dependency-path: client/package-lock.json

- name: Set version
run: node .github/scripts/set-version.mjs "$VERSION"

# 远程终端的页面用 client/node_modules 里的 xterm.js(见 ios/scripts/terminal-page.sh):只要运行时的依赖
- name: xterm.js
working-directory: client
run: npm ci --no-audit --no-fund --omit=dev --ignore-scripts

# 不设 TEAM_ID:ad-hoc 签名、带 App Group 权限的 IPA,安装前要重新签名(见 docs/ios.md)
- name: Build
run: ios/scripts/build-ipa.sh
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ See [How it works → Video](docs/architecture.md#video) for details.
- **Fixed control codes**: they survive restarts, upgrades and even server restarts until you change them yourself
- **Console**: browser-style tabs to control several computers at once, plus a multi-screen overview to watch them all. Computers you've connected to are saved and reconnect with one click; if one is offline, it connects as soon as it comes back
- **Web console**: the controller can also run in Docker and be used from a browser, with nothing to install on the computer you control from
- **Remote terminal**: when you only want to run command-line programs such as `claude`, `codex` or `pi` on the other computer, open just a terminal there instead of the screen (Windows / macOS / Linux hosts, running as the signed-in user): next to no bandwidth, and after a dropped connection you get the same terminal back with its programs still running. [Details](docs/usage.md#remote-terminal)
- **Remote terminal**: when you only want to run command-line programs such as `claude`, `codex` or `pi` on the other computer, open just a terminal there instead of the screen (Windows / macOS / Linux hosts, running as the signed-in user), from the desktop app or from a phone (Android / iOS): next to no bandwidth, and after a dropped connection you get the same terminal back with its programs still running. [Details](docs/usage.md#remote-terminal)
- **Android**: control computers and phones from a phone as a trackpad or touchscreen, or share your own screen to get help (a device needs the pairing code shown on the phone the first time, and you're notified whenever one connects); watch on a TV with the remote
- **iPhone / iPad**: the same remote control as on Android (trackpad / touch gestures, keyboard, mouse with pointer lock on iPad, game controls), or share the screen through the system screen broadcast (view only: iOS doesn't let apps be controlled)
- **Audio**: the host's system audio plays on the controller (Opus + adaptive jitter buffer), with optional A/V sync for watching videos. The other way, the controller can send its microphone to meeting apps and voice typing on Windows, macOS 14.2+ and Linux (PipeWire) hosts. Mac and Linux hosts publish **Airhand Microphone** while forwarding is on
Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Airhand 是一个**高性能、低延迟**的远程桌面:画面用 GPU 硬件
- **固定的控制码**:重启、升级,甚至服务器重启之后都不变,直到你主动更换
- **控制台**:浏览器式标签页,同时控制多台电脑,多屏总览同时看所有画面。连接过的设备自动保存,下次点一下就连;对方离线时,等它上线自动连上
- **网页控制台**:控制端也能用 Docker 部署,浏览器打开就能用,操作的电脑上什么都不用装
- **远程终端**:只想在对方电脑上跑 `claude`、`codex`、`pi` 这类命令行程序时,不传画面、只开一个终端(Windows / macOS / Linux 被控端,以登录的用户的身份运行):几乎不占带宽,断线重连后接回原来的终端,里面的程序一直在跑。[详细说明](docs/usage.zh-CN.md#远程终端)
- **远程终端**:只想在对方电脑上跑 `claude`、`codex`、`pi` 这类命令行程序时,不传画面、只开一个终端(Windows / macOS / Linux 被控端,以登录的用户的身份运行),电脑和手机(Android / iOS)上都能开:几乎不占带宽,断线重连后接回原来的终端,里面的程序一直在跑。[详细说明](docs/usage.zh-CN.md#远程终端)
- **Android**:在手机上用触控板或触屏的方式控制电脑、手机,也能共享自己的屏幕让别人协助(对方第一次连接时要输入手机上显示的配对码,有设备连上来时会提醒你);在电视上用遥控器看画面
- **iPhone / iPad**:和 Android 一样控制电脑、手机(触控板 / 触屏手势、键盘、外接鼠标,iPad 上可以锁定指针、游戏按键),也能用系统的屏幕广播共享自己的屏幕(只能被看:iOS 不允许别的应用操作本机)
- **声音**:被控端的系统声音同步到控制端(Opus + 自适应抖动缓冲),看视频时可以打开音画同步。反过来,控制端的麦克风可以转发给 Windows、macOS 14.2+ 和 Linux(PipeWire)被控端,供那里的会议软件和语音输入使用。Mac 和 Linux 会在转发期间提供一个 **Airhand Microphone** 录音设备
Expand Down
30 changes: 30 additions & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ android {
buildConfig = true
}
sourceSets["main"].jniLibs.srcDir(layout.buildDirectory.dir("rustJniLibs"))
// 远程终端的页面(见下面的 terminalAssets)
sourceSets["main"].assets.srcDir(layout.buildDirectory.dir("generated/terminalAssets"))
packaging {
resources.excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
Expand Down Expand Up @@ -166,6 +168,34 @@ val cargoBuild by tasks.registering(Exec::class) {
}
tasks.named("preBuild") { dependsOn(cargoBuild) }

// ───────────── 远程终端的页面:client/mobile-terminal 加上 xterm.js,拷到 build/generated/terminalAssets/terminal/ ─────────────
// xterm.js 从 client/node_modules 拷(和桌面控制台同一个版本):先在 client 里 npm ci
val terminalAssets by tasks.registering(Sync::class) {
description = "Copies the remote terminal page (client/mobile-terminal) and xterm.js into the app's assets"
group = "build"
val client = rootProject.file("../client")
val xterm = client.resolve("node_modules/@xterm")
val required = listOf(
xterm.resolve("xterm/lib/xterm.js"),
xterm.resolve("xterm/css/xterm.css"),
xterm.resolve("addon-unicode11/lib/addon-unicode11.js"),
)
from(client.resolve("mobile-terminal")) { include("*.html", "*.js") }
from(required)
// 没有拷 .map:去掉指向它的注释
filesMatching("*.js") { filter { line -> if (line.startsWith("//# sourceMappingURL=")) "" else line } }
into(layout.buildDirectory.dir("generated/terminalAssets/terminal"))
doFirst {
val missing = required.filter { !it.isFile }
if (missing.isNotEmpty()) {
throw GradleException(
"The remote terminal page needs xterm.js from client/node_modules: run `npm ci` in client/ first (missing ${missing.joinToString()})",
)
}
}
}
tasks.named("preBuild") { dependsOn(terminalAssets) }

dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.activity.compose)
Expand Down
5 changes: 5 additions & 0 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
-keepclasseswithmembernames class * {
native <methods>;
}

# 远程终端的页面按名字调用原生的方法(AirhandAndroid.post,见 ui/terminal/TerminalWebView.kt)
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
8 changes: 8 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@
android:theme="@style/Theme.Airhand.Session"
tools:ignore="DiscouragedApi" />

<!-- 远程终端(不传画面,见 TerminalActivity):旋转、弹出键盘时不重建,终端跟着改大小 -->
<activity
android:name=".ui.terminal.TerminalActivity"
android:exported="false"
android:launchMode="singleTask"
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden|navigation|uiMode|density"
android:windowSoftInputMode="adjustResize|stateHidden" />

<!-- 剪贴板里的文件:系统分享菜单里的"发给对方"(见 core/ClipFiles.kt) -->
<activity
android:name=".ui.ShareFilesActivity"
Expand Down
26 changes: 26 additions & 0 deletions android/app/src/main/java/app/airhand/android/AirhandApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ProcessLifecycleOwner
import app.airhand.android.controller.ControllerClient
import app.airhand.android.controller.RemoteSession
import app.airhand.android.controller.TerminalSession
import app.airhand.android.core.CrashLog
import app.airhand.android.core.Native
import app.airhand.android.core.Updater
Expand Down Expand Up @@ -56,6 +57,11 @@ class AirhandApp : Application() {
/** 当前的远程会话(同一时间只有一个) */
val session: StateFlow<RemoteSession?> = _session.asStateFlow()

private val _terminal = MutableStateFlow<TerminalSession?>(null)

/** 当前的远程终端(同一时间一个,和远程画面的会话互不影响) */
val terminal: StateFlow<TerminalSession?> = _terminal.asStateFlow()

override fun onCreate() {
super.onCreate()
// 最先装上:之后哪里崩了(包括加载 Rust 库)都记得下来
Expand Down Expand Up @@ -97,6 +103,25 @@ class AirhandApp : Application() {
if (s != null && _session.value === s) _session.value = null
}

/**
* 在一台电脑上开远程终端(不传画面)。之前的终端会话先关掉(界面上先问过用户)。
* 主线程上调用(显示终端的页面要在主线程上建)
*/
fun startTerminal(code: String, pairing: String? = null): TerminalSession {
android.util.Log.i("airhand", "opening a terminal on $code")
_terminal.value?.close()
val s = TerminalSession(this, code, pairing)
_terminal.value = s
s.start()
return s
}

/** 关掉终端会话(里面的程序随之结束) */
fun endTerminal(s: TerminalSession? = _terminal.value) {
s?.close()
if (s != null && _terminal.value === s) _terminal.value = null
}

/** 忘掉配对过的控制端:在共享就交给 Rust(它改完发回来再保存),没在共享就直接改保存的 */
fun forgetPaired() {
if (!HostService.forgetPaired()) pairing.forget()
Expand All @@ -112,6 +137,7 @@ class AirhandApp : Application() {
val trustReset = old.trustedFp.isNotEmpty() && now.trustedFp.isEmpty()
if (old.server != now.server || old.fingerprint != now.fingerprint || old.deviceName != now.deviceName || trustReset) {
endSession()
endTerminal()
controller.restart()
HostService.restartIfRunning(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ object Commands {
* `resume`:之前连上时得到的重连凭证(十六进制,见 [Resume]);`hostKey`:之前记下的对方公钥(只认它);
* `pairing`:配对码(对方要求配对时用户输入的);`settings` / `audio`:开始时的画质和要不要声音(在端到端握手里
* 交给对方,它一开始就按这个建编码器);`privacy`:要不要防窥模式(重连时带上现在的开关,对方一开始就保持着,
* 它的屏幕不会在重连的间隙露出来)
* 它的屏幕不会在重连的间隙露出来);`terminal`:终端会话(不要画面和声音,只开终端,见 [TerminalSession])
*/
fun connect(
code: String,
Expand All @@ -119,7 +119,9 @@ object Commands {
pairing: String? = null,
audio: Boolean = false,
privacy: Boolean = false,
terminal: Boolean = false,
): JSONObject = options(resume, settings, hostKey, pairing, audio, privacy).put("cmd", "connect").put("code", code)
.apply { if (terminal) put("terminal", true) }

/** 连接选项(`ConnectOptions`) */
fun options(resume: String?, settings: Quality, hostKey: String?, pairing: String?, audio: Boolean, privacy: Boolean): JSONObject =
Expand All @@ -141,6 +143,23 @@ object Commands {
fun privacy(sid: Int, on: Boolean): JSONObject = cmd("privacy", sid).put("on", on)
fun clipboard(sid: Int, text: String): JSONObject = cmd("clipboard", sid).put("text", text)
fun disconnect(sid: Int): JSONObject = cmd("disconnect", sid)

// ── 远程终端(见 [TerminalSession] 和 Rust 的 airhand_proto::terminal)──

private fun size(cols: Int, rows: Int): JSONObject = JSONObject().put("cols", cols).put("rows", rows)

/** 开第 `term` 个终端。`resume`:接回断线前的那个(对方给的凭证,收到了哪里) */
fun terminalOpen(sid: Int, term: Int, cols: Int, rows: Int, resume: Pair<String, Long>?): JSONObject =
cmd("terminalOpen", sid).put("term", term).put("size", size(cols, rows))
.put("resume", resume?.let { JSONObject().put("token", it.first).put("offset", it.second) } ?: JSONObject.NULL)

fun terminalInput(sid: Int, term: Int, data: String): JSONObject = cmd("terminalInput", sid).put("term", term).put("data", data)
fun terminalResize(sid: Int, term: Int, cols: Int, rows: Int): JSONObject =
cmd("terminalResize", sid).put("term", term).put("size", size(cols, rows))

/** 界面显示了到 `offset` 为止的输出(累积的位置) */
fun terminalAck(sid: Int, term: Int, offset: Long): JSONObject = cmd("terminalAck", sid).put("term", term).put("offset", offset)
fun terminalClose(sid: Int, term: Int): JSONObject = cmd("terminalClose", sid).put("term", term)
}

/** 重连凭证:Rust 那边是 16 个字节(JSON 数组),这里存成十六进制字符串("我的设备"里) */
Expand Down
Loading