Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pkg/service/clientservice/clientservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/wavetermdev/waveterm/pkg/wcloud"
"github.com/wavetermdev/waveterm/pkg/wconfig"
"github.com/wavetermdev/waveterm/pkg/wcore"
"github.com/wavetermdev/waveterm/pkg/wlayout"
"github.com/wavetermdev/waveterm/pkg/wshrpc"
"github.com/wavetermdev/waveterm/pkg/wsl"
"github.com/wavetermdev/waveterm/pkg/wstore"
Expand Down Expand Up @@ -64,7 +63,7 @@ func (cs *ClientService) AgreeTos(ctx context.Context) (waveobj.UpdatesRtnType,
if err != nil {
return nil, fmt.Errorf("error updating client data: %w", err)
}
wlayout.BootstrapStarterLayout(ctx)
wcore.BootstrapStarterLayout(ctx)
return waveobj.ContextGetUpdatesRtn(ctx), nil
}

Expand Down
18 changes: 4 additions & 14 deletions pkg/service/windowservice/windowservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/wavetermdev/waveterm/pkg/tsgen/tsgenmeta"
"github.com/wavetermdev/waveterm/pkg/waveobj"
"github.com/wavetermdev/waveterm/pkg/wcore"
"github.com/wavetermdev/waveterm/pkg/wlayout"
"github.com/wavetermdev/waveterm/pkg/wps"
"github.com/wavetermdev/waveterm/pkg/wstore"
)
Expand Down Expand Up @@ -50,15 +49,6 @@ func (svc *WindowService) CreateWindow(ctx context.Context, winSize *waveobj.Win
if err != nil {
return nil, fmt.Errorf("error creating window: %w", err)
}

ws, err := wcore.GetWorkspace(ctx, window.WorkspaceId)
if err != nil {
return window, fmt.Errorf("error getting workspace: %w", err)
}
err = wlayout.BootstrapNewWorkspaceLayout(ctx, ws)
if err != nil {
return window, fmt.Errorf("error bootstrapping new workspace layout: %w", err)
}
return window, nil
}

