返回 DeepSeek-Reasonix
remote_context.go
根目录 / desktop / remote_context.go
1 package main
2
3 import "encoding/json"
4
5 // remoteContextSnapshot reads the selected remote session, then rejects a
6 // response that raced with a reconnect or a switch to another session.
7 func (a *App) remoteContextSnapshot(tabID string) (int, int, bool) {
8 a.remoteTabMu.Lock()
9 tab := a.remoteTabs[tabID]
10 if tab == nil || tab.client == nil || tab.state != "ready" || tab.routing.rehydratingPath != "" {
11 a.remoteTabMu.Unlock()
12 return 0, 0, false
13 }
14 client, base := tab.client, tab.base
15 path, generation, revision := tab.routing.currentPath, tab.gen, tab.routing.pathRevision
16 a.remoteTabMu.Unlock()
17
18 ctx, cancel := commandContext(a)
19 defer cancel()
20 data, err := serveGet(ctx, client, serveURL(base, "/context"), path)
21 if err != nil {
22 return 0, 0, false
23 }
24 var value struct {
25 Used int `json:"used"`
26 Window int `json:"window"`
27 }
28 if json.Unmarshal(data, &value) != nil {
29 return 0, 0, false
30 }
31 a.remoteTabMu.Lock()
32 current := a.remoteTabs[tabID]
33 valid := current == tab && current.client == client && current.gen == generation &&
34 current.routing.pathRevision == revision && current.routing.currentPath == path &&
35 current.routing.rehydratingPath == "" && current.state == "ready"
36 a.remoteTabMu.Unlock()
37 return value.Used, value.Window, valid
38 }
39
39 lines GO