Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions frontend/app/store/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
29 changes: 0 additions & 29 deletions pkg/eventbus/eventbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
59 changes: 0 additions & 59 deletions pkg/service/windowservice/windowservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"},
Expand Down
29 changes: 0 additions & 29 deletions pkg/wstore/wstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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