Expand Down Expand Up @@ -137,12 +127,12 @@ func (svc *WindowService) MoveBlockToNewWindow(ctx context.Context, currentTabId
if !windowCreated {
return nil, fmt.Errorf("new window not created")
}
wlayout.QueueLayoutActionForTab(ctx, currentTabId, waveobj.LayoutActionData{
ActionType: wlayout.LayoutActionDataType_Remove,
wcore.QueueLayoutActionForTab(ctx, currentTabId, waveobj.LayoutActionData{
ActionType: wcore.LayoutActionDataType_Remove,
BlockId: blockId,
})
wlayout.QueueLayoutActionForTab(ctx, ws.ActiveTabId, waveobj.LayoutActionData{
ActionType: wlayout.LayoutActionDataType_Insert,
wcore.QueueLayoutActionForTab(ctx, ws.ActiveTabId, waveobj.LayoutActionData{
ActionType: wcore.LayoutActionDataType_Insert,
BlockId: blockId,
Focused: true,
})
Expand Down
11 changes: 3 additions & 8 deletions pkg/service/workspaceservice/workspaceservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/wavetermdev/waveterm/pkg/tsgen/tsgenmeta"
"github.com/wavetermdev/waveterm/pkg/waveobj"
"github.com/wavetermdev/waveterm/pkg/wcore"
"github.com/wavetermdev/waveterm/pkg/wlayout"
"github.com/wavetermdev/waveterm/pkg/wps"
"github.com/wavetermdev/waveterm/pkg/wstore"
)
Expand All @@ -27,12 +26,12 @@ func (svc *WorkspaceService) CreateWorkspace_Meta() tsgenmeta.MethodMeta {
}

func (svc *WorkspaceService) CreateWorkspace(ctx context.Context) (string, error) {
newWS, err := wcore.CreateWorkspace(ctx, "", "", "")
newWS, err := wcore.CreateWorkspace(ctx, "", "", "", false)
if err != nil {
return "", fmt.Errorf("error creating workspace: %w", err)
}

err = wlayout.BootstrapNewWorkspaceLayout(ctx, newWS)
err = wcore.BootstrapNewWorkspaceLayout(ctx, newWS)
if err != nil {
return newWS.OID, fmt.Errorf("error bootstrapping new workspace layout: %w", err)
}
Expand Down Expand Up @@ -97,14 +96,10 @@ func (svc *WorkspaceService) CreateTab(workspaceId string, tabName string, activ
ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout)
defer cancelFn()
ctx = waveobj.ContextWithUpdates(ctx)
tabId, err := wcore.CreateTab(ctx, workspaceId, tabName, activateTab, pinned)
tabId, err := wcore.CreateTab(ctx, workspaceId, tabName, activateTab, pinned, false)
if err != nil {
return "", nil, fmt.Errorf("error creating tab: %w", err)
}
err = wlayout.ApplyPortableLayout(ctx, tabId, wlayout.GetNewTabLayout())
if err != nil {
return "", nil, fmt.Errorf("error applying new tab layout: %w", err)
}
updates := waveobj.ContextGetUpdatesRtn(ctx)
go func() {
defer panichandler.PanicHandler("WorkspaceService:CreateTab:SendUpdateEvents")
Expand Down
5 changes: 2 additions & 3 deletions pkg/wlayout/wlayout.go → pkg/wcore/layout.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

package wlayout
package wcore

import (
"context"
Expand All @@ -10,7 +10,6 @@ import (
"time"

"github.com/wavetermdev/waveterm/pkg/waveobj"
"github.com/wavetermdev/waveterm/pkg/wcore"
"github.com/wavetermdev/waveterm/pkg/wstore"
)

Expand Down Expand Up @@ -131,7 +130,7 @@ func ApplyPortableLayout(ctx context.Context, tabId string, layout PortableLayou
for i := 0; i < len(layout); i++ {
layoutAction := layout[i]

blockData, err := wcore.CreateBlock(ctx, tabId, layoutAction.BlockDef, &waveobj.RuntimeOpts{})
blockData, err := CreateBlock(ctx, tabId, layoutAction.BlockDef, &waveobj.RuntimeOpts{})
if err != nil {
return fmt.Errorf("unable to create block to apply portable layout to tab %s: %w", tabId, err)
}
Expand Down
6 changes: 1 addition & 5 deletions pkg/wcore/wcore.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,10 @@ func EnsureInitialData() error {
return nil
}
log.Println("client has no windows, creating starter workspace")
starterWs, err := CreateWorkspace(ctx, "Starter workspace", "circle", "green")
starterWs, err := CreateWorkspace(ctx, "Starter workspace", "circle", "green", true)
if err != nil {
return fmt.Errorf("error creating starter workspace: %w", err)
}
_, err = CreateTab(ctx, starterWs.OID, "", true, true)
if err != nil {
return fmt.Errorf("error creating tab: %w", err)
}
_, err = CreateWindow(ctx, nil, starterWs.OID)
if err != nil {
return fmt.Errorf("error creating window: %w", err)
Expand Down
13 changes: 11 additions & 2 deletions pkg/wcore/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,20 @@ func CreateWindow(ctx context.Context, winSize *waveobj.WinSize, workspaceId str
log.Printf("CreateWindow %v %v\n", winSize, workspaceId)
var ws *waveobj.Workspace
if workspaceId == "" {
ws1, err := CreateWorkspace(ctx, "", "", "")
ws1, err := CreateWorkspace(ctx, "", "", "", false)
if err != nil {
return nil, fmt.Errorf("error creating workspace: %w", err)
}
ws = ws1
err = BootstrapNewWorkspaceLayout(ctx, ws)
if err != nil {
errStr := fmt.Errorf("error bootstrapping new workspace layout: %w", err)
_, err = DeleteWorkspace(ctx, ws.OID, true)
if err != nil {
errStr = fmt.Errorf("%s\nerror deleting workspace: %w", errStr, err)
}
return nil, errStr
}
} else {
ws1, err := GetWorkspace(ctx, workspaceId)
if err != nil {
Expand Down Expand Up @@ -176,7 +185,7 @@ func CheckAndFixWindow(ctx context.Context, windowId string) *waveobj.Window {
}
if len(ws.TabIds) == 0 {
log.Printf("fixing workspace with no tabs %q (in checkAndFixWindow)\n", ws.OID)
_, err = CreateTab(ctx, ws.OID, "", true, false)
_, err = CreateTab(ctx, ws.OID, "", true, false, false)
if err != nil {
log.Printf("error creating tab (in checkAndFixWindow): %v\n", err)
}
Expand Down
18 changes: 14 additions & 4 deletions pkg/wcore/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/wavetermdev/waveterm/pkg/wstore"
)

func CreateWorkspace(ctx context.Context, name string, icon string, color string) (*waveobj.Workspace, error) {
func CreateWorkspace(ctx context.Context, name string, icon string, color string, isInitialLaunch bool) (*waveobj.Workspace, error) {
log.Println("CreateWorkspace")
ws := &waveobj.Workspace{
OID: uuid.NewString(),
Expand All @@ -31,7 +31,7 @@ func CreateWorkspace(ctx context.Context, name string, icon string, color string
return nil, fmt.Errorf("error inserting workspace: %w", err)
}

_, err = CreateTab(ctx, ws.OID, "", true, false)
_, err = CreateTab(ctx, ws.OID, "", true, false, isInitialLaunch)
if err != nil {
return nil, fmt.Errorf("error creating tab: %w", err)
}
Expand Down Expand Up @@ -81,15 +81,17 @@ func GetWorkspace(ctx context.Context, wsID string) (*waveobj.Workspace, error)
}

// returns tabid
func CreateTab(ctx context.Context, workspaceId string, tabName string, activateTab bool, pinned bool) (string, error) {
func CreateTab(ctx context.Context, workspaceId string, tabName string, activateTab bool, pinned bool, isInitialLaunch bool) (string, error) {
if tabName == "" {
ws, err := GetWorkspace(ctx, workspaceId)
if err != nil {
return "", fmt.Errorf("workspace %s not found: %w", workspaceId, err)
}
tabName = "T" + fmt.Sprint(len(ws.TabIds)+len(ws.PinnedTabIds)+1)
}
tab, err := createTabObj(ctx, workspaceId, tabName, pinned)

// The initial tab for the initial launch should be pinned
tab, err := createTabObj(ctx, workspaceId, tabName, pinned || isInitialLaunch)
if err != nil {
return "", fmt.Errorf("error creating tab: %w", err)
}
Expand All @@ -99,6 +101,14 @@ func CreateTab(ctx context.Context, workspaceId string, tabName string, activate
return "", fmt.Errorf("error setting active tab: %w", err)
}
}

// No need to apply an initial layout for the initial launch, since the starter layout will get applied after TOS modal dismissal
if !isInitialLaunch {
err = ApplyPortableLayout(ctx, tab.OID, GetNewTabLayout())
if err != nil {
return tab.OID, fmt.Errorf("error applying new tab layout: %w", err)
}
}
telemetry.GoUpdateActivityWrap(wshrpc.ActivityUpdate{NewTab: 1}, "createtab")
return tab.OID, nil
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/wshrpc/wshserver/wshserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/wavetermdev/waveterm/pkg/waveobj"
"github.com/wavetermdev/waveterm/pkg/wconfig"
"github.com/wavetermdev/waveterm/pkg/wcore"
"github.com/wavetermdev/waveterm/pkg/wlayout"
"github.com/wavetermdev/waveterm/pkg/wps"
"github.com/wavetermdev/waveterm/pkg/wshrpc"
"github.com/wavetermdev/waveterm/pkg/wshutil"
Expand Down Expand Up @@ -180,8 +179,8 @@ func (ws *WshServer) CreateBlockCommand(ctx context.Context, data wshrpc.Command
if err != nil {
return nil, fmt.Errorf("error creating block: %w", err)
}
err = wlayout.QueueLayoutActionForTab(ctx, tabId, waveobj.LayoutActionData{
ActionType: wlayout.LayoutActionDataType_Insert,
err = wcore.QueueLayoutActionForTab(ctx, tabId, waveobj.LayoutActionData{
ActionType: wcore.LayoutActionDataType_Insert,
BlockId: blockData.OID,
Magnified: data.Magnified,
Focused: true,
Expand Down Expand Up @@ -506,8 +505,8 @@ func (ws *WshServer) DeleteBlockCommand(ctx context.Context, data wshrpc.Command
if err != nil {
return fmt.Errorf("error deleting block: %w", err)
}
wlayout.QueueLayoutActionForTab(ctx, tabId, waveobj.LayoutActionData{
ActionType: wlayout.LayoutActionDataType_Remove,
wcore.QueueLayoutActionForTab(ctx, tabId, waveobj.LayoutActionData{
ActionType: wcore.LayoutActionDataType_Remove,
BlockId: data.BlockId,
})
updates := waveobj.ContextGetUpdatesRtn(ctx)
Expand Down