接通 Windows 与 Web 设备间加密文字聊天

This commit is contained in:
xhgit committed 2026-11-13 18:43:04 +08:00
1 parent b04034ee89
commit d1efdedc57
27 files changed
+880 -22

No files matched your search

+233
View File
@@ -0,0 +1,233 @@
import { APIError } from '../api'
import { mlsBinding, signMls } from '../identity'
import { base64, decode, fingerprint, loadEngine } from './engine'
import type { DeviceMls } from './engine'
import { withVault } from './vault'
export interface Peer {
id: string
name: string
publicKey: string
mls?: { publicKey: string; signature: string }
}
export interface ChatIdentity {
user: { id: string; username: string }
device: { id: string }
}
interface Package { package: string; signature: string }
interface Outgoing { messageId: string; recipientDevice: string; ciphertext: string }
interface Incoming { messageId: string; senderDevice: string; ciphertext: string; sequence: string; createdAt: string }
export interface ChatLine {
id: string
peer: string
text: string
time: string
own: boolean
}
interface ChatState {
engine: string
cursor: string
pending: Incoming[]
outbox: Outgoing[]
lines: ChatLine[]
pinned: Record<string, string>
groups: Record<string, string>
package?: { lastPublished: number; item: Package }
rejected: number
}
export type Call = <T>(path: string, method?: string, body?: object) => Promise<T>
const encoder = new TextEncoder()
function aad(id: string, sender: string, recipient: string) {
return encoder.encode('XHChat message v1\n' + id + '\n' + sender + '\n' + recipient)
}
async function verify(peer: Peer, user: string, type: 'credential' | 'KeyPackage', value: Uint8Array, signature: string) {
const key = await crypto.subtle.importKey('raw', decode(peer.publicKey), 'Ed25519', false, ['verify'])
if (!await crypto.subtle.verify('Ed25519', key, decode(signature), mlsBinding(type, user, peer.id, value))) {
throw new Error('对方设备签名验证失败')
}
}
async function verifiedPeer(peer: Peer, user: string) {
if (!peer.mls) throw new Error('此设备尚未启用加密聊天')
const key = decode(peer.mls.publicKey)
await verify(peer, user, 'credential', key, peer.mls.signature)
return key
}
export function directory(call: Call, user: string) {
return call<Peer[]>('/contacts/' + user + '/devices')
}
function update<R>(identity: ChatIdentity, operation: (s: ChatState, save: (s: ChatState) => Promise<void>, factory: Awaited<ReturnType<typeof loadEngine>>) => Promise<R>) {
return withVault<ChatState, R>(identity.device.id, async (state, save) => {
const factory = await loadEngine()
if (!state) {
const engine = new factory.DeviceMls(identity.device.id)
try {
state = { engine: base64(engine.snapshot()), cursor: '0', pending: [], outbox: [], lines: [], pinned: {}, groups: {}, rejected: 0 }
await save(state)
} finally {
engine.free()
}
}
return operation(state, save, factory)
})
}
async function signed(identity: ChatIdentity, kind: 'credential' | 'KeyPackage', value: Uint8Array<ArrayBuffer>) {
return base64(await signMls(identity.user.username, kind, identity.user.id, identity.device.id, value))
}
export async function enableChat(identity: ChatIdentity, call: Call) {
return update(identity, async (state, save, factory) => {
const engine = factory.DeviceMls.restore(decode(state.engine))
try {
if (engine.device() !== identity.device.id) throw new Error('本机加密状态属于其他设备')
const key = engine.public_key()
await call('/mls-credential', 'POST', { publicKey: base64(key), signature: await signed(identity, 'credential', key) })
if (!state.package || Date.now() - state.package.lastPublished >= 6 * 3600_000) {
if (!state.package || state.package.lastPublished) {
const pack = engine.key_package()
state.package = { lastPublished: 0, item: { package: base64(pack), signature: await signed(identity, 'KeyPackage', pack) } }
state.engine = base64(engine.snapshot())
await save(state)
}
await call('/key-packages', 'POST', state.package.item)
state.package.lastPublished = Date.now()
await save(state)
}
return fingerprint(decode(await localIdentityKey(identity, call)))
} finally {
engine.free()
}
})
}
async function localIdentityKey(identity: ChatIdentity, call: Call) {
const { publicKey } = await call<{ publicKey: string }>('/mls-local-key')
const credential = decode(publicKey)
const proof = await signed(identity, 'credential', credential)
await verify({ id: identity.device.id, name: '', publicKey }, identity.user.id, 'credential', credential, proof)
return publicKey
}
export async function trust(identity: ChatIdentity, user: string, peer: Peer, code: string) {
await verifiedPeer(peer, user)
const expected = await fingerprint(decode(peer.publicKey))
if (code.replace(/\s+/g, '').toLowerCase() !== expected) throw new Error('安全码不匹配')
await update(identity, async (state, save) => {
const previous = state.pinned[peer.id]
if (previous && previous !== peer.publicKey) throw new Error('该设备身份已变更,请使用新设备重新建立会话')
state.pinned[peer.id] = peer.publicKey
await save(state)
})
}
async function flush(state: ChatState, save: (state: ChatState) => Promise<void>, call: Call) {
const unavailable = new Set<string>()
for (const item of [...state.outbox]) {
if (unavailable.has(item.recipientDevice)) continue
try {
await call('/inbox', 'POST', item)
state.outbox = state.outbox.filter((pending) => pending.messageId !== item.messageId)
await save(state)
} catch (error) {
if (!(error instanceof APIError) || error.status !== 404) throw error
unavailable.add(item.recipientDevice)
}
}
return unavailable
}
export function send(identity: ChatIdentity, user: string, peer: Peer, text: string, call: Call) {
return update(identity, async (state, save, factory) => {
const current = (await directory(call, user)).find((item) => item.id === peer.id)
if (!current || state.pinned[current.id] !== current.publicKey) throw new Error('发送前请核验对方设备安全码')
const key = await verifiedPeer(current, user)
const unavailable = await flush(state, save, call)
if (unavailable.has(current.id)) throw new Error('该设备暂不可接收消息')
const plaintext = encoder.encode(text.trim())
if (!plaintext.length || plaintext.length > 8000) throw new Error('消息须为 1 至 8000 字节')
if (state.lines.length >= 1000) throw new Error('本机预览版消息容量已达上限')
const engine = factory.DeviceMls.restore(decode(state.engine))
try {
let group = state.groups[current.id] ? decode(state.groups[current.id]) : undefined
if (!group) {
const pack = await call<Package>('/contacts/' + user + '/devices/' + current.id + '/claim', 'POST')
const wire = decode(pack.package)
await verify(current, user, 'KeyPackage', wire, pack.signature)
group = crypto.getRandomValues(new Uint8Array(32))
const welcome = engine.start(group, current.id, key, wire)
state.groups[current.id] = base64(group)
state.outbox.push({ messageId: crypto.randomUUID(), recipientDevice: current.id, ciphertext: base64(welcome) })
}
const id = crypto.randomUUID()
const ciphertext = engine.encrypt(group, aad(id, identity.device.id, current.id), plaintext)
state.outbox.push({ messageId: id, recipientDevice: current.id, ciphertext: base64(ciphertext) })
state.lines.push({ id, peer: current.id, text: text.trim(), time: new Date().toISOString(), own: true })
state.engine = base64(engine.snapshot())
await save(state)
await flush(state, save, call)
} finally {
engine.free()
}
})
}
export function synchronize(identity: ChatIdentity, user: string, call: Call) {
return update(identity, async (state, save, factory) => {
const peers = await directory(call, user)
for (let page = 0; page < 4; page++) {
const inbox = await call<Incoming[]>('/inbox?after=' + state.cursor)
if (!inbox.length) break
if (state.pending.length + inbox.length > 512) throw new Error('待验证消息已达上限,请先打开相应联系人的聊天')
state.pending.push(...inbox)
state.cursor = inbox.at(-1)!.sequence
await save(state)
if (inbox.length < 64) break
}
for (const item of [...state.pending]) {
const peer = peers.find((device) => device.id === item.senderDevice)
if (!peer || !peer.mls || state.pinned[peer.id] !== peer.publicKey) continue
const engine = factory.DeviceMls.restore(decode(state.engine))
try {
const key = await verifiedPeer(peer, user)
const wire = decode(item.ciphertext)
if (wire[3] === 3) {
const group = base64(engine.join(peer.id, key, wire))
const previous = state.groups[peer.id]
if (!previous || group < previous) state.groups[peer.id] = group
} else {
const plaintext = engine.decrypt(peer.id, key, aad(item.messageId, peer.id, identity.device.id), wire)
if (state.lines.length < 1000) state.lines.push({
id: item.messageId, peer: peer.id, text: new TextDecoder('utf-8', { fatal: true }).decode(plaintext),
time: item.createdAt, own: false,
})
}
state.engine = base64(engine.snapshot())
} catch {
state.rejected++
} finally {
engine.free()
}
state.pending = state.pending.filter((pending) => pending.sequence !== item.sequence)
await save(state)
}
let deliveryError = ''
try {
const unavailable = await flush(state, save, call)
if (unavailable.size) deliveryError = '部分待发消息的设备已不可用'
} catch (cause) {
deliveryError = cause instanceof APIError && cause.status === 404 ? '部分待发消息的设备已不可用' : '部分消息等待重试'
}
return { lines: state.lines, pinned: state.pinned, peers, rejected: state.rejected, deliveryError,
unsent: state.outbox.map((item) => item.messageId) }
})
}
+48
View File
@@ -0,0 +1,48 @@
export interface DeviceMls {
free(): void
snapshot(): Uint8Array<ArrayBuffer>
device(): string
public_key(): Uint8Array<ArrayBuffer>
key_package(): Uint8Array<ArrayBuffer>
start(id: Uint8Array, peer: string, key: Uint8Array, wire: Uint8Array): Uint8Array<ArrayBuffer>
join(peer: string, key: Uint8Array, wire: Uint8Array): Uint8Array<ArrayBuffer>
encrypt(id: Uint8Array, aad: Uint8Array, value: Uint8Array): Uint8Array<ArrayBuffer>
decrypt(peer: string, key: Uint8Array, aad: Uint8Array, wire: Uint8Array): Uint8Array<ArrayBuffer>
}
interface Module {
default(): Promise<unknown>
DeviceMls: {
new (device: string): DeviceMls
restore(bytes: Uint8Array): DeviceMls
}
}
let pending: Promise<Module> | undefined
export function loadEngine() {
const path = '/mls/xhchat_mls_check.js'
pending ??= import(/* @vite-ignore */ path).then(async (module: Module) => {
await module.default()
return module
}).catch((error) => {
pending = undefined
throw error
})
return pending
}
export function base64(bytes: Uint8Array) {
let binary = ''
for (let i = 0; i < bytes.length; i += 4096) binary += String.fromCharCode(...bytes.subarray(i, i + 4096))
return btoa(binary)
}
export function decode(value: string) {
return Uint8Array.from(atob(value), (character) => character.charCodeAt(0))
}
export async function fingerprint(key: Uint8Array<ArrayBuffer>) {
return Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256', key)),
(byte) => byte.toString(16).padStart(2, '0')).join('')
}
+71
View File
@@ -0,0 +1,71 @@
import { base64, decode } from './engine'
interface VaultRecord {
key: CryptoKey | string
iv?: Uint8Array<ArrayBuffer>
sealed?: ArrayBuffer
}
function database(): Promise<IDBDatabase> {
return new Promise((resolve, reject) => {
const request = indexedDB.open('xhchat-encrypted-chat', 1)
request.onupgradeneeded = () => request.result.createObjectStore('vaults')
request.onsuccess = () => resolve(request.result)
request.onerror = () => reject(request.error)
request.onblocked = () => reject(new Error('请关闭其他 XHChat 页面后重试'))
})
}
function record(db: IDBDatabase, scope: string, value?: VaultRecord): Promise<VaultRecord | undefined> {
return new Promise((resolve, reject) => {
const transaction = db.transaction('vaults', value ? 'readwrite' : 'readonly')
const store = transaction.objectStore('vaults')
const request = value ? store.put(value, scope) : store.get(scope)
transaction.oncomplete = () => resolve(value ?? request.result)
transaction.onabort = () => reject(transaction.error)
})
}
async function newKey(): Promise<VaultRecord['key']> {
if (!window.xhchat) return crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])
const raw = crypto.getRandomValues(new Uint8Array(32))
try {
return await window.xhchat.protectMls(base64(raw))
} finally {
raw.fill(0)
}
}
async function unsealKey(value: VaultRecord['key']) {
if (!window.xhchat && typeof value !== 'string') return value
if (!window.xhchat || typeof value !== 'string') throw new Error('会话存储密钥无效')
const raw = decode(await window.xhchat.unprotectMls(value))
try {
return await crypto.subtle.importKey('raw', raw, 'AES-GCM', false, ['encrypt', 'decrypt'])
} finally {
raw.fill(0)
}
}
export async function withVault<T, R>(device: string, update: (state: T | undefined, save: (state: T) => Promise<void>) => Promise<R>) {
const scope = (window.xhchat?.apiBase ?? location.origin) + '/' + device
const additionalData = new TextEncoder().encode(scope)
return navigator.locks.request('xhchat-chat:' + scope, async () => {
const db = await database()
try {
const stored = await record(db, scope)
const wrapped = stored?.key ?? await newKey()
const key = await unsealKey(wrapped)
const state = stored?.iv && stored.sealed
? JSON.parse(new TextDecoder().decode(await crypto.subtle.decrypt({ name: 'AES-GCM', iv: stored.iv, additionalData }, key, stored.sealed))) as T
: undefined
return await update(state, async (next) => {
const iv = crypto.getRandomValues(new Uint8Array(12))
const sealed = await crypto.subtle.encrypt({ name: 'AES-GCM', iv, additionalData }, key, new TextEncoder().encode(JSON.stringify(next)))
await record(db, scope, { key: wrapped, iv, sealed })
})
} finally {
db.close()
}
})
}
+17
View File
@@ -7,6 +7,9 @@ interface DesktopBridge {
apiBase: string
signChallenge: (username: string, challenge: string) => Promise<DeviceProof>
openBrowser?: () => Promise<void>
signMls: (username: string, kind: 'credential' | 'KeyPackage', user: string, device: string, value: Uint8Array<ArrayBuffer>) => Promise<Uint8Array<ArrayBuffer>>
protectMls: (key: string) => Promise<string>
unprotectMls: (key: string) => Promise<string>
}
declare global {
@@ -53,6 +56,20 @@ async function browserKey(username: string): Promise<CryptoKeyPair> {
export const platform = window.xhchat ? 'windows' : 'web'
export function mlsBinding(kind: 'credential' | 'KeyPackage', user: string, device: string, value: Uint8Array) {
const prefix = new TextEncoder().encode('XHChat MLS ' + kind + ' v1\n' + user + '\n' + device + '\n')
const bytes = new Uint8Array(prefix.length + value.length)
bytes.set(prefix)
bytes.set(value, prefix.length)
return bytes
}
export async function signMls(username: string, kind: 'credential' | 'KeyPackage', user: string, device: string, value: Uint8Array<ArrayBuffer>) {
if (window.xhchat) return window.xhchat.signMls(username, kind, user, device, value)
const pair = await browserKey(username)
return new Uint8Array(await crypto.subtle.sign('Ed25519', pair.privateKey, mlsBinding(kind, user, device, value)))
}
export async function signChallenge(username: string, challenge: string): Promise<DeviceProof> {
if (window.xhchat) return window.xhchat.signChallenge(username, challenge)
try {
+2
View File
@@ -5,6 +5,7 @@ import App from './App.vue'
import AuthView from './views/AuthView.vue'
import DeviceView from './views/DeviceView.vue'
import ContactsView from './views/ContactsView.vue'
import ChatView from './views/ChatView.vue'
import Workspace from './views/Workspace.vue'
import { useSession } from './session'
import './style.css'
@@ -18,6 +19,7 @@ const router = createRouter({
{ path: '/', component: Workspace, children: [
{ path: 'devices', component: DeviceView },
{ path: 'contacts', component: ContactsView },
{ path: 'chat/:user?', component: ChatView },
] },
{ path: '/:pathMatch(.*)*', redirect: '/' },
],
+8 -3
View File
@@ -25,6 +25,7 @@ export const useSession = defineStore('session', () => {
const identity = shallowRef<Identity>()
const connection = ref('离线')
const contactChanges = ref(0)
const inboxChanges = ref(0)
let token = ''
let socket: WebSocket | undefined
let retry: ReturnType<typeof setTimeout> | undefined
@@ -56,6 +57,7 @@ export const useSession = defineStore('session', () => {
attempts = 0
}
if (type === 'contacts_changed') contactChanges.value++
if (type === 'inbox_changed') inboxChanges.value++
}
active.onclose = (event) => {
if (socket !== active) return
@@ -90,10 +92,13 @@ export const useSession = defineStore('session', () => {
}
async function authorized<T>(path: string, method = 'GET', body?: object) {
const current = token
try {
return await request<T>(path, method, token, body)
const response = await request<T>(path, method, current, body)
if (token !== current) throw new Error('登录会话已变更')
return response
} catch (error) {
if (error instanceof APIError && error.status === 401) clear()
if (token === current && error instanceof APIError && error.status === 401) clear()
throw error
}
}
@@ -104,7 +109,7 @@ export const useSession = defineStore('session', () => {
}
return {
identity, connection, contactChanges, authenticate, logout,
identity, connection, contactChanges, inboxChanges, authenticate, logout, authorized,
devices: () => authorized<Device[]>('/devices'),
revoke: (id: string) => authorized<void>('/devices/' + encodeURIComponent(id), 'DELETE'),
contacts: () => authorized<Contact[]>('/contacts'),
+12
View File
@@ -73,6 +73,18 @@ input { width: 100%; color: var(--text); background: var(--base); border: 1px so
.contact-heading h1 { font-size: 22px; }
.contact-detail > button { margin-bottom: 18px; }
.contact-preferences { max-width: 340px; }
.chat-page { display: grid; gap: 14px; }
.chat-page > button { justify-self: start; }
.chat-page details p { margin: 8px 0; }
.security-code { overflow-wrap: anywhere; color: var(--green); }
.chat-page select, .chat-compose textarea { font: inherit; border: 1px solid var(--line); border-radius: 8px; background: var(--base); color: var(--text); padding: 8px; }
.verified-label { color: var(--green); font-weight: 600; }
.chat-lines { list-style: none; padding: 0; margin: 0; min-height: 90px; max-height: 45vh; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.chat-lines li { align-self: start; border-radius: 9px; background: var(--base); padding: 8px 11px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-lines li.own { align-self: end; background: var(--green-soft); }
.chat-lines small { display: block; text-align: end; }
.chat-compose { display: grid; gap: 8px; }
.chat-compose button { justify-self: end; }
.account-footer { display: grid; gap: 12px; margin-top: auto; }
.account-footer p { color: var(--muted); font-size: 13px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin: 0 8px 1px 4px; }
+135
View File
@@ -0,0 +1,135 @@
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { useSession } from '../session'
import { enableChat, send, synchronize, trust } from '../chat/chat'
const session = useSession()
const route = useRoute()
const ownCode = ref('')
const code = ref('')
const selected = ref('')
const draft = ref('')
const error = ref('')
const busy = ref(false)
const view = ref<Awaited<ReturnType<typeof synchronize>>>()
const target = computed(() => typeof route.params.user === 'string' ? route.params.user : '')
const peer = computed(() => view.value?.peers.find((item) => item.id === selected.value))
const trusted = computed(() => peer.value && view.value?.pinned[peer.value.id] === peer.value.publicKey)
const changed = computed(() => peer.value && view.value?.pinned[peer.value.id] && !trusted.value)
const lines = computed(() => (view.value?.lines ?? []).filter((line) => line.peer === selected.value))
let timer: ReturnType<typeof setInterval>
async function execute(action: () => Promise<void>) {
if (busy.value || !session.identity) return
busy.value = true
error.value = ''
try {
await action()
} catch (cause) {
error.value = cause instanceof Error ? cause.message : '加密聊天暂不可用'
} finally {
busy.value = false
}
}
async function refresh() {
const identity = session.identity
if (!identity || !target.value || !ownCode.value) return
const contact = target.value
const current = await synchronize(identity, contact, session.authorized)
if (target.value !== contact) return
view.value = current
if (!current.peers.some((device) => device.id === selected.value)) selected.value = current.peers[0]?.id ?? ''
}
function enable() {
void execute(async () => {
if (!session.identity) return
ownCode.value = await enableChat(session.identity, session.authorized)
await refresh()
})
}
function confirm() {
void execute(async () => {
if (!session.identity || !peer.value) return
await trust(session.identity, target.value, peer.value, code.value)
code.value = ''
await refresh()
})
}
function submit() {
void execute(async () => {
if (!session.identity || !peer.value) return
await send(session.identity, target.value, peer.value, draft.value, session.authorized)
draft.value = ''
await refresh()
})
}
function sync() {
if (ownCode.value) void execute(refresh)
}
watch(target, () => {
view.value = undefined
selected.value = ''
code.value = ''
draft.value = ''
sync()
})
watch(() => [session.inboxChanges, session.contactChanges, session.connection], sync)
onMounted(() => { timer = setInterval(sync, 10_000) })
onBeforeUnmount(() => clearInterval(timer))
</script>
<template>
<section class="device-page">
<header class="page-header">
<h1>加密聊天</h1>
<button v-if="ownCode" class="plain" :disabled="busy" @click="sync">刷新</button>
</header>
<div class="device-content chat-page">
<p v-if="error" class="error" role="alert">{{ error }}</p>
<button v-if="!ownCode" type="button" class="primary" :disabled="busy" @click="enable">启用本机加密聊天</button>
<template v-else>
<details open>
<summary>本机安全码</summary>
<p>请通过另一可信渠道将此安全码告知对方。双方都需验证。</p>
<code class="security-code">{{ ownCode }}</code>
</details>
<template v-if="target">
<label v-if="view?.peers.length">对方设备
<select v-model="selected" :disabled="busy">
<option v-for="device in view.peers" :key="device.id" :value="device.id">{{ device.name }}</option>
</select>
</label>
<p v-else>对方设备出现后可开始验证。</p>
<p v-if="changed" class="error" role="alert">设备身份已变更,请重新核验。</p>
<p v-if="peer && !peer.mls">等待对方启用本机加密聊天。</p>
<form v-if="peer?.mls && !trusted" class="contact-preferences" @submit.prevent="confirm">
<label>对方安全码<input v-model="code" required maxlength="100" autocomplete="off"></label>
<button class="plain" :disabled="busy">核验设备</button>
</form>
<template v-if="trusted">
<p class="verified-label">设备已验证</p>
<p v-if="view?.deliveryError" class="error">{{ view.deliveryError }}</p>
<p v-if="view?.rejected" class="muted">已拒绝 {{ view.rejected }} 个无法验证的封包。</p>
<ol class="chat-lines" aria-label="消息记录" aria-live="polite">
<li v-for="line in lines" :key="line.id" :class="{ own: line.own }">
<span>{{ line.text }}</span><small v-if="view?.unsent.includes(line.id)">待发送</small>
</li>
</ol>
<form class="chat-compose" @submit.prevent="submit">
<label>消息<textarea v-model="draft" required rows="3" maxlength="4000"></textarea></label>
<button class="primary" :disabled="busy || !draft.trim()">发送</button>
</form>
</template>
</template>
<p v-else>在联系人详情打开聊天。</p>
</template>
</div>
</section>
</template>
+1
View File
@@ -115,6 +115,7 @@ async function change(action: ContactAction) {
<button v-if="detail.state === 'outgoing'" class="plain" :disabled="busy" @click="change('cancel')">取消申请</button>
<button v-if="detail.state === 'blocked'" class="plain" :disabled="busy" @click="change('unblock')">解除拉黑</button>
<form v-if="detail.state === 'friend'" class="contact-preferences" @submit.prevent="change('preferences')">
<RouterLink class="plain" :to="'/chat/' + detail.id">打开加密聊天</RouterLink>
<label>备注<input v-model="alias" maxlength="64"></label>
<label>分组<input v-model="category" maxlength="32"></label>
<button class="plain" :disabled="busy">保存</button>
+2
View File
@@ -24,6 +24,7 @@ async function act(action: () => Promise<void>) {
<main v-if="session.identity" class="workspace">
<nav class="rail" aria-label="主导航">
<RouterLink class="mark" to="/devices" aria-label="XHChat">X</RouterLink>
<RouterLink class="rail-link" to="/chat" title="消息" aria-label="消息">◇</RouterLink>
<RouterLink class="rail-link" to="/contacts" title="联系人" aria-label="联系人">人</RouterLink>
<RouterLink class="rail-link" to="/devices" title="设备管理" aria-label="设备管理">▣</RouterLink>
<button v-if="browser" type="button" class="rail-link browser-button" title="浏览器" aria-label="浏览器" @click="act(browser)">◎</button>
@@ -34,6 +35,7 @@ async function act(action: () => Promise<void>) {
<div><strong>{{ session.identity.user.username }}</strong><small>我的账号</small></div>
</div>
<nav class="panel-links" aria-label="工作区">
<RouterLink to="/chat">消息</RouterLink>
<RouterLink to="/contacts">联系人</RouterLink>
<RouterLink to="/devices">设备管理</RouterLink>
<button v-if="browser" class="plain mobile-browser" @click="act(browser)">浏览器</button>