mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
Add a new terminal to the default tab in a new window (#368)
This commit is contained in:
parent
27f1f3ecc2
commit
4bfb96b001
@ -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()
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user