MCPcopy
hub / github.com/wavetermdev/waveterm / CreateWindow

Function CreateWindow

pkg/wcore/window.go:81–128  ·  view source on GitHub ↗
(ctx context.Context, winSize *waveobj.WinSize, workspaceId string)

Source from the content-addressed store, hash-verified

79}
80
81func CreateWindow(ctx context.Context, winSize *waveobj.WinSize, workspaceId string) (*waveobj.Window, error) {
82 log.Printf("CreateWindow %v %v\n", winSize, workspaceId)
83 var ws *waveobj.Workspace
84 if workspaceId == "" {
85 ws1, err := CreateWorkspace(ctx, "", "", "", false, false)
86 if err != nil {
87 return nil, fmt.Errorf("error creating workspace: %w", err)
88 }
89 ws = ws1
90 } else {
91 ws1, err := GetWorkspace(ctx, workspaceId)
92 if err != nil {
93 return nil, fmt.Errorf("error getting workspace: %w", err)
94 }
95 ws = ws1
96 }
97 windowId := uuid.NewString()
98 if winSize == nil {
99 winSize = &waveobj.WinSize{
100 Width: 0,
101 Height: 0,
102 }
103 }
104 window := &waveobj.Window{
105 OID: windowId,
106 WorkspaceId: ws.OID,
107 IsNew: true,
108 Pos: waveobj.Point{
109 X: 0,
110 Y: 0,
111 },
112 WinSize: *winSize,
113 }
114 err := wstore.DBInsert(ctx, window)
115 if err != nil {
116 return nil, fmt.Errorf("error inserting window: %w", err)
117 }
118 client, err := GetClientData(ctx)
119 if err != nil {
120 return nil, fmt.Errorf("error getting client: %w", err)
121 }
122 client.WindowIds = append(client.WindowIds, windowId)
123 err = wstore.DBUpdate(ctx, client)
124 if err != nil {
125 return nil, fmt.Errorf("error updating client: %w", err)
126 }
127 return GetWindow(ctx, windowId)
128}
129
130// CloseWindow closes a window and deletes its workspace if it is empty and not named.
131// If fromElectron is true, it does not send an event to Electron.

Callers 2

CreateWindowMethod · 0.92
EnsureInitialDataFunction · 0.85

Calls 6

DBInsertFunction · 0.92
DBUpdateFunction · 0.92
CreateWorkspaceFunction · 0.85
GetWorkspaceFunction · 0.85
GetClientDataFunction · 0.85
GetWindowFunction · 0.85

Tested by

no test coverage detected