fix broken windows (with no tabs) (#867)

This commit is contained in:
Mike Sawka 2024-09-26 13:29:07 -07:00 committed by GitHub
parent 68dfc4ab90
commit e567434b03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
}