mirror of
https://github.com/wavetermdev/waveterm
synced 2026-04-21 14:37:16 +00:00
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>
This commit is contained in:
parent
76f78f0f97
commit
3f4484a9e2
4 changed files with 0 additions and 123 deletions
|
|
@ -113,12 +113,6 @@ class WindowServiceType {
|
|||
return WOS.callBackendService("window", "GetWindow", Array.from(arguments))
|
||||
}
|
||||
|
||||
// move block to new window
|
||||
// @returns object updates
|
||||
MoveBlockToNewWindow(currentTabId: string, blockId: string): Promise<void> {
|
||||
return WOS.callBackendService("window", "MoveBlockToNewWindow", Array.from(arguments))
|
||||
}
|
||||
|
||||
// set window position and size
|
||||
// @returns object updates
|
||||
SetWindowPosAndSize(windowId: string, pos: Point, size: WinSize): Promise<void> {
|
||||
|
|
|
|||
|
|
@ -9,11 +9,9 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
WSEvent_ElectronNewWindow = "electron:newwindow"
|
||||
WSEvent_ElectronCloseWindow = "electron:closewindow"
|
||||
WSEvent_ElectronUpdateActiveTab = "electron:updateactivetab"
|
||||
WSEvent_Rpc = "rpc"
|
||||
|
|
@ -48,33 +46,6 @@ func UnregisterWSChannel(connId string) {
|
|||
delete(wsMap, connId)
|
||||
}
|
||||
|
||||
func getWindowWatchesForWindowId(windowId string) []*WindowWatchData {
|
||||
globalLock.Lock()
|
||||
defer globalLock.Unlock()
|
||||
var watches []*WindowWatchData
|
||||
for _, wdata := range wsMap {
|
||||
if wdata.RouteId == windowId {
|
||||
watches = append(watches, wdata)
|
||||
}
|
||||
}
|
||||
return watches
|
||||
}
|
||||
|
||||
// TODO fix busy wait -- but we need to wait until a new window connects back with a websocket
|
||||
// returns true if the window is connected
|
||||
func BusyWaitForWindowId(windowId string, timeout time.Duration) bool {
|
||||
endTime := time.Now().Add(timeout)
|
||||
for {
|
||||
if len(getWindowWatchesForWindowId(windowId)) > 0 {
|
||||
return true
|
||||
}
|
||||
if time.Now().After(endTime) {
|
||||
return false
|
||||
}
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
func SendEventToElectron(event WSEventType) {
|
||||
barr, err := json.Marshal(event)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -6,10 +6,8 @@ package windowservice
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/wavetermdev/waveterm/pkg/eventbus"
|
||||
"github.com/wavetermdev/waveterm/pkg/panichandler"
|
||||
"github.com/wavetermdev/waveterm/pkg/tsgen/tsgenmeta"
|
||||
"github.com/wavetermdev/waveterm/pkg/waveobj"
|
||||
|
|
@ -82,63 +80,6 @@ func (ws *WindowService) SetWindowPosAndSize(ctx context.Context, windowId strin
|
|||
return waveobj.ContextGetUpdatesRtn(ctx), nil
|
||||
}
|
||||
|
||||
func (svc *WindowService) MoveBlockToNewWindow_Meta() tsgenmeta.MethodMeta {
|
||||
return tsgenmeta.MethodMeta{
|
||||
Desc: "move block to new window",
|
||||
ArgNames: []string{"ctx", "currentTabId", "blockId"},
|
||||
}
|
||||
}
|
||||
|
||||
func (svc *WindowService) MoveBlockToNewWindow(ctx context.Context, currentTabId string, blockId string) (waveobj.UpdatesRtnType, error) {
|
||||
log.Printf("MoveBlockToNewWindow(%s, %s)", currentTabId, blockId)
|
||||
ctx = waveobj.ContextWithUpdates(ctx)
|
||||
tab, err := wstore.DBMustGet[*waveobj.Tab](ctx, currentTabId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting tab: %w", err)
|
||||
}
|
||||
log.Printf("tab.BlockIds[%s]: %v", tab.OID, tab.BlockIds)
|
||||
var foundBlock bool
|
||||
for _, tabBlockId := range tab.BlockIds {
|
||||
if tabBlockId == blockId {
|
||||
foundBlock = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !foundBlock {
|
||||
return nil, fmt.Errorf("block not found in current tab")
|
||||
}
|
||||
newWindow, err := wcore.CreateWindow(ctx, nil, "")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating window: %w", err)
|
||||
}
|
||||
ws, err := wcore.GetWorkspace(ctx, newWindow.WorkspaceId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting workspace: %w", err)
|
||||
}
|
||||
err = wstore.MoveBlockToTab(ctx, currentTabId, ws.ActiveTabId, blockId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error moving block to tab: %w", err)
|
||||
}
|
||||
eventbus.SendEventToElectron(eventbus.WSEventType{
|
||||
EventType: eventbus.WSEvent_ElectronNewWindow,
|
||||
Data: newWindow.OID,
|
||||
})
|
||||
windowCreated := eventbus.BusyWaitForWindowId(newWindow.OID, 2*time.Second)
|
||||
if !windowCreated {
|
||||
return nil, fmt.Errorf("new window not created")
|
||||
}
|
||||
wcore.QueueLayoutActionForTab(ctx, currentTabId, waveobj.LayoutActionData{
|
||||
ActionType: wcore.LayoutActionDataType_Remove,
|
||||
BlockId: blockId,
|
||||
})
|
||||
wcore.QueueLayoutActionForTab(ctx, ws.ActiveTabId, waveobj.LayoutActionData{
|
||||
ActionType: wcore.LayoutActionDataType_Insert,
|
||||
BlockId: blockId,
|
||||
Focused: true,
|
||||
})
|
||||
return waveobj.ContextGetUpdatesRtn(ctx), nil
|
||||
}
|
||||
|
||||
func (svc *WindowService) SwitchWorkspace_Meta() tsgenmeta.MethodMeta {
|
||||
return tsgenmeta.MethodMeta{
|
||||
ArgNames: []string{"ctx", "windowId", "workspaceId"},
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
|
||||
"github.com/wavetermdev/waveterm/pkg/wavebase"
|
||||
"github.com/wavetermdev/waveterm/pkg/waveobj"
|
||||
)
|
||||
|
|
@ -74,31 +73,3 @@ func UpdateObjectMeta(ctx context.Context, oref waveobj.ORef, meta waveobj.MetaM
|
|||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func MoveBlockToTab(ctx context.Context, currentTabId string, newTabId string, blockId string) error {
|
||||
return WithTx(ctx, func(tx *TxWrap) error {
|
||||
block, _ := DBGet[*waveobj.Block](tx.Context(), blockId)
|
||||
if block == nil {
|
||||
return fmt.Errorf("block not found: %q", blockId)
|
||||
}
|
||||
currentTab, _ := DBGet[*waveobj.Tab](tx.Context(), currentTabId)
|
||||
if currentTab == nil {
|
||||
return fmt.Errorf("current tab not found: %q", currentTabId)
|
||||
}
|
||||
newTab, _ := DBGet[*waveobj.Tab](tx.Context(), newTabId)
|
||||
if newTab == nil {
|
||||
return fmt.Errorf("new tab not found: %q", newTabId)
|
||||
}
|
||||
blockIdx := utilfn.FindStringInSlice(currentTab.BlockIds, blockId)
|
||||
if blockIdx == -1 {
|
||||
return fmt.Errorf("block not found in current tab: %q", blockId)
|
||||
}
|
||||
currentTab.BlockIds = utilfn.RemoveElemFromSlice(currentTab.BlockIds, blockId)
|
||||
newTab.BlockIds = append(newTab.BlockIds, blockId)
|
||||
block.ParentORef = waveobj.MakeORef(waveobj.OType_Tab, newTabId).String()
|
||||
DBUpdate(tx.Context(), block)
|
||||
DBUpdate(tx.Context(), currentTab)
|
||||
DBUpdate(tx.Context(), newTab)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue