Skip to content

Commit 3f4484a

Browse files
Copilotsawka
andauthored
Remove dead “move block to new window” path and dependent unused APIs (#3002)
`WindowService.MoveBlockToNewWindow` appears to be unreferenced, and its supporting path had become isolated. This change removes that dead RPC surface and the backend/eventbus helpers that existed only for that flow. - **Window service cleanup (backend RPC)** - Removed `MoveBlockToNewWindow_Meta` and `MoveBlockToNewWindow` from `pkg/service/windowservice/windowservice.go`. - Dropped now-unused imports tied to that method (`log`, `eventbus`). - **Store cleanup** - Removed `MoveBlockToTab` from `pkg/wstore/wstore.go`. - Removed now-unused `utilfn` import from the same file. - **Eventbus cleanup** - Removed unused event constant `WSEvent_ElectronNewWindow`. - Removed `getWindowWatchesForWindowId` and `BusyWaitForWindowId`, which were only used by the deleted move-to-new-window path. - Removed now-unused `time` import. - **Generated frontend service surface** - Regenerated service bindings and removed `WindowServiceType.MoveBlockToNewWindow(...)` from `frontend/app/store/services.ts`. Example of removed RPC surface: ```ts // removed from frontend/app/store/services.ts MoveBlockToNewWindow(currentTabId: string, blockId: string): Promise<void> { return WOS.callBackendService("window", "MoveBlockToNewWindow", Array.from(arguments)) } ``` <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/wavetermdev/waveterm/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
1 parent 76f78f0 commit 3f4484a

4 files changed

Lines changed: 0 additions & 123 deletions

File tree

frontend/app/store/services.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,6 @@ class WindowServiceType {
113113
return WOS.callBackendService("window", "GetWindow", Array.from(arguments))
114114
}
115115

116-
// move block to new window
117-
// @returns object updates
118-
MoveBlockToNewWindow(currentTabId: string, blockId: string): Promise<void> {
119-
return WOS.callBackendService("window", "MoveBlockToNewWindow", Array.from(arguments))
120-
}
121-
122116
// set window position and size
123117
// @returns object updates
124118
SetWindowPosAndSize(windowId: string, pos: Point, size: WinSize): Promise<void> {

pkg/eventbus/eventbus.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import (
99
"log"
1010
"os"
1111
"sync"
12-
"time"
1312
)
1413

1514
const (
16-
WSEvent_ElectronNewWindow = "electron:newwindow"
1715
WSEvent_ElectronCloseWindow = "electron:closewindow"
1816
WSEvent_ElectronUpdateActiveTab = "electron:updateactivetab"
1917
WSEvent_Rpc = "rpc"
@@ -48,33 +46,6 @@ func UnregisterWSChannel(connId string) {
4846
delete(wsMap, connId)
4947
}
5048

51-
func getWindowWatchesForWindowId(windowId string) []*WindowWatchData {
52-
globalLock.Lock()
53-
defer globalLock.Unlock()
54-
var watches []*WindowWatchData
55-
for _, wdata := range wsMap {
56-
if wdata.RouteId == windowId {
57-
watches = append(watches, wdata)
58-
}
59-
}
60-
return watches
61-
}
62-
63-
// TODO fix busy wait -- but we need to wait until a new window connects back with a websocket
64-
// returns true if the window is connected
65-
func BusyWaitForWindowId(windowId string, timeout time.Duration) bool {
66-
endTime := time.Now().Add(timeout)
67-
for {
68-
if len(getWindowWatchesForWindowId(windowId)) > 0 {
69-
return true
70-
}
71-
if time.Now().After(endTime) {
72-
return false
73-
}
74-
time.Sleep(20 * time.Millisecond)
75-
}
76-
}
77-
7849
func SendEventToElectron(event WSEventType) {
7950
barr, err := json.Marshal(event)
8051
if err != nil {

pkg/service/windowservice/windowservice.go

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ package windowservice
66
import (
77
"context"
88
"fmt"
9-
"log"
109
"time"
1110

12-
"github.com/wavetermdev/waveterm/pkg/eventbus"
1311
"github.com/wavetermdev/waveterm/pkg/panichandler"
1412
"github.com/wavetermdev/waveterm/pkg/tsgen/tsgenmeta"
1513
"github.com/wavetermdev/waveterm/pkg/waveobj"
@@ -82,63 +80,6 @@ func (ws *WindowService) SetWindowPosAndSize(ctx context.Context, windowId strin
8280
return waveobj.ContextGetUpdatesRtn(ctx), nil
8381
}
8482

85-
func (svc *WindowService) MoveBlockToNewWindow_Meta() tsgenmeta.MethodMeta {
86-
return tsgenmeta.MethodMeta{
87-
Desc: "move block to new window",
88-
ArgNames: []string{"ctx", "currentTabId", "blockId"},
89-
}
90-
}
91-
92-
func (svc *WindowService) MoveBlockToNewWindow(ctx context.Context, currentTabId string, blockId string) (waveobj.UpdatesRtnType, error) {
93-
log.Printf("MoveBlockToNewWindow(%s, %s)", currentTabId, blockId)
94-
ctx = waveobj.ContextWithUpdates(ctx)
95-
tab, err := wstore.DBMustGet[*waveobj.Tab](ctx, currentTabId)
96-
if err != nil {
97-
return nil, fmt.Errorf("error getting tab: %w", err)
98-
}
99-
log.Printf("tab.BlockIds[%s]: %v", tab.OID, tab.BlockIds)
100-
var foundBlock bool
101-
for _, tabBlockId := range tab.BlockIds {
102-
if tabBlockId == blockId {
103-
foundBlock = true
104-
break
105-
}
106-
}
107-
if !foundBlock {
108-
return nil, fmt.Errorf("block not found in current tab")
109-
}
110-
newWindow, err := wcore.CreateWindow(ctx, nil, "")
111-
if err != nil {
112-
return nil, fmt.Errorf("error creating window: %w", err)
113-
}
114-
ws, err := wcore.GetWorkspace(ctx, newWindow.WorkspaceId)
115-
if err != nil {
116-
return nil, fmt.Errorf("error getting workspace: %w", err)
117-
}
118-
err = wstore.MoveBlockToTab(ctx, currentTabId, ws.ActiveTabId, blockId)
119-
if err != nil {
120-
return nil, fmt.Errorf("error moving block to tab: %w", err)
121-
}
122-
eventbus.SendEventToElectron(eventbus.WSEventType{
123-
EventType: eventbus.WSEvent_ElectronNewWindow,
124-
Data: newWindow.OID,
125-
})
126-
windowCreated := eventbus.BusyWaitForWindowId(newWindow.OID, 2*time.Second)
127-
if !windowCreated {
128-
return nil, fmt.Errorf("new window not created")
129-
}
130-
wcore.QueueLayoutActionForTab(ctx, currentTabId, waveobj.LayoutActionData{
131-
ActionType: wcore.LayoutActionDataType_Remove,
132-
BlockId: blockId,
133-
})
134-
wcore.QueueLayoutActionForTab(ctx, ws.ActiveTabId, waveobj.LayoutActionData{
135-
ActionType: wcore.LayoutActionDataType_Insert,
136-
BlockId: blockId,
137-
Focused: true,
138-
})
139-
return waveobj.ContextGetUpdatesRtn(ctx), nil
140-
}
141-
14283
func (svc *WindowService) SwitchWorkspace_Meta() tsgenmeta.MethodMeta {
14384
return tsgenmeta.MethodMeta{
14485
ArgNames: []string{"ctx", "windowId", "workspaceId"},

pkg/wstore/wstore.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"sync"
1010

11-
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
1211
"github.com/wavetermdev/waveterm/pkg/wavebase"
1312
"github.com/wavetermdev/waveterm/pkg/waveobj"
1413
)
@@ -74,31 +73,3 @@ func UpdateObjectMeta(ctx context.Context, oref waveobj.ORef, meta waveobj.MetaM
7473
return nil
7574
})
7675
}
77-
78-
func MoveBlockToTab(ctx context.Context, currentTabId string, newTabId string, blockId string) error {
79-
return WithTx(ctx, func(tx *TxWrap) error {
80-
block, _ := DBGet[*waveobj.Block](tx.Context(), blockId)
81-
if block == nil {
82-
return fmt.Errorf("block not found: %q", blockId)
83-
}
84-
currentTab, _ := DBGet[*waveobj.Tab](tx.Context(), currentTabId)
85-
if currentTab == nil {
86-
return fmt.Errorf("current tab not found: %q", currentTabId)
87-
}
88-
newTab, _ := DBGet[*waveobj.Tab](tx.Context(), newTabId)
89-
if newTab == nil {
90-
return fmt.Errorf("new tab not found: %q", newTabId)
91-
}
92-
blockIdx := utilfn.FindStringInSlice(currentTab.BlockIds, blockId)
93-
if blockIdx == -1 {
94-
return fmt.Errorf("block not found in current tab: %q", blockId)
95-
}
96-
currentTab.BlockIds = utilfn.RemoveElemFromSlice(currentTab.BlockIds, blockId)
97-
newTab.BlockIds = append(newTab.BlockIds, blockId)
98-
block.ParentORef = waveobj.MakeORef(waveobj.OType_Tab, newTabId).String()
99-
DBUpdate(tx.Context(), block)
100-
DBUpdate(tx.Context(), currentTab)
101-
DBUpdate(tx.Context(), newTab)
102-
return nil
103-
})
104-
}

0 commit comments

Comments
 (0)