Add a new terminal to the default tab in a new window (#368)

This commit is contained in:
Evan Simkowitz 2024-09-11 17:39:08 -07:00 committed by GitHub
parent 27f1f3ecc2
commit 4bfb96b001
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 38 additions and 9 deletions

View File

@ -29,6 +29,7 @@ import (
"github.com/wavetermdev/waveterm/pkg/wconfig" "github.com/wavetermdev/waveterm/pkg/wconfig"
"github.com/wavetermdev/waveterm/pkg/wcore" "github.com/wavetermdev/waveterm/pkg/wcore"
"github.com/wavetermdev/waveterm/pkg/web" "github.com/wavetermdev/waveterm/pkg/web"
"github.com/wavetermdev/waveterm/pkg/wlayout"
"github.com/wavetermdev/waveterm/pkg/wps" "github.com/wavetermdev/waveterm/pkg/wps"
"github.com/wavetermdev/waveterm/pkg/wshrpc" "github.com/wavetermdev/waveterm/pkg/wshrpc"
"github.com/wavetermdev/waveterm/pkg/wshrpc/wshremote" "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) log.Printf("error initializing wsh and shell-integration files: %v\n", err)
} }
}() }()
err = wcore.EnsureInitialData() window, err := wcore.EnsureInitialData()
if err != nil { if err != nil {
log.Printf("error ensuring initial data: %v\n", err) log.Printf("error ensuring initial data: %v\n", err)
return 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() createMainWshClient()
installShutdownSignalHandlers() installShutdownSignalHandlers()
startupActivityUpdate() startupActivityUpdate()

View File

@ -62,7 +62,15 @@ func (cs *ClientService) GetWindow(windowId string) (*waveobj.Window, error) {
} }
func (cs *ClientService) MakeWindow(ctx context.Context) (*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) { func (cs *ClientService) GetAllConnStatus(ctx context.Context) ([]wshrpc.ConnStatus, error) {

View File

@ -136,7 +136,7 @@ func CreateWindow(ctx context.Context, winSize *waveobj.WinSize) (*waveobj.Windo
return wstore.DBMustGet[*waveobj.Window](ctx, windowId) 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 // does not need to run in a transaction since it is called on startup
ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second) ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second)
defer cancelFn() defer cancelFn()
@ -144,17 +144,17 @@ func EnsureInitialData() error {
if err == wstore.ErrNotFound { if err == wstore.ErrNotFound {
client, err = CreateClient(ctx) client, err = CreateClient(ctx)
if err != nil { 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 { 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 { 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) { func CreateClient(ctx context.Context) (*waveobj.Client, error) {

View File

@ -145,6 +145,17 @@ func ApplyPortableLayout(ctx context.Context, tabId string, layout PortableLayou
return nil 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 { func BootstrapStarterLayout(ctx context.Context) error {
ctx, cancelFn := context.WithTimeout(ctx, 2*time.Second) ctx, cancelFn := context.WithTimeout(ctx, 2*time.Second)
defer cancelFn() defer cancelFn()
@ -171,7 +182,7 @@ func BootstrapStarterLayout(ctx context.Context) error {
err = ApplyPortableLayout(ctx, tabId, starterLayout) err = ApplyPortableLayout(ctx, tabId, starterLayout)
if err != nil { if err != nil {
return fmt.Errorf("error applying portable layout: %w", err) return fmt.Errorf("error applying starter layout: %w", err)
} }
return nil return nil