From e567434b035fdda01ec11db43a1f108b91785c92 Mon Sep 17 00:00:00 2001 From: Mike Sawka Date: Thu, 26 Sep 2024 13:29:07 -0700 Subject: [PATCH] fix broken windows (with no tabs) (#867) --- pkg/wcore/wcore.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pkg/wcore/wcore.go b/pkg/wcore/wcore.go index 659ec0cda..d53418b20 100644 --- a/pkg/wcore/wcore.go +++ b/pkg/wcore/wcore.go @@ -137,6 +137,26 @@ func CreateWindow(ctx context.Context, winSize *waveobj.WinSize) (*waveobj.Windo return wstore.DBMustGet[*waveobj.Window](ctx, windowId) } +func checkAndFixWindow(ctx context.Context, windowId string) { + window, err := wstore.DBMustGet[*waveobj.Window](ctx, windowId) + if err != nil { + log.Printf("error getting window %q (in checkAndFixWindow): %v\n", windowId, err) + return + } + workspace, err := wstore.DBMustGet[*waveobj.Workspace](ctx, window.WorkspaceId) + if err != nil { + log.Printf("error getting workspace %q (in checkAndFixWindow): %v\n", window.WorkspaceId, err) + return + } + if len(workspace.TabIds) == 0 { + log.Printf("fixing workspace with no tabs %q (in checkAndFixWindow)\n", workspace.OID) + _, err = CreateTab(ctx, windowId, "T1", true) + if err != nil { + log.Printf("error creating tab (in checkAndFixWindow): %v\n", err) + } + } +} + // returns (new-window, first-time, error) func EnsureInitialData() (*waveobj.Window, bool, error) { // does not need to run in a transaction since it is called on startup @@ -152,6 +172,9 @@ func EnsureInitialData() (*waveobj.Window, bool, error) { firstRun = true } log.Printf("clientid: %s\n", client.OID) + if len(client.WindowIds) == 1 { + checkAndFixWindow(ctx, client.WindowIds[0]) + } if len(client.WindowIds) > 0 { return nil, false, nil }