Skip to content

PasteFerry (隔空贴): clipboard and file sync across macOS, Windows and Linux. Direct-first, end-to-end encrypted. Optional official access: no server to host. Independent self-hosting remains available.

修复中转显示不一致与复制记录重复,发布 1.0.2

baiyuze3f1f2250599a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 519d0e4..9738d85 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,18 @@
# 更新记录 / Changelog
+## 1.0.2 — 2026-10-08
+
+- 修复:一端经中转时,另一端误显示为「直连」,两台设备显示不一致。只有发送方能确定自己的数据
+ 是否走 TURN,现在连接建立后两端互相告知,任一端经中转即两端都显示「中转」。
+ Fixed: when only one side was relayed, the other side showed "direct". Only the sender knows whether its
+ traffic goes through TURN, so the two sides now tell each other after connecting; if either is relayed,
+ both show "relay".
+- 修复:收到图片或文件后,复制记录里同一条出现两行,其中一行进度条一直在动。
+ Fixed: a received image or file appeared twice in the history, one row with a progress bar that never stopped.
+- 修复:本机复制的图片在发送后一直显示进度条。 Fixed: items copied on this Mac kept showing a progress bar after sending.
+- 传输进度按真实比例显示,并做了节流,大文件传输时不再挤掉「传输完成」的事件。
+ Transfer progress now shows the actual percentage and is throttled, so large transfers no longer crowd out the completion event.
+
## 1.0.1 — 2026-10-08
- 修复:配对时两台 Mac 显示的安全指纹不一样,无从核对。之前每台只显示「对方」的指纹;
diff --git a/client-core/internal/sync/engine.go b/client-core/internal/sync/engine.go
index 4eb6584..f707121 100644
--- a/client-core/internal/sync/engine.go
+++ b/client-core/internal/sync/engine.go
@@ -74,6 +74,10 @@ type Engine struct {
mu sync.Mutex
// 正在接收中的流:stream_id -> 接收器
incoming map[string]*receiver
+
+ // 每次传输上一次上报进度的时间,用于节流,见 emitProgress
+ progressMu sync.Mutex
+ lastProgress map[string]time.Time
}
type Options struct {
@@ -98,20 +102,21 @@ func New(opts Options) *Engine {
log = slog.Default()
}
return &Engine{
- log: log,
- store: opts.Store,
- cache: opts.Cache,
- watcher: opts.Watcher,
- deviceID: opts.DeviceID,
- deviceName: opts.DeviceName,
- loadConfig: opts.LoadConfig,
- send: opts.Send,
- broadcast: opts.Broadcast,
- openStream: opts.OpenStream,
- onlinePeers: opts.OnlinePeers,
- onRecord: opts.OnRecord,
- onProgress: opts.OnProgress,
- incoming: make(map[string]*receiver),
+ log: log,
+ store: opts.Store,
+ cache: opts.Cache,
+ watcher: opts.Watcher,
+ deviceID: opts.DeviceID,
+ deviceName: opts.DeviceName,
+ loadConfig: opts.LoadConfig,
+ send: opts.Send,
+ broadcast: opts.Broadcast,
+ openStream: opts.OpenStream,
+ onlinePeers: opts.OnlinePeers,
+ onRecord: opts.OnRecord,
+ onProgress: opts.OnProgress,
+ incoming: make(map[string]*receiver),
+ lastProgress: make(map[string]time.Time),
}
}
@@ -456,6 +461,7 @@ func (e *Engine) pushTo(ctx context.Context, peer string, clip store.Clip) error
// 等发送缓冲排空再关闭,否则尾部数据会被丢弃
w.WaitDrained(ctx, 60*time.Second)
dc.Close()
+ e.forgetProgress(clip.ID)
ok := packErr == nil
errMsg := ""
@@ -621,6 +627,7 @@ func (e *Engine) finishReceive(r *receiver, cacheRel string, tops []string) {
e.mu.Lock()
delete(e.incoming, r.streamID)
e.mu.Unlock()
+ e.forgetProgress(r.clipID)
var size int64
for _, p := range tops {
@@ -770,10 +777,26 @@ func (e *Engine) emitRecord(clip store.Clip) {
})
}
+// progressInterval 是同一次传输两次进度上报之间的最小间隔。
+//
+// 进度原本按数据块上报,一个大文件会产生上万条事件。事件队列每个订阅者只缓冲 64 条,
+// 满了就丢弃新事件——「传输完成」那条记录更新也可能被挤掉,界面上的进度条就永远停不下来。
+const progressInterval = 200 * time.Millisecond
+
func (e *Engine) emitProgress(clipID string, sent, total int64, start time.Time) {
if e.onProgress == nil {
return
}
+ done := total > 0 && sent >= total
+ now := time.Now()
+ e.progressMu.Lock()
+ last, seen := e.lastProgress[clipID]
+ if !done && seen && now.Sub(last) < progressInterval {
+ e.progressMu.Unlock()
+ return
+ }
+ e.lastProgress[clipID] = now
+ e.progressMu.Unlock()
elapsed := time.Since(start).Seconds()
var rate float64
if elapsed > 0 {
@@ -784,6 +807,13 @@ func (e *Engine) emitProgress(clipID string, sent, total int64, start time.Time)
})
}
+// forgetProgress 在一次传输结束后清掉它的节流记录。
+func (e *Engine) forgetProgress(clipID string) {
+ e.progressMu.Lock()
+ delete(e.lastProgress, clipID)
+ e.progressMu.Unlock()
+}
+
// peerName 取对端设备名用于展示;查不到就退回 ID。
func (e *Engine) peerName(deviceID string) string {
devices, err := e.store.ListDevices()
diff --git a/client-core/internal/sync/progress_test.go b/client-core/internal/sync/progress_test.go
new file mode 100644
index 0000000..33beef3
--- /dev/null
+++ b/client-core/internal/sync/progress_test.go
@@ -0,0 +1,30 @@
+package sync
+
+import (
+ "testing"
+ "time"
+
+ pb "github.com/baiyuze/copysync/proto/gen/copysync/v1"
+)
+
+// 进度上报要节流:按数据块上报会把事件队列挤满,挤掉「传输完成」的记录更新。
+func TestEmitProgressThrottles(t *testing.T) {
+ var got []*pb.TransferProgress
+ e := &Engine{
+ onProgress: func(p *pb.TransferProgress) { got = append(got, p) },
+ lastProgress: make(map[string]time.Time),
+ }
+ start := time.Now()
+ const total = 10_000
+ for sent := int64(100); sent <= total; sent += 100 {
+ e.emitProgress("clip", sent, total, start)
+ }
+
+ if len(got) > 5 {
+ t.Errorf("连续 100 次上报产生了 %d 个事件,应被节流到个位数", len(got))
+ }
+ // 最后一条必须是 100%,界面靠它知道传完了
+ if last := got[len(got)-1]; last.GetTransferred() != total {
+ t.Errorf("最后一条进度 = %d,应为 %d", last.GetTransferred(), total)
+ }
+}
diff --git a/client-core/internal/transport/p2p/peer.go b/client-core/internal/transport/p2p/peer.go
index 44e34f4..6e47fa4 100644
--- a/client-core/internal/transport/p2p/peer.go
+++ b/client-core/internal/transport/p2p/peer.go
@@ -94,6 +94,8 @@ type Peer struct {
// 只看前者会导致状态报成"已连接"但 Send 立刻失败。
pcConnected bool
pendingKind ConnState
+ // remoteRelayed 是对端经 LinkInfo 告知的「它那边是否走中转」,见 wire.proto 的 LinkInfo
+ remoteRelayed bool
// connectTimer 在握手迟迟不完成时触发重置,避免永久卡在 connecting
connectTimer *time.Timer
// dialing 表示 Connect 正在进行中,防止并发重入建出两个 PeerConnection
@@ -491,7 +493,11 @@ func (p *Peer) maybeReady() {
p.mu.Lock()
ready := p.pcConnected && p.control != nil &&
p.control.ReadyState() == webrtc.DataChannelStateOpen
- kind := p.pendingKind
+ ownView := p.pendingKind
+ kind := ownView
+ if p.remoteRelayed {
+ kind = StateRelay
+ }
p.mu.Unlock()
if ready {
@@ -502,11 +508,47 @@ func (p *Peer) maybeReady() {
}
p.mu.Unlock()
p.setState(kind)
+ // 只有本端能确定自己发出的数据走没走 TURN,告诉对端,让两边显示一致
+ _ = p.Send(&pb.PeerMessage{Payload: &pb.PeerMessage_Link{
+ Link: &pb.LinkInfo{Relayed: ownView == StateRelay},
+ }})
+ }
+}
+
+// handleLinkInfo 记下对端的视角;对端经中转时,本端也改报中转。
+func (p *Peer) handleLinkInfo(l *pb.LinkInfo) {
+ p.mu.Lock()
+ p.remoteRelayed = l.GetRelayed()
+ upgrade := l.GetRelayed() && p.state == StateDirect
+ p.mu.Unlock()
+ if upgrade {
+ p.setState(StateRelay)
}
}
// detectConnectionKind 判断当前选中的 candidate 对是直连还是经 TURN 中转。
+//
+// 两端的 candidate 都要看:只要有一端是 relay,数据就经过 TURN。
+// 常见的情形是一端在对称 NAT 后面,用自己的中转地址发送,另一端仍从普通地址收发;
+// 只看本端的话,后者会把中转误报成直连,两台设备一台显示直连、一台显示中转。
+//
+// 选中的 candidate 对直接从 ICE 传输层取:受控一方(answer 方)的统计数据里
+// 往往找不到标记为 nominated 的 candidate 对,只靠统计数据会落到默认值上。
func (p *Peer) detectConnectionKind(pc *webrtc.PeerConnection) ConnState {
+ if sctp := pc.SCTP(); sctp != nil && sctp.Transport() != nil {
+ if ice := sctp.Transport().ICETransport(); ice != nil {
+ if pair, err := ice.GetSelectedCandidatePair(); err == nil && pair != nil &&
+ pair.Local != nil && pair.Remote != nil {
+ if pair.Local.Typ == webrtc.ICECandidateTypeRelay ||
+ pair.Remote.Typ == webrtc.ICECandidateTypeRelay {
+ return StateRelay
+ }
+ return StateDirect
+ }
+ }
+ }
+
+ // 取不到选中的 candidate 对时,退回统计数据
stats := pc.GetStats()
for _, s := range stats {
pair, ok := s.(webrtc.ICECandidatePairStats)
@@ -515,16 +557,14 @@ func (p *Peer) detectConnectionKind(pc *webrtc.PeerConnection) ConnState {
}
for _, cs := range stats {
c, ok := cs.(webrtc.ICECandidateStats)
- if !ok || c.ID != pair.LocalCandidateID {
- continue
- }
- if c.CandidateType == webrtc.ICECandidateTypeRelay {
+ if ok && (c.ID == pair.LocalCandidateID || c.ID == pair.RemoteCandidateID) &&
+ c.CandidateType == webrtc.ICECandidateTypeRelay {
return StateRelay
}
- return StateDirect
}
+ return StateDirect
}
- // 拿不到明细时保守地报直连——功能不受影响,只是显示可能不准
+ // 拿不到明细时报直连——功能不受影响,只是显示可能不准
return StateDirect
}
@@ -547,6 +587,10 @@ func (p *Peer) bindControl(dc *webrtc.DataChannel) {
p.log.Warn("控制消息解析失败", "err", err)
return
}
+ if l := m.GetLink(); l != nil {
+ p.handleLinkInfo(l) // 连接层自己的消息,不交给同步引擎
+ return
+ }
if p.onMessage != nil {
p.onMessage(&m)
}
@@ -606,6 +650,7 @@ func (p *Peer) closeLocked() {
p.pcConnected = false
p.makingOffer = false
p.pendingKind = StateOffline
+ p.remoteRelayed = false
p.dialing = false
if p.connectTimer != nil {
p.connectTimer.Stop()
diff --git a/client-core/internal/transport/p2p/relay_test.go b/client-core/internal/transport/p2p/relay_test.go
index ae0e886..ce12a6e 100644
--- a/client-core/internal/transport/p2p/relay_test.go
+++ b/client-core/internal/transport/p2p/relay_test.go
@@ -29,8 +29,8 @@ func TestRelayFallback(t *testing.T) {
defer turnSrv.Close()
r := newRelay()
- alice := newRelayHarness(t, "alice", r, turnSrv)
- bob := newRelayHarness(t, "bob", r, turnSrv)
+ alice := newRelayHarness(t, "alice", r, turnSrv, true)
+ bob := newRelayHarness(t, "bob", r, turnSrv, true)
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second)
defer cancel()
@@ -65,7 +65,52 @@ func TestRelayFallback(t *testing.T) {
}
}
-func newRelayHarness(t *testing.T, id string, r *relay, turnSrv *turnrelay.Server) *harness {
+// TestRelayOneSided 验证只有一端走中转时,两端都识别为中转。
+//
+// 真实网络里常见的情形:一端在对称 NAT 后面打不通,用自己的 TURN 中转地址发送;
+// 另一端仍从普通地址收发。只看本端 candidate 的话,后者会把中转误报成直连,
+// 两台设备一台显示「直连」一台显示「中转」。
+func TestRelayOneSided(t *testing.T) {
+ turnSrv, err := turnrelay.New(turnrelay.Options{
+ PublicIP: "127.0.0.1",
+ Port: 34781,
+ Secret: "test-secret",
+ CredentialTTL: time.Hour,
+ })
+ if err != nil {
+ t.Skipf("无法启动 TURN 服务(端口可能被占用): %v", err)
+ }
+ defer turnSrv.Close()
+
+ r := newRelay()
+ alice := newRelayHarness(t, "alice", r, turnSrv, true) // 只能走中转
+ bob := newRelayHarness(t, "bob", r, turnSrv, false) // 普通设备
+
+ ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second)
+ defer cancel()
+ if err := alice.manager.Connect(ctx, "bob"); err != nil {
+ t.Fatalf("发起连接: %v", err)
+ }
+
+ waitConnected(t, alice, "bob")
+ waitConnected(t, bob, "alice")
+
+ // bob 自己看到的对端地址可能只是个普通地址,要等 alice 发来 LinkInfo 才改报中转,
+ // 所以这里等最终状态,而不是第一次报告的状态
+ deadline := time.Now().Add(5 * time.Second)
+ for time.Now().Before(deadline) &&
+ (alice.manager.State("bob") != p2p.StateRelay || bob.manager.State("alice") != p2p.StateRelay) {
+ time.Sleep(50 * time.Millisecond)
+ }
+ if s := alice.manager.State("bob"); s != p2p.StateRelay {
+ t.Errorf("alice 的连接方式 = %v,应为 relay", s)
+ }
+ if s := bob.manager.State("alice"); s != p2p.StateRelay {
+ t.Errorf("bob 的连接方式 = %v,对端经中转发送时也应识别为 relay", s)
+ }
+}
+
+func newRelayHarness(t *testing.T, id string, r *relay, turnSrv *turnrelay.Server, forceRelay bool) *harness {
t.Helper()
h := &harness{
@@ -77,7 +122,7 @@ func newRelayHarness(t *testing.T, id string, r *relay, turnSrv *turnrelay.Serve
h.manager = p2p.NewManager(p2p.ManagerOptions{
SelfID: id,
SendSignal: r.send(id),
- ForceRelay: true,
+ ForceRelay: forceRelay,
OnState: func(_ string, s p2p.ConnState) {
select {
case h.states <- s:
diff --git a/docs/en/index.html b/docs/en/index.html
index 96b6426..3dc6d2f 100644
--- a/docs/en/index.html
+++ b/docs/en/index.html
@@ -40,7 +40,7 @@
"description": "Open-source tool that syncs the clipboard and files between Macs. Copy text, images, files or folders on one Mac and paste them on another. Devices connect directly over WebRTC with DTLS encryption, falling back to a TURN relay on a server the user hosts.",
"applicationCategory": "UtilitiesApplication",
"operatingSystem": "macOS 13 or later (Intel and Apple silicon)",
- "softwareVersion": "1.0.1",
+ "softwareVersion": "1.0.2",
"datePublished": "2026-10-08",
"inLanguage": "en",
"license": "https://opensource.org/licenses/MIT",
@@ -134,7 +134,7 @@
<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 3v10m0 0-4-4m4 4 4-4M4 16h12"/></svg>
Download for macOS
</a>
- <span class="note">Version 1.0.1, free and open source. macOS 13 or later, Intel and Apple silicon.</span>
+ <span class="note">Version 1.0.2, free and open source. macOS 13 or later, Intel and Apple silicon.</span>
</div>
<div class="demo" role="img" aria-label="Demo: a file is selected on a MacBook Pro and copied with Command C, travels over a direct connection to a MacBook Air, and is pasted there with Command V">
@@ -362,7 +362,7 @@ sudo ./install.sh YOUR_PUBLIC_IP</code></pre>
<div class="table-scroll">
<table class="specs">
<tbody>
- <tr><th scope="row">Version</th><td>1.0.1, released <time datetime="2026-10-08">October 8, 2026</time></td></tr>
+ <tr><th scope="row">Version</th><td>1.0.2, released <time datetime="2026-10-08">October 8, 2026</time></td></tr>
<tr><th scope="row">Mac app</th><td>macOS 13 Ventura or later; universal binary for Intel and Apple silicon, no Rosetta; 45 MB download</td></tr>
<tr><th scope="row">Server</th><td>Linux on x86_64 or ARM64 (systemd or Docker), or macOS; about 15 MB of RAM</td></tr>
<tr><th scope="row">Content</th><td>Plain text, rich text, images and screenshots, files, folders; each type can be turned off</td></tr>
diff --git a/docs/index.html b/docs/index.html
index 9e6be3b..009f94a 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -40,7 +40,7 @@
"description": "在两台 Mac 之间同步剪贴板与文件的开源工具。复制文本、图片、文件或文件夹后,另一台 Mac 可直接粘贴。设备间 WebRTC 直连、DTLS 端到端加密,打不通时经用户自建服务器的 TURN 中转。",
"applicationCategory": "UtilitiesApplication",
"operatingSystem": "macOS 13 及以上(Intel 与 Apple 芯片)",
- "softwareVersion": "1.0.1",
+ "softwareVersion": "1.0.2",
"datePublished": "2026-10-08",
"inLanguage": "zh-CN",
"license": "https://opensource.org/licenses/MIT",
@@ -134,7 +134,7 @@
<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 3v10m0 0-4-4m4 4 4-4M4 16h12"/></svg>
下载 macOS 版
</a>
- <span class="note">版本 1.0.1,免费开源。macOS 13 及以上,Intel 与 Apple 芯片通用。</span>
+ <span class="note">版本 1.0.2,免费开源。macOS 13 及以上,Intel 与 Apple 芯片通用。</span>
</div>
<div class="demo" role="img" aria-label="演示:在 MacBook Pro 上选中文件并按下 Command C,文件经直连传到 MacBook Air,在那里按下 Command V 粘贴出来">
@@ -362,7 +362,7 @@ sudo ./install.sh 你的公网IP</code></pre>
<div class="table-scroll">
<table class="specs">
<tbody>
- <tr><th scope="row">版本</th><td>1.0.1,<time datetime="2026-10-08">2026 年 10 月 8 日</time>发布</td></tr>
+ <tr><th scope="row">版本</th><td>1.0.2,<time datetime="2026-10-08">2026 年 10 月 8 日</time>发布</td></tr>
<tr><th scope="row">Mac 客户端</th><td>macOS 13 Ventura 及以上;Intel 与 Apple 芯片通用,不需要 Rosetta;安装包 45 MB</td></tr>
<tr><th scope="row">服务器</th><td>Linux x86_64 或 ARM64(systemd 或 Docker),也可以运行在 macOS 上;约 15 MB 内存</td></tr>
<tr><th scope="row">同步的内容</th><td>纯文本、带格式的文本、图片与截图、文件、文件夹,可以按类型关闭</td></tr>
diff --git a/docs/llms.txt b/docs/llms.txt
index ca83f04..c6286bc 100644
--- a/docs/llms.txt
+++ b/docs/llms.txt
@@ -6,7 +6,7 @@
Key facts:
-- Current version: 1.0.1, released 2026-10-08.
+- Current version: 1.0.2, released 2026-10-08.
- Client: macOS 13 Ventura or later, universal binary for Intel and Apple silicon. Distributed as a DMG; not notarized by Apple, so the first launch needs "Open Anyway" in System Settings → Privacy & Security.
- Server: a single static Go binary for Linux (x86_64, ARM64) or macOS, installed via systemd script or Docker Compose. Ports: 8787/tcp (signaling), 3478/udp (STUN/TURN), 32768–60999/udp (relay).
- Content synced: plain text, rich text (HTML plus a plain-text copy), images, files, folders.
diff --git a/proto/copysync/v1/wire.proto b/proto/copysync/v1/wire.proto
index d642e04..b4e8593 100644
--- a/proto/copysync/v1/wire.proto
+++ b/proto/copysync/v1/wire.proto
@@ -168,9 +168,17 @@ message PeerMessage {
FetchReject reject = 3; // 拒绝:源文件没了 / 已过期
TransferHeader header = 4; // 数据流即将开始
TransferDone done = 5;
+ LinkInfo link = 6; // 连接建立后互相告知本端是否经中转
}
}
+// 连接就绪后各自发一次。只有本端能确定自己发出的数据是否走 TURN:
+// 对端经中转发来的包,在本端看来可能只是一个普通地址(peer-reflexive),
+// 单靠自己的视角会把中转误判成直连。两端交换后,任一端经中转即显示为中转。
+message LinkInfo {
+ bool relayed = 1;
+}
+
// 复制发生时广播给所有在线对端。
// 小于阈值的内容会紧接着主动推送;大于阈值的只发这条,等对方来取。
message ClipOffer {
diff --git a/proto/gen/copysync/v1/wire.pb.go b/proto/gen/copysync/v1/wire.pb.go
index bd32fe0..0b11947 100644
--- a/proto/gen/copysync/v1/wire.pb.go
+++ b/proto/gen/copysync/v1/wire.pb.go
@@ -1510,6 +1510,7 @@ type PeerMessage struct {
// *PeerMessage_Reject
// *PeerMessage_Header
// *PeerMessage_Done
+ // *PeerMessage_Link
Payload isPeerMessage_Payload `protobuf_oneof:"payload"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
@@ -1597,6 +1598,15 @@ func (x *PeerMessage) GetDone() *TransferDone {
return nil
}
+func (x *PeerMessage) GetLink() *LinkInfo {
+ if x != nil {
+ if x, ok := x.Payload.(*PeerMessage_Link); ok {
+ return x.Link
+ }
+ }
+ return nil
+}
+
type isPeerMessage_Payload interface {
isPeerMessage_Payload()
}
@@ -1621,6 +1631,10 @@ type PeerMessage_Done struct {
Done *TransferDone `protobuf:"bytes,5,opt,name=done,proto3,oneof"`
}
+type PeerMessage_Link struct {
+ Link *LinkInfo `protobuf:"bytes,6,opt,name=link,proto3,oneof"` // 连接建立后互相告知本端是否经中转
+}
+
func (*PeerMessage_Offer) isPeerMessage_Payload() {}
func (*PeerMessage_Fetch) isPeerMessage_Payload() {}
@@ -1631,6 +1645,55 @@ func (*PeerMessage_Header) isPeerMessage_Payload() {}
func (*PeerMessage_Done) isPeerMessage_Payload() {}
+func (*PeerMessage_Link) isPeerMessage_Payload() {}
+
+// 连接就绪后各自发一次。只有本端能确定自己发出的数据是否走 TURN:
+// 对端经中转发来的包,在本端看来可能只是一个普通地址(peer-reflexive),
+// 单靠自己的视角会把中转误判成直连。两端交换后,任一端经中转即显示为中转。
+type LinkInfo struct {
+ state protoimpl.MessageState `protogen:"open.v1"`
+ Relayed bool `protobuf:"varint,1,opt,name=relayed,proto3" json:"relayed,omitempty"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
+}
+
+func (x *LinkInfo) Reset() {
+ *x = LinkInfo{}
+ mi := &file_copysync_v1_wire_proto_msgTypes[20]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+}
+
+func (x *LinkInfo) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*LinkInfo) ProtoMessage() {}
+
+func (x *LinkInfo) ProtoReflect() protoreflect.Message {
+ mi := &file_copysync_v1_wire_proto_msgTypes[20]
+ if x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use LinkInfo.ProtoReflect.Descriptor instead.
+func (*LinkInfo) Descriptor() ([]byte, []int) {
+ return file_copysync_v1_wire_proto_rawDescGZIP(), []int{20}
+}
+
+func (x *LinkInfo) GetRelayed() bool {
+ if x != nil {
+ return x.Relayed
+ }
+ return false
+}
+
// 复制发生时广播给所有在线对端。
// 小于阈值的内容会紧接着主动推送;大于阈值的只发这条,等对方来取。
type ClipOffer struct {
@@ -1651,7 +1714,7 @@ type ClipOffer struct {
func (x *ClipOffer) Reset() {
*x = ClipOffer{}
- mi := &file_copysync_v1_wire_proto_msgTypes[20]
+ mi := &file_copysync_v1_wire_proto_msgTypes[21]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1663,7 +1726,7 @@ func (x *ClipOffer) String() string {
func (*ClipOffer) ProtoMessage() {}
func (x *ClipOffer) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_wire_proto_msgTypes[20]
+ mi := &file_copysync_v1_wire_proto_msgTypes[21]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1676,7 +1739,7 @@ func (x *ClipOffer) ProtoReflect() protoreflect.Message {
// Deprecated: Use ClipOffer.ProtoReflect.Descriptor instead.
func (*ClipOffer) Descriptor() ([]byte, []int) {
- return file_copysync_v1_wire_proto_rawDescGZIP(), []int{20}
+ return file_copysync_v1_wire_proto_rawDescGZIP(), []int{21}
}
func (x *ClipOffer) GetClipId() string {
@@ -1745,7 +1808,7 @@ type PeerFetch struct {
func (x *PeerFetch) Reset() {
*x = PeerFetch{}
- mi := &file_copysync_v1_wire_proto_msgTypes[21]
+ mi := &file_copysync_v1_wire_proto_msgTypes[22]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1757,7 +1820,7 @@ func (x *PeerFetch) String() string {
func (*PeerFetch) ProtoMessage() {}
func (x *PeerFetch) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_wire_proto_msgTypes[21]
+ mi := &file_copysync_v1_wire_proto_msgTypes[22]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1770,7 +1833,7 @@ func (x *PeerFetch) ProtoReflect() protoreflect.Message {
// Deprecated: Use PeerFetch.ProtoReflect.Descriptor instead.
func (*PeerFetch) Descriptor() ([]byte, []int) {
- return file_copysync_v1_wire_proto_rawDescGZIP(), []int{21}
+ return file_copysync_v1_wire_proto_rawDescGZIP(), []int{22}
}
func (x *PeerFetch) GetClipId() string {
@@ -1790,7 +1853,7 @@ type FetchReject struct {
func (x *FetchReject) Reset() {
*x = FetchReject{}
- mi := &file_copysync_v1_wire_proto_msgTypes[22]
+ mi := &file_copysync_v1_wire_proto_msgTypes[23]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1802,7 +1865,7 @@ func (x *FetchReject) String() string {
func (*FetchReject) ProtoMessage() {}
func (x *FetchReject) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_wire_proto_msgTypes[22]
+ mi := &file_copysync_v1_wire_proto_msgTypes[23]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1815,7 +1878,7 @@ func (x *FetchReject) ProtoReflect() protoreflect.Message {
// Deprecated: Use FetchReject.ProtoReflect.Descriptor instead.
func (*FetchReject) Descriptor() ([]byte, []int) {
- return file_copysync_v1_wire_proto_rawDescGZIP(), []int{22}
+ return file_copysync_v1_wire_proto_rawDescGZIP(), []int{23}
}
func (x *FetchReject) GetClipId() string {
@@ -1846,7 +1909,7 @@ type TransferHeader struct {
func (x *TransferHeader) Reset() {
*x = TransferHeader{}
- mi := &file_copysync_v1_wire_proto_msgTypes[23]
+ mi := &file_copysync_v1_wire_proto_msgTypes[24]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1858,7 +1921,7 @@ func (x *TransferHeader) String() string {
func (*TransferHeader) ProtoMessage() {}
func (x *TransferHeader) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_wire_proto_msgTypes[23]
+ mi := &file_copysync_v1_wire_proto_msgTypes[24]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1871,7 +1934,7 @@ func (x *TransferHeader) ProtoReflect() protoreflect.Message {
// Deprecated: Use TransferHeader.ProtoReflect.Descriptor instead.
func (*TransferHeader) Descriptor() ([]byte, []int) {
- return file_copysync_v1_wire_proto_rawDescGZIP(), []int{23}
+ return file_copysync_v1_wire_proto_rawDescGZIP(), []int{24}
}
func (x *TransferHeader) GetClipId() string {
@@ -1922,7 +1985,7 @@ type TransferDone struct {
func (x *TransferDone) Reset() {
*x = TransferDone{}
- mi := &file_copysync_v1_wire_proto_msgTypes[24]
+ mi := &file_copysync_v1_wire_proto_msgTypes[25]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1934,7 +1997,7 @@ func (x *TransferDone) String() string {
func (*TransferDone) ProtoMessage() {}
func (x *TransferDone) ProtoReflect() protoreflect.Message {
- mi := &file_copysync_v1_wire_proto_msgTypes[24]
+ mi := &file_copysync_v1_wire_proto_msgTypes[25]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1947,7 +2010,7 @@ func (x *TransferDone) ProtoReflect() protoreflect.Message {
// Deprecated: Use TransferDone.ProtoReflect.Descriptor instead.
func (*TransferDone) Descriptor() ([]byte, []int) {
- return file_copysync_v1_wire_proto_rawDescGZIP(), []int{24}
+ return file_copysync_v1_wire_proto_rawDescGZIP(), []int{25}
}
func (x *TransferDone) GetClipId() string {
@@ -2089,14 +2152,17 @@ const file_copysync_v1_wire_proto_rawDesc = "" +
"\apayload\";\n" +
"\vServerError\x12\x12\n" +
"\x04code\x18\x01 \x01(\tR\x04code\x12\x18\n" +
- "\amessage\x18\x02 \x01(\tR\amessage\"\x94\x02\n" +
+ "\amessage\x18\x02 \x01(\tR\amessage\"\xc1\x02\n" +
"\vPeerMessage\x12.\n" +
"\x05offer\x18\x01 \x01(\v2\x16.copysync.v1.ClipOfferH\x00R\x05offer\x12.\n" +
"\x05fetch\x18\x02 \x01(\v2\x16.copysync.v1.PeerFetchH\x00R\x05fetch\x122\n" +
"\x06reject\x18\x03 \x01(\v2\x18.copysync.v1.FetchRejectH\x00R\x06reject\x125\n" +
"\x06header\x18\x04 \x01(\v2\x1b.copysync.v1.TransferHeaderH\x00R\x06header\x12/\n" +
- "\x04done\x18\x05 \x01(\v2\x19.copysync.v1.TransferDoneH\x00R\x04doneB\t\n" +
- "\apayload\"\xa2\x02\n" +
+ "\x04done\x18\x05 \x01(\v2\x19.copysync.v1.TransferDoneH\x00R\x04done\x12+\n" +
+ "\x04link\x18\x06 \x01(\v2\x15.copysync.v1.LinkInfoH\x00R\x04linkB\t\n" +
+ "\apayload\"$\n" +
+ "\bLinkInfo\x12\x18\n" +
+ "\arelayed\x18\x01 \x01(\bR\arelayed\"\xa2\x02\n" +
"\tClipOffer\x12\x17\n" +
"\aclip_id\x18\x01 \x01(\tR\x06clipId\x12)\n" +
"\x04kind\x18\x02 \x01(\x0e2\x15.copysync.v1.ClipKindR\x04kind\x12+\n" +
@@ -2148,7 +2214,7 @@ func file_copysync_v1_wire_proto_rawDescGZIP() []byte {
}
var file_copysync_v1_wire_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
-var file_copysync_v1_wire_proto_msgTypes = make([]protoimpl.MessageInfo, 25)
+var file_copysync_v1_wire_proto_msgTypes = make([]protoimpl.MessageInfo, 26)
var file_copysync_v1_wire_proto_goTypes = []any{
(Compression)(0), // 0: copysync.v1.Compression
(Packaging)(0), // 1: copysync.v1.Packaging
@@ -2172,13 +2238,14 @@ var file_copysync_v1_wire_proto_goTypes = []any{
(*ClientEnvelope)(nil), // 19: copysync.v1.ClientEnvelope
(*ServerError)(nil), // 20: copysync.v1.ServerError
(*PeerMessage)(nil), // 21: copysync.v1.PeerMessage
- (*ClipOffer)(nil), // 22: copysync.v1.ClipOffer
- (*PeerFetch)(nil), // 23: copysync.v1.PeerFetch
- (*FetchReject)(nil), // 24: copysync.v1.FetchReject
- (*TransferHeader)(nil), // 25: copysync.v1.TransferHeader
- (*TransferDone)(nil), // 26: copysync.v1.TransferDone
- (ClipKind)(0), // 27: copysync.v1.ClipKind
- (*ClipItem)(nil), // 28: copysync.v1.ClipItem
+ (*LinkInfo)(nil), // 22: copysync.v1.LinkInfo
+ (*ClipOffer)(nil), // 23: copysync.v1.ClipOffer
+ (*PeerFetch)(nil), // 24: copysync.v1.PeerFetch
+ (*FetchReject)(nil), // 25: copysync.v1.FetchReject
+ (*TransferHeader)(nil), // 26: copysync.v1.TransferHeader
+ (*TransferDone)(nil), // 27: copysync.v1.TransferDone
+ (ClipKind)(0), // 28: copysync.v1.ClipKind
+ (*ClipItem)(nil), // 29: copysync.v1.ClipItem
}
var file_copysync_v1_wire_proto_depIdxs = []int32{
4, // 0: copysync.v1.SignalMessage.offer:type_name -> copysync.v1.SdpOffer
@@ -2199,20 +2266,21 @@ var file_copysync_v1_wire_proto_depIdxs = []int32{
2, // 15: copysync.v1.ClientEnvelope.forward:type_name -> copysync.v1.Signed
12, // 16: copysync.v1.ClientEnvelope.pairing_create:type_name -> copysync.v1.PairingCreateRequest
14, // 17: copysync.v1.ClientEnvelope.pairing_redeem:type_name -> copysync.v1.PairingRedeemRequest
- 22, // 18: copysync.v1.PeerMessage.offer:type_name -> copysync.v1.ClipOffer
- 23, // 19: copysync.v1.PeerMessage.fetch:type_name -> copysync.v1.PeerFetch
- 24, // 20: copysync.v1.PeerMessage.reject:type_name -> copysync.v1.FetchReject
- 25, // 21: copysync.v1.PeerMessage.header:type_name -> copysync.v1.TransferHeader
- 26, // 22: copysync.v1.PeerMessage.done:type_name -> copysync.v1.TransferDone
- 27, // 23: copysync.v1.ClipOffer.kind:type_name -> copysync.v1.ClipKind
- 28, // 24: copysync.v1.ClipOffer.items:type_name -> copysync.v1.ClipItem
- 0, // 25: copysync.v1.TransferHeader.compression:type_name -> copysync.v1.Compression
- 1, // 26: copysync.v1.TransferHeader.packaging:type_name -> copysync.v1.Packaging
- 27, // [27:27] is the sub-list for method output_type
- 27, // [27:27] is the sub-list for method input_type
- 27, // [27:27] is the sub-list for extension type_name
- 27, // [27:27] is the sub-list for extension extendee
- 0, // [0:27] is the sub-list for field type_name
+ 23, // 18: copysync.v1.PeerMessage.offer:type_name -> copysync.v1.ClipOffer
+ 24, // 19: copysync.v1.PeerMessage.fetch:type_name -> copysync.v1.PeerFetch
+ 25, // 20: copysync.v1.PeerMessage.reject:type_name -> copysync.v1.FetchReject
+ 26, // 21: copysync.v1.PeerMessage.header:type_name -> copysync.v1.TransferHeader
+ 27, // 22: copysync.v1.PeerMessage.done:type_name -> copysync.v1.TransferDone
+ 22, // 23: copysync.v1.PeerMessage.link:type_name -> copysync.v1.LinkInfo
+ 28, // 24: copysync.v1.ClipOffer.kind:type_name -> copysync.v1.ClipKind
+ 29, // 25: copysync.v1.ClipOffer.items:type_name -> copysync.v1.ClipItem
+ 0, // 26: copysync.v1.TransferHeader.compression:type_name -> copysync.v1.Compression
+ 1, // 27: copysync.v1.TransferHeader.packaging:type_name -> copysync.v1.Packaging
+ 28, // [28:28] is the sub-list for method output_type
+ 28, // [28:28] is the sub-list for method input_type
+ 28, // [28:28] is the sub-list for extension type_name
+ 28, // [28:28] is the sub-list for extension extendee
+ 0, // [0:28] is the sub-list for field type_name
}
func init() { file_copysync_v1_wire_proto_init() }
@@ -2249,6 +2317,7 @@ func file_copysync_v1_wire_proto_init() {
(*PeerMessage_Reject)(nil),
(*PeerMessage_Header)(nil),
(*PeerMessage_Done)(nil),
+ (*PeerMessage_Link)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
@@ -2256,7 +2325,7 @@ func file_copysync_v1_wire_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_copysync_v1_wire_proto_rawDesc), len(file_copysync_v1_wire_proto_rawDesc)),
NumEnums: 2,
- NumMessages: 25,
+ NumMessages: 26,
NumExtensions: 0,
NumServices: 0,
},
diff --git a/scripts/build.sh b/scripts/build.sh
index 20eb2ed..1492183 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -14,7 +14,7 @@ set -euo pipefail
cd "$(dirname "$0")/.."
DIST=dist
-VERSION=${VERSION:-1.0.1}
+VERSION=${VERSION:-1.0.2}
rm -rf "$DIST" && mkdir -p "$DIST"
# 构建 x86_64 + arm64 通用二进制:两台 Mac 的芯片未必相同,单架构的
diff --git a/scripts/package.sh b/scripts/package.sh
index 82668ce..b678161 100755
--- a/scripts/package.sh
+++ b/scripts/package.sh
@@ -15,7 +15,7 @@
set -euo pipefail
cd "$(dirname "$0")/.."
-export VERSION=${VERSION:-1.0.1}
+export VERSION=${VERSION:-1.0.2}
OUT=release
./scripts/build.sh
diff --git a/ui/lib/app_state.dart b/ui/lib/app_state.dart
index 2c0bf9d..a3f7274 100644
--- a/ui/lib/app_state.dart
+++ b/ui/lib/app_state.dart
@@ -32,6 +32,9 @@ class AppState extends ChangeNotifier {
List<Device> _peers = const [];
final List<ClipRecord> _records = [];
+ /// 正在传输的记录的进度(0–1),只在界面上展示,传完即移除。
+ final Map<String, double> _progress = {};
+
/// 待用户核对指纹的配对请求。非空时界面弹出确认。
Device? _pendingPairing;
@@ -46,6 +49,9 @@ class AppState extends ChangeNotifier {
Device? get self => _self;
List<Device> get peers => List.unmodifiable(_peers);
List<ClipRecord> get records => List.unmodifiable(_records);
+
+ /// 传输进度;总量未知或尚未开始时为 null。
+ double? progressOf(String clipId) => _progress[clipId];
Device? get pendingPairing => _pendingPairing;
ServiceState? get serviceState => _serviceState;
@@ -216,17 +222,13 @@ class AppState extends ChangeNotifier {
void _onEvent(Event ev) {
final added = ev.whichPayload();
switch (added) {
+ // 同一条记录会被推送多次(开始接收时一次、接收完成时一次),一律按 id 合并,
+ // 否则界面上会出现两行,其中「接收中」那行的进度条永远停不下来
case Event_Payload.clipAdded:
- _records.insert(0, ev.clipAdded);
- if (_records.length > 500) _records.removeLast();
+ _upsert(ev.clipAdded);
case Event_Payload.clipUpdated:
- final i = _records.indexWhere((r) => r.id == ev.clipUpdated.id);
- if (i >= 0) {
- _records[i] = ev.clipUpdated;
- } else {
- _records.insert(0, ev.clipUpdated);
- }
+ _upsert(ev.clipUpdated);
case Event_Payload.clipRemoved:
_records.removeWhere((r) => r.id == ev.clipRemoved);
@@ -238,10 +240,7 @@ class AppState extends ChangeNotifier {
_status = ev.statusChanged;
case Event_Payload.progress:
- final i = _records.indexWhere((r) => r.id == ev.progress.clipId);
- if (i >= 0) {
- _records[i] = _records[i]..status = ClipStatus.CLIP_STATUS_FETCHING;
- }
+ _onProgress(ev.progress);
default:
break;
@@ -249,6 +248,39 @@ class AppState extends ChangeNotifier {
notifyListeners();
}
+ void _upsert(ClipRecord r) {
+ final i = _records.indexWhere((x) => x.id == r.id);
+ if (i >= 0) {
+ _records[i] = r;
+ } else {
+ _records.insert(0, r);
+ if (_records.length > 500) _records.removeLast();
+ }
+ // 传完(或失败)了就不再显示进度
+ if (r.status != ClipStatus.CLIP_STATUS_FETCHING) _progress.remove(r.id);
+ }
+
+ /// 进度事件只用于「从对端接收」的记录:本机复制的记录在发送时也会产生进度,
+ /// 若把它们也标成「接收中」,就再也没有事件能把状态改回来。
+ void _onProgress(TransferProgress p) {
+ final i = _records.indexWhere((r) => r.id == p.clipId);
+ if (i < 0 || _records[i].outgoing) return;
+ final r = _records[i];
+ if (r.status == ClipStatus.CLIP_STATUS_REMOTE_ONLY) {
+ // 用户点了「拉取到本机」,开始传了
+ _records[i] = r.deepCopy()..status = ClipStatus.CLIP_STATUS_FETCHING;
+ } else if (r.status != ClipStatus.CLIP_STATUS_FETCHING) {
+ return; // 已经传完的记录,迟到的进度事件不能把它拉回「接收中」
+ }
+ if (p.total > 0) {
+ _progress[p.clipId] = (p.transferred.toInt() / p.total.toInt()).clamp(0.0, 1.0);
+ }
+ }
+
+ /// 测试用:直接注入一条后台服务的事件。
+ @visibleForTesting
+ void debugEvent(Event ev) => _onEvent(ev);
+
void _onDeviceChanged(Device d) {
// 带 pairingSession 的不是已配对设备,而是一条待确认的配对请求
if (d.pairingSession.isNotEmpty) {
diff --git a/ui/lib/gen/copysync/v1/wire.pb.dart b/ui/lib/gen/copysync/v1/wire.pb.dart
index 19a5468..839c8cc 100644
--- a/ui/lib/gen/copysync/v1/wire.pb.dart
+++ b/ui/lib/gen/copysync/v1/wire.pb.dart
@@ -1785,7 +1785,7 @@ class ServerError extends $pb.GeneratedMessage {
void clearMessage() => $_clearField(2);
}
-enum PeerMessage_Payload { offer, fetch, reject, header, done, notSet }
+enum PeerMessage_Payload { offer, fetch, reject, header, done, link, notSet }
/// 控制通道消息
class PeerMessage extends $pb.GeneratedMessage {
@@ -1795,6 +1795,7 @@ class PeerMessage extends $pb.GeneratedMessage {
FetchReject? reject,
TransferHeader? header,
TransferDone? done,
+ LinkInfo? link,
}) {
final result = PeerMessage._();
if (offer != null) result.offer = offer;
@@ -1802,6 +1803,7 @@ class PeerMessage extends $pb.GeneratedMessage {
if (reject != null) result.reject = reject;
if (header != null) result.header = header;
if (done != null) result.done = done;
+ if (link != null) result.link = link;
return result;
}
@@ -1821,13 +1823,14 @@ class PeerMessage extends $pb.GeneratedMessage {
3: PeerMessage_Payload.reject,
4: PeerMessage_Payload.header,
5: PeerMessage_Payload.done,
+ 6: PeerMessage_Payload.link,
0: PeerMessage_Payload.notSet
};
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
_omitMessageNames ? '' : 'PeerMessage',
package: const $pb.PackageName(_omitMessageNames ? '' : 'copysync.v1'),
createEmptyInstance: PeerMessage.$_createMessage)
- ..oo(0, [1, 2, 3, 4, 5])
+ ..oo(0, [1, 2, 3, 4, 5, 6])
..aOM<ClipOffer>(1, _omitFieldNames ? '' : 'offer',
subBuilder: ClipOffer.$_createMessage)
..aOM<PeerFetch>(2, _omitFieldNames ? '' : 'fetch',
@@ -1838,6 +1841,8 @@ class PeerMessage extends $pb.GeneratedMessage {
subBuilder: TransferHeader.$_createMessage)
..aOM<TransferDone>(5, _omitFieldNames ? '' : 'done',
subBuilder: TransferDone.$_createMessage)
+ ..aOM<LinkInfo>(6, _omitFieldNames ? '' : 'link',
+ subBuilder: LinkInfo.$_createMessage)
..hasRequiredFields = false;
@$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.')
@@ -1867,6 +1872,7 @@ class PeerMessage extends $pb.GeneratedMessage {
@$pb.TagNumber(3)
@$pb.TagNumber(4)
@$pb.TagNumber(5)
+ @$pb.TagNumber(6)
PeerMessage_Payload whichPayload() =>
_PeerMessage_PayloadByTag[$_whichOneof(0)]!;
@$pb.TagNumber(1)
@@ -1874,6 +1880,7 @@ class PeerMessage extends $pb.GeneratedMessage {
@$pb.TagNumber(3)
@$pb.TagNumber(4)
@$pb.TagNumber(5)
+ @$pb.TagNumber(6)
void clearPayload() => $_clearField($_whichOneof(0));
@$pb.TagNumber(1)
@@ -1930,6 +1937,75 @@ class PeerMessage extends $pb.GeneratedMessage {
void clearDone() => $_clearField(5);
@$pb.TagNumber(5)
TransferDone ensureDone() => $_ensure(4);
+
+ @$pb.TagNumber(6)
+ LinkInfo get link => $_getN(5);
+ @$pb.TagNumber(6)
+ set link(LinkInfo value) => $_setField(6, value);
+ @$pb.TagNumber(6)
+ $core.bool hasLink() => $_has(5);
+ @$pb.TagNumber(6)
+ void clearLink() => $_clearField(6);
+ @$pb.TagNumber(6)
+ LinkInfo ensureLink() => $_ensure(5);
+}
+
+/// 连接就绪后各自发一次。只有本端能确定自己发出的数据是否走 TURN:
+/// 对端经中转发来的包,在本端看来可能只是一个普通地址(peer-reflexive),
+/// 单靠自己的视角会把中转误判成直连。两端交换后,任一端经中转即显示为中转。
+class LinkInfo extends $pb.GeneratedMessage {
+ factory LinkInfo({
+ $core.bool? relayed,
+ }) {
+ final result = LinkInfo._();
+ if (relayed != null) result.relayed = relayed;
+ return result;
+ }
+
+ LinkInfo._();
+
+ factory LinkInfo.fromBuffer($core.List<$core.int> data,
+ [$pb.ExtensionRegistry registry = $pb.ExtensionRegistry.EMPTY]) =>
+ LinkInfo()..mergeFromBuffer(data, registry);
+ factory LinkInfo.fromJson($core.String json,
+ [$pb.ExtensionRegistry registry = $pb.ExtensionRegistry.EMPTY]) =>
+ LinkInfo()..mergeFromJson(json, registry);
+
+ static final $pb.BuilderInfo _i = $pb.BuilderInfo(
+ _omitMessageNames ? '' : 'LinkInfo',
+ package: const $pb.PackageName(_omitMessageNames ? '' : 'copysync.v1'),
+ createEmptyInstance: LinkInfo.$_createMessage)
+ ..aOB(1, _omitFieldNames ? '' : 'relayed')
+ ..hasRequiredFields = false;
+
+ @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.')
+ LinkInfo clone() => deepCopy();
+ @$core.Deprecated('See https://github.com/google/protobuf.dart/issues/998.')
+ LinkInfo copyWith(void Function(LinkInfo) updates) =>
+ super.copyWith((message) => updates(message as LinkInfo)) as LinkInfo;
+
+ @$core.override
+ $pb.BuilderInfo get info_ => _i;
+
+ @$core.pragma('dart2js:noInline')
+ @$core.Deprecated('Use LinkInfo() / LinkInfo.new instead')
+ static LinkInfo create() => LinkInfo._();
+ static $pb.GeneratedMessage $_createMessage() => LinkInfo._();
+ @$core.override
+ LinkInfo createEmptyInstance() => LinkInfo._();
+ @$core.pragma('dart2js:noInline')
+ static LinkInfo getDefault() => _defaultInstance ??=
+ $pb.GeneratedMessage.$_defaultFor<LinkInfo>(LinkInfo.$_createMessage);
+ static LinkInfo? _defaultInstance;
+
+ @$pb.TagNumber(1)
+ $core.bool get relayed => $_getBF(0);
+ @$pb.TagNumber(1)
+ set relayed($core.bool value) => $_setBool(0, value);
+ @$pb.TagNumber(1)
+ $core.bool hasRelayed() => $_has(0);
+ @$pb.TagNumber(1)
+ void clearRelayed() => $_clearField(1);
}
/// 复制发生时广播给所有在线对端。
diff --git a/ui/lib/gen/copysync/v1/wire.pbjson.dart b/ui/lib/gen/copysync/v1/wire.pbjson.dart
index 19a505f..2f8f059 100644
--- a/ui/lib/gen/copysync/v1/wire.pbjson.dart
+++ b/ui/lib/gen/copysync/v1/wire.pbjson.dart
@@ -561,6 +561,15 @@ const PeerMessage$json = {
'9': 0,
'10': 'done'
},
+ {
+ '1': 'link',
+ '3': 6,
+ '4': 1,
+ '5': 11,
+ '6': '.copysync.v1.LinkInfo',
+ '9': 0,
+ '10': 'link'
+ },
],
'8': [
{'1': 'payload'},
@@ -573,7 +582,20 @@ final $typed_data.Uint8List peerMessageDescriptor = $convert.base64Decode(
'VvZmZlchIuCgVmZXRjaBgCIAEoCzIWLmNvcHlzeW5jLnYxLlBlZXJGZXRjaEgAUgVmZXRjaBIy'
'CgZyZWplY3QYAyABKAsyGC5jb3B5c3luYy52MS5GZXRjaFJlamVjdEgAUgZyZWplY3QSNQoGaG'
'VhZGVyGAQgASgLMhsuY29weXN5bmMudjEuVHJhbnNmZXJIZWFkZXJIAFIGaGVhZGVyEi8KBGRv'
- 'bmUYBSABKAsyGS5jb3B5c3luYy52MS5UcmFuc2ZlckRvbmVIAFIEZG9uZUIJCgdwYXlsb2Fk');
+ 'bmUYBSABKAsyGS5jb3B5c3luYy52MS5UcmFuc2ZlckRvbmVIAFIEZG9uZRIrCgRsaW5rGAYgAS'
+ 'gLMhUuY29weXN5bmMudjEuTGlua0luZm9IAFIEbGlua0IJCgdwYXlsb2Fk');
+
+@$core.Deprecated('Use linkInfoDescriptor instead')
+const LinkInfo$json = {
+ '1': 'LinkInfo',
+ '2': [
+ {'1': 'relayed', '3': 1, '4': 1, '5': 8, '10': 'relayed'},
+ ],
+};
+
+/// Descriptor for `LinkInfo`. Decode as a `google.protobuf.DescriptorProto`.
+final $typed_data.Uint8List linkInfoDescriptor =
+ $convert.base64Decode('CghMaW5rSW5mbxIYCgdyZWxheWVkGAEgASgIUgdyZWxheWVk');
@$core.Deprecated('Use clipOfferDescriptor instead')
const ClipOffer$json = {
diff --git a/ui/lib/pages/history_page.dart b/ui/lib/pages/history_page.dart
index e2851ef..abdb88a 100644
--- a/ui/lib/pages/history_page.dart
+++ b/ui/lib/pages/history_page.dart
@@ -249,7 +249,14 @@ class _RecordRowState extends State<_RecordRow> {
child: const Text('拉取到本机'),
);
case ClipStatus.CLIP_STATUS_FETCHING:
- return const SizedBox(width: 72, child: LinearProgressIndicator(minHeight: 3));
+ // 知道总量时显示真实进度,否则显示不确定进度
+ return SizedBox(
+ width: 72,
+ child: LinearProgressIndicator(
+ minHeight: 3,
+ value: AppScope.of(context).progressOf(r.id),
+ ),
+ );
case ClipStatus.CLIP_STATUS_FAILED:
return Tooltip(
message: r.error.isEmpty ? '传输失败' : r.error,
diff --git a/ui/pubspec.yaml b/ui/pubspec.yaml
index a1211ff..44d0409 100644
--- a/ui/pubspec.yaml
+++ b/ui/pubspec.yaml
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
-version: 1.0.1+2
+version: 1.0.2+3
environment:
sdk: ^3.12.2
diff --git a/ui/test/widget_test.dart b/ui/test/widget_test.dart
index 4522f94..f6fe4d5 100644
--- a/ui/test/widget_test.dart
+++ b/ui/test/widget_test.dart
@@ -1,3 +1,4 @@
+import 'package:fixnum/fixnum.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -85,6 +86,39 @@ void main() {
});
});
+ group('复制记录事件', () {
+ AppState seeded(List<ClipRecord> records) =>
+ AppState()..debugSeed(status: Status(), config: Config(), self: Device(), records: records);
+ Event added(ClipRecord r) => Event(clipAdded: r);
+ Event progress(String id, int done, int total) => Event(
+ progress: TransferProgress(clipId: id, transferred: Int64(done), total: Int64(total)));
+
+ test('本机复制的记录在发送时不会变成「接收中」', () {
+ final state = seeded([ClipRecord(id: 'out', outgoing: true, status: ClipStatus.CLIP_STATUS_READY)]);
+ state.debugEvent(progress('out', 50, 100));
+ expect(state.records.single.status, ClipStatus.CLIP_STATUS_READY);
+ expect(state.progressOf('out'), isNull);
+ });
+
+ test('同一条记录推送两次只显示一行,并以最新状态为准', () {
+ final state = seeded([]);
+ state.debugEvent(added(ClipRecord(id: 'in', status: ClipStatus.CLIP_STATUS_FETCHING)));
+ state.debugEvent(progress('in', 50, 100));
+ expect(state.progressOf('in'), 0.5);
+
+ state.debugEvent(added(ClipRecord(id: 'in', status: ClipStatus.CLIP_STATUS_READY)));
+ expect(state.records, hasLength(1));
+ expect(state.records.single.status, ClipStatus.CLIP_STATUS_READY);
+ expect(state.progressOf('in'), isNull);
+ });
+
+ test('迟到的进度事件不会把已完成的记录拉回「接收中」', () {
+ final state = seeded([ClipRecord(id: 'in', status: ClipStatus.CLIP_STATUS_READY)]);
+ state.debugEvent(progress('in', 90, 100));
+ expect(state.records.single.status, ClipStatus.CLIP_STATUS_READY);
+ });
+ });
+
test('数据目录路径与 Go 侧 config.DefaultPaths 保持一致', () {
final dir = DaemonEndpoint.defaultDataDir();
// 路径不一致会导致 UI 根本找不到 daemon,这里锁住约定