diff --git a/cmd/server/main-server.go b/cmd/server/main-server.go index bb423c45..7f548873 100644 --- a/cmd/server/main-server.go +++ b/cmd/server/main-server.go @@ -29,6 +29,7 @@ import ( "github.com/wavetermdev/waveterm/pkg/wconfig" "github.com/wavetermdev/waveterm/pkg/wcore" "github.com/wavetermdev/waveterm/pkg/web" + "github.com/wavetermdev/waveterm/pkg/wlayout" "github.com/wavetermdev/waveterm/pkg/wps" "github.com/wavetermdev/waveterm/pkg/wshrpc" "github.com/wavetermdev/waveterm/pkg/wshrpc/wshremote" @@ -228,11 +229,20 @@ func main() { log.Printf("error initializing wsh and shell-integration files: %v\n", err) } }() - err = wcore.EnsureInitialData() + window, err := wcore.EnsureInitialData() if err != nil { log.Printf("error ensuring initial data: %v\n", err) return } + if window != nil { + ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second) + defer cancelFn() + err = wlayout.BootstrapNewWindowLayout(ctx, window) + if err != nil { + log.Panicf("error applying new window layout: %v\n", err) + return + } + } createMainWshClient() installShutdownSignalHandlers() startupActivityUpdate() diff --git a/pkg/service/clientservice/clientservice.go b/pkg/service/clientservice/clientservice.go index 52da22ab..757c0d00 100644 --- a/pkg/service/clientservice/clientservice.go +++ b/pkg/service/clientservice/clientservice.go @@ -62,7 +62,15 @@ func (cs *ClientService) GetWindow(windowId string) (*waveobj.Window, error) { } func (cs *ClientService) MakeWindow(ctx context.Context) (*waveobj.Window, error) { - return wcore.CreateWindow(ctx, nil) + window, err := wcore.CreateWindow(ctx, nil) + if err != nil { + return nil, err + } + err = wlayout.BootstrapNewWindowLayout(ctx, window) + if err != nil { + return window, err + } + return window, nil } func (cs *ClientService) GetAllConnStatus(ctx context.Context) ([]wshrpc.ConnStatus, error) { diff --git a/pkg/wcore/wcore.go b/pkg/wcore/wcore.go index 736f8675..260cbe45 100644 --- a/pkg/wcore/wcore.go +++ b/pkg/wcore/wcore.go @@ -136,7 +136,7 @@ func CreateWindow(ctx context.Context, winSize *waveobj.WinSize) (*waveobj.Windo return wstore.DBMustGet[*waveobj.Window](ctx, windowId) } -func EnsureInitialData() error { +func EnsureInitialData() (*waveobj.Window, error) { // does not need to run in a transaction since it is called on startup ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second) defer cancelFn() @@ -144,17 +144,17 @@ func EnsureInitialData() error { if err == wstore.ErrNotFound { client, err = CreateClient(ctx) if err != nil { - return fmt.Errorf("error creating client: %w", err) + return nil, fmt.Errorf("error creating client: %w", err) } } if len(client.WindowIds) > 0 { - return nil + return nil, nil } - _, err = CreateWindow(ctx, &waveobj.WinSize{Height: 0, Width: 0}) + window, err := CreateWindow(ctx, &waveobj.WinSize{Height: 0, Width: 0}) if err != nil { - return fmt.Errorf("error creating window: %w", err) + return nil, fmt.Errorf("error creating window: %w", err) } - return nil + return window, nil } func CreateClient(ctx context.Context) (*waveobj.Client, error) { diff --git a/pkg/wlayout/wlayout.go b/pkg/wlayout/wlayout.go index 2f7766b4..2a47837d 100644 --- a/pkg/wlayout/wlayout.go +++ b/pkg/wlayout/wlayout.go @@ -145,6 +145,17 @@ func ApplyPortableLayout(ctx context.Context, tabId string, layout PortableLayou return nil } +func BootstrapNewWindowLayout(ctx context.Context, window *waveobj.Window) error { + tabId := window.ActiveTabId + newTabLayout := GetNewTabLayout() + + err := ApplyPortableLayout(ctx, tabId, newTabLayout) + if err != nil { + return fmt.Errorf("error applying new window layout: %w", err) + } + return nil +} + func BootstrapStarterLayout(ctx context.Context) error { ctx, cancelFn := context.WithTimeout(ctx, 2*time.Second) defer cancelFn() @@ -171,7 +182,7 @@ func BootstrapStarterLayout(ctx context.Context) error { err = ApplyPortableLayout(ctx, tabId, starterLayout) if err != nil { - return fmt.Errorf("error applying portable layout: %w", err) + return fmt.Errorf("error applying starter layout: %w", err) } return nil