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

Function CloseWindow

pkg/wcore/window.go:132–169  ·  view source on GitHub ↗

CloseWindow closes a window and deletes its workspace if it is empty and not named. If fromElectron is true, it does not send an event to Electron.

(ctx context.Context, windowId string, fromElectron bool)

Source from the content-addressed store, hash-verified

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.
132func CloseWindow(ctx context.Context, windowId string, fromElectron bool) error {
133 log.Printf("CloseWindow %s\n", windowId)
134 window, err := GetWindow(ctx, windowId)
135 if err == nil {
136 log.Printf("got window %s\n", windowId)
137 deleted, _, err := DeleteWorkspace(ctx, window.WorkspaceId, false)
138 if err != nil {
139 log.Printf("error deleting workspace: %v\n", err)
140 }
141 if deleted {
142 log.Printf("deleted workspace %s\n", window.WorkspaceId)
143 }
144 err = wstore.DBDelete(ctx, waveobj.OType_Window, windowId)
145 if err != nil {
146 return fmt.Errorf("error deleting window: %w", err)
147 }
148 log.Printf("deleted window %s\n", windowId)
149 } else {
150 log.Printf("error getting window %s: %v\n", windowId, err)
151 }
152 client, err := wstore.DBGetSingleton[*waveobj.Client](ctx)
153 if err != nil {
154 return fmt.Errorf("error getting client: %w", err)
155 }
156 client.WindowIds = utilfn.RemoveElemFromSlice(client.WindowIds, windowId)
157 err = wstore.DBUpdate(ctx, client)
158 if err != nil {
159 return fmt.Errorf("error updating client: %w", err)
160 }
161 log.Printf("updated client\n")
162 if !fromElectron {
163 eventbus.SendEventToElectron(eventbus.WSEventType{
164 EventType: eventbus.WSEvent_ElectronCloseWindow,
165 Data: windowId,
166 })
167 }
168 return nil
169}
170
171func CheckAndFixWindow(ctx context.Context, windowId string) *waveobj.Window {
172 log.Printf("CheckAndFixWindow %s\n", windowId)

Callers 4

CloseWindowMethod · 0.92
DeleteWorkspaceFunction · 0.85
DeleteTabFunction · 0.85
CheckAndFixWindowFunction · 0.85

Calls 6

DBDeleteFunction · 0.92
RemoveElemFromSliceFunction · 0.92
DBUpdateFunction · 0.92
SendEventToElectronFunction · 0.92
GetWindowFunction · 0.85
DeleteWorkspaceFunction · 0.85

Tested by

no test coverage detected