mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
move CreateX functions to wcore (#275)
This commit is contained in:
parent
4e68211f22
commit
f28bdccb5d
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/wavetermdev/thenextwave/pkg/waveobj"
|
"github.com/wavetermdev/thenextwave/pkg/waveobj"
|
||||||
"github.com/wavetermdev/thenextwave/pkg/wcloud"
|
"github.com/wavetermdev/thenextwave/pkg/wcloud"
|
||||||
"github.com/wavetermdev/thenextwave/pkg/wconfig"
|
"github.com/wavetermdev/thenextwave/pkg/wconfig"
|
||||||
|
"github.com/wavetermdev/thenextwave/pkg/wcore"
|
||||||
"github.com/wavetermdev/thenextwave/pkg/web"
|
"github.com/wavetermdev/thenextwave/pkg/web"
|
||||||
"github.com/wavetermdev/thenextwave/pkg/wps"
|
"github.com/wavetermdev/thenextwave/pkg/wps"
|
||||||
"github.com/wavetermdev/thenextwave/pkg/wshrpc"
|
"github.com/wavetermdev/thenextwave/pkg/wshrpc"
|
||||||
@ -212,7 +213,7 @@ 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 = wstore.EnsureInitialData()
|
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
|
||||||
|
@ -361,7 +361,7 @@ function handleWSEventMessage(msg: WSEventType) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.eventtype == "layoutaction") {
|
if (msg.eventtype == "layoutaction") {
|
||||||
const layoutAction: WSLayoutActionData = msg.data;
|
const layoutAction: LayoutActionData = msg.data;
|
||||||
const tabId = layoutAction.tabid;
|
const tabId = layoutAction.tabid;
|
||||||
const layoutModel = getLayoutModelForTabById(tabId);
|
const layoutModel = getLayoutModelForTabById(tabId);
|
||||||
switch (layoutAction.actiontype) {
|
switch (layoutAction.actiontype) {
|
||||||
|
20
frontend/types/gotypes.d.ts
vendored
20
frontend/types/gotypes.d.ts
vendored
@ -208,6 +208,16 @@ declare global {
|
|||||||
data64: string;
|
data64: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// waveobj.LayoutActionData
|
||||||
|
type LayoutActionData = {
|
||||||
|
tabid: string;
|
||||||
|
actiontype: string;
|
||||||
|
blockid: string;
|
||||||
|
nodesize?: number;
|
||||||
|
indexarr?: number[];
|
||||||
|
magnified?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
// waveobj.LayoutState
|
// waveobj.LayoutState
|
||||||
type LayoutState = WaveObj & {
|
type LayoutState = WaveObj & {
|
||||||
rootnode?: any;
|
rootnode?: any;
|
||||||
@ -525,16 +535,6 @@ declare global {
|
|||||||
data64: string;
|
data64: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
// eventbus.WSLayoutActionData
|
|
||||||
type WSLayoutActionData = {
|
|
||||||
tabid: string;
|
|
||||||
actiontype: string;
|
|
||||||
blockid: string;
|
|
||||||
nodesize?: number;
|
|
||||||
indexarr?: number[];
|
|
||||||
magnified?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
// webcmd.WSRpcCommand
|
// webcmd.WSRpcCommand
|
||||||
type WSRpcCommand = {
|
type WSRpcCommand = {
|
||||||
wscommand: "rpc";
|
wscommand: "rpc";
|
||||||
|
@ -56,15 +56,6 @@ const (
|
|||||||
WSLayoutActionType_Remove = "delete"
|
WSLayoutActionType_Remove = "delete"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WSLayoutActionData struct {
|
|
||||||
TabId string `json:"tabid"`
|
|
||||||
ActionType string `json:"actiontype"`
|
|
||||||
BlockId string `json:"blockid"`
|
|
||||||
NodeSize uint `json:"nodesize,omitempty"`
|
|
||||||
IndexArr []int `json:"indexarr,omitempty"`
|
|
||||||
Magnified bool `json:"magnified,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var globalLock = &sync.Mutex{}
|
var globalLock = &sync.Mutex{}
|
||||||
var wsMap = make(map[string]*WindowWatchData) // websocketid => WindowWatchData
|
var wsMap = make(map[string]*WindowWatchData) // websocketid => WindowWatchData
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/wavetermdev/thenextwave/pkg/service/objectservice"
|
"github.com/wavetermdev/thenextwave/pkg/service/objectservice"
|
||||||
"github.com/wavetermdev/thenextwave/pkg/util/utilfn"
|
"github.com/wavetermdev/thenextwave/pkg/util/utilfn"
|
||||||
"github.com/wavetermdev/thenextwave/pkg/waveobj"
|
"github.com/wavetermdev/thenextwave/pkg/waveobj"
|
||||||
|
"github.com/wavetermdev/thenextwave/pkg/wcore"
|
||||||
"github.com/wavetermdev/thenextwave/pkg/wshrpc"
|
"github.com/wavetermdev/thenextwave/pkg/wshrpc"
|
||||||
"github.com/wavetermdev/thenextwave/pkg/wstore"
|
"github.com/wavetermdev/thenextwave/pkg/wstore"
|
||||||
)
|
)
|
||||||
@ -63,7 +64,7 @@ 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 wstore.CreateWindow(ctx, nil)
|
return wcore.CreateWindow(ctx, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *ClientService) GetAllConnStatus(ctx context.Context) ([]wshrpc.ConnStatus, error) {
|
func (cs *ClientService) GetAllConnStatus(ctx context.Context) ([]wshrpc.ConnStatus, error) {
|
||||||
@ -183,7 +184,7 @@ func (cs *ClientService) BootstrapStarterLayout(ctx context.Context) error {
|
|||||||
|
|
||||||
eventbus.SendEventToWindow(windowId, eventbus.WSEventType{
|
eventbus.SendEventToWindow(windowId, eventbus.WSEventType{
|
||||||
EventType: eventbus.WSEvent_LayoutAction,
|
EventType: eventbus.WSEvent_LayoutAction,
|
||||||
Data: &eventbus.WSLayoutActionData{
|
Data: &waveobj.LayoutActionData{
|
||||||
ActionType: "insertatindex",
|
ActionType: "insertatindex",
|
||||||
TabId: tabId,
|
TabId: tabId,
|
||||||
BlockId: blockData.OID,
|
BlockId: blockData.OID,
|
||||||
|
@ -83,21 +83,11 @@ func (svc *ObjectService) AddTabToWorkspace(uiContext waveobj.UIContext, tabName
|
|||||||
ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout)
|
ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout)
|
||||||
defer cancelFn()
|
defer cancelFn()
|
||||||
ctx = waveobj.ContextWithUpdates(ctx)
|
ctx = waveobj.ContextWithUpdates(ctx)
|
||||||
windowData, err := wstore.DBMustGet[*waveobj.Window](ctx, uiContext.WindowId)
|
tabId, err := wcore.CreateTab(ctx, uiContext.WindowId, tabName, activateTab)
|
||||||
if err != nil {
|
|
||||||
return "", nil, fmt.Errorf("error getting window: %w", err)
|
|
||||||
}
|
|
||||||
tab, err := wstore.CreateTab(ctx, windowData.WorkspaceId, tabName)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, fmt.Errorf("error creating tab: %w", err)
|
return "", nil, fmt.Errorf("error creating tab: %w", err)
|
||||||
}
|
}
|
||||||
if activateTab {
|
return tabId, waveobj.ContextGetUpdatesRtn(ctx), nil
|
||||||
err = wstore.SetActiveTab(ctx, uiContext.WindowId, tab.OID)
|
|
||||||
if err != nil {
|
|
||||||
return "", nil, fmt.Errorf("error setting active tab: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tab.OID, waveobj.ContextGetUpdatesRtn(ctx), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *ObjectService) UpdateWorkspaceTabIds_Meta() tsgenmeta.MethodMeta {
|
func (svc *ObjectService) UpdateWorkspaceTabIds_Meta() tsgenmeta.MethodMeta {
|
||||||
|
@ -119,7 +119,7 @@ func (svc *WindowService) MoveBlockToNewWindow(ctx context.Context, currentTabId
|
|||||||
if !foundBlock {
|
if !foundBlock {
|
||||||
return nil, fmt.Errorf("block not found in current tab")
|
return nil, fmt.Errorf("block not found in current tab")
|
||||||
}
|
}
|
||||||
newWindow, err := wstore.CreateWindow(ctx, nil)
|
newWindow, err := wcore.CreateWindow(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error creating window: %w", err)
|
return nil, fmt.Errorf("error creating window: %w", err)
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ func (svc *WindowService) MoveBlockToNewWindow(ctx context.Context, currentTabId
|
|||||||
}
|
}
|
||||||
eventbus.SendEventToWindow(curWindowId, eventbus.WSEventType{
|
eventbus.SendEventToWindow(curWindowId, eventbus.WSEventType{
|
||||||
EventType: eventbus.WSEvent_LayoutAction,
|
EventType: eventbus.WSEvent_LayoutAction,
|
||||||
Data: eventbus.WSLayoutActionData{
|
Data: waveobj.LayoutActionData{
|
||||||
ActionType: eventbus.WSLayoutActionType_Remove,
|
ActionType: eventbus.WSLayoutActionType_Remove,
|
||||||
TabId: currentTabId,
|
TabId: currentTabId,
|
||||||
BlockId: blockId,
|
BlockId: blockId,
|
||||||
@ -145,7 +145,7 @@ func (svc *WindowService) MoveBlockToNewWindow(ctx context.Context, currentTabId
|
|||||||
})
|
})
|
||||||
eventbus.SendEventToWindow(newWindow.OID, eventbus.WSEventType{
|
eventbus.SendEventToWindow(newWindow.OID, eventbus.WSEventType{
|
||||||
EventType: eventbus.WSEvent_LayoutAction,
|
EventType: eventbus.WSEvent_LayoutAction,
|
||||||
Data: eventbus.WSLayoutActionData{
|
Data: waveobj.LayoutActionData{
|
||||||
ActionType: eventbus.WSLayoutActionType_Insert,
|
ActionType: eventbus.WSLayoutActionType_Insert,
|
||||||
TabId: newWindow.ActiveTabId,
|
TabId: newWindow.ActiveTabId,
|
||||||
BlockId: blockId,
|
BlockId: blockId,
|
||||||
|
@ -33,7 +33,7 @@ var ExtraTypes = []any{
|
|||||||
waveobj.UIContext{},
|
waveobj.UIContext{},
|
||||||
eventbus.WSEventType{},
|
eventbus.WSEventType{},
|
||||||
eventbus.WSFileEventData{},
|
eventbus.WSFileEventData{},
|
||||||
eventbus.WSLayoutActionData{},
|
waveobj.LayoutActionData{},
|
||||||
filestore.WaveFile{},
|
filestore.WaveFile{},
|
||||||
wconfig.SettingsConfigType{},
|
wconfig.SettingsConfigType{},
|
||||||
wconfig.TermThemesConfigType{},
|
wconfig.TermThemesConfigType{},
|
||||||
|
@ -173,6 +173,15 @@ func (t *Tab) GetBlockORefs() []ORef {
|
|||||||
return rtn
|
return rtn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LayoutActionData struct {
|
||||||
|
TabId string `json:"tabid"`
|
||||||
|
ActionType string `json:"actiontype"`
|
||||||
|
BlockId string `json:"blockid"`
|
||||||
|
NodeSize uint `json:"nodesize,omitempty"`
|
||||||
|
IndexArr []int `json:"indexarr,omitempty"`
|
||||||
|
Magnified bool `json:"magnified,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type LayoutState struct {
|
type LayoutState struct {
|
||||||
OID string `json:"oid"`
|
OID string `json:"oid"`
|
||||||
Version int `json:"version"`
|
Version int `json:"version"`
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/wavetermdev/thenextwave/pkg/blockcontroller"
|
"github.com/wavetermdev/thenextwave/pkg/blockcontroller"
|
||||||
"github.com/wavetermdev/thenextwave/pkg/waveobj"
|
"github.com/wavetermdev/thenextwave/pkg/waveobj"
|
||||||
"github.com/wavetermdev/thenextwave/pkg/wps"
|
"github.com/wavetermdev/thenextwave/pkg/wps"
|
||||||
@ -68,3 +69,117 @@ func DeleteTab(ctx context.Context, workspaceId string, tabId string) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns tabid
|
||||||
|
func CreateTab(ctx context.Context, windowId string, tabName string, activateTab bool) (string, error) {
|
||||||
|
windowData, err := wstore.DBMustGet[*waveobj.Window](ctx, windowId)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error getting window: %w", err)
|
||||||
|
}
|
||||||
|
tab, err := wstore.CreateTab(ctx, windowData.WorkspaceId, tabName)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error creating tab: %w", err)
|
||||||
|
}
|
||||||
|
if activateTab {
|
||||||
|
err = wstore.SetActiveTab(ctx, windowId, tab.OID)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error setting active tab: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tab.OID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateWindow(ctx context.Context, winSize *waveobj.WinSize) (*waveobj.Window, error) {
|
||||||
|
windowId := uuid.NewString()
|
||||||
|
workspaceId := uuid.NewString()
|
||||||
|
if winSize == nil {
|
||||||
|
winSize = &waveobj.WinSize{
|
||||||
|
Width: 1200,
|
||||||
|
Height: 800,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window := &waveobj.Window{
|
||||||
|
OID: windowId,
|
||||||
|
WorkspaceId: workspaceId,
|
||||||
|
Pos: waveobj.Point{
|
||||||
|
X: 100,
|
||||||
|
Y: 100,
|
||||||
|
},
|
||||||
|
WinSize: *winSize,
|
||||||
|
}
|
||||||
|
err := wstore.DBInsert(ctx, window)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error inserting window: %w", err)
|
||||||
|
}
|
||||||
|
ws := &waveobj.Workspace{
|
||||||
|
OID: workspaceId,
|
||||||
|
Name: "w" + workspaceId[0:8],
|
||||||
|
}
|
||||||
|
err = wstore.DBInsert(ctx, ws)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error inserting workspace: %w", err)
|
||||||
|
}
|
||||||
|
_, err = CreateTab(ctx, windowId, "T1", true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error inserting tab: %w", err)
|
||||||
|
}
|
||||||
|
client, err := wstore.DBGetSingleton[*waveobj.Client](ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting client: %w", err)
|
||||||
|
}
|
||||||
|
client.WindowIds = append(client.WindowIds, windowId)
|
||||||
|
err = wstore.DBUpdate(ctx, client)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error updating client: %w", err)
|
||||||
|
}
|
||||||
|
return wstore.DBMustGet[*waveobj.Window](ctx, windowId)
|
||||||
|
}
|
||||||
|
|
||||||
|
func EnsureInitialData() 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()
|
||||||
|
client, err := wstore.DBGetSingleton[*waveobj.Client](ctx)
|
||||||
|
if err == wstore.ErrNotFound {
|
||||||
|
client, err = CreateClient(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error creating client: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(client.WindowIds) > 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
_, err = CreateWindow(ctx, &waveobj.WinSize{Height: 0, Width: 0})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error creating window: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateClient(ctx context.Context) (*waveobj.Client, error) {
|
||||||
|
client := &waveobj.Client{
|
||||||
|
OID: uuid.NewString(),
|
||||||
|
WindowIds: []string{},
|
||||||
|
}
|
||||||
|
err := wstore.DBInsert(ctx, client)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error inserting client: %w", err)
|
||||||
|
}
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateBlock(ctx context.Context, createBlockCmd wshrpc.CommandCreateBlockData) (*waveobj.ORef, error) {
|
||||||
|
tabId := createBlockCmd.TabId
|
||||||
|
blockData, err := wstore.CreateBlock(ctx, tabId, createBlockCmd.BlockDef, createBlockCmd.RtOpts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error creating block: %w", err)
|
||||||
|
}
|
||||||
|
controllerName := blockData.Meta.GetString(waveobj.MetaKey_Controller, "")
|
||||||
|
if controllerName != "" {
|
||||||
|
err = blockcontroller.StartBlockController(ctx, createBlockCmd.TabId, blockData.OID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error starting block controller: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &waveobj.ORef{OType: waveobj.OType_Block, OID: blockData.OID}, nil
|
||||||
|
}
|
||||||
|
@ -177,7 +177,6 @@ func SavePlotData(ctx context.Context, blockId string, history string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ws *WshServer) GetMetaCommand(ctx context.Context, data wshrpc.CommandGetMetaData) (waveobj.MetaMapType, error) {
|
func (ws *WshServer) GetMetaCommand(ctx context.Context, data wshrpc.CommandGetMetaData) (waveobj.MetaMapType, error) {
|
||||||
log.Printf("calling meta: %s\n", data.ORef)
|
|
||||||
obj, err := wstore.DBGetORef(ctx, data.ORef)
|
obj, err := wstore.DBGetORef(ctx, data.ORef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error getting object: %w", err)
|
return nil, fmt.Errorf("error getting object: %w", err)
|
||||||
@ -263,21 +262,10 @@ func sendWStoreUpdatesToEventBus(updates waveobj.UpdatesRtnType) {
|
|||||||
func (ws *WshServer) CreateBlockCommand(ctx context.Context, data wshrpc.CommandCreateBlockData) (*waveobj.ORef, error) {
|
func (ws *WshServer) CreateBlockCommand(ctx context.Context, data wshrpc.CommandCreateBlockData) (*waveobj.ORef, error) {
|
||||||
ctx = waveobj.ContextWithUpdates(ctx)
|
ctx = waveobj.ContextWithUpdates(ctx)
|
||||||
tabId := data.TabId
|
tabId := data.TabId
|
||||||
if data.TabId != "" {
|
blockRef, err := wcore.CreateBlock(ctx, data)
|
||||||
tabId = data.TabId
|
|
||||||
}
|
|
||||||
blockData, err := wstore.CreateBlock(ctx, tabId, data.BlockDef, data.RtOpts)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error creating block: %w", err)
|
return nil, fmt.Errorf("error creating block: %w", err)
|
||||||
}
|
}
|
||||||
controllerName := blockData.Meta.GetString(waveobj.MetaKey_Controller, "")
|
|
||||||
if controllerName != "" {
|
|
||||||
// TODO
|
|
||||||
err = blockcontroller.StartBlockController(ctx, data.TabId, blockData.OID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error starting block controller: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updates := waveobj.ContextGetUpdatesRtn(ctx)
|
updates := waveobj.ContextGetUpdatesRtn(ctx)
|
||||||
sendWStoreUpdatesToEventBus(updates)
|
sendWStoreUpdatesToEventBus(updates)
|
||||||
windowId, err := wstore.DBFindWindowForTabId(ctx, tabId)
|
windowId, err := wstore.DBFindWindowForTabId(ctx, tabId)
|
||||||
@ -289,14 +277,14 @@ func (ws *WshServer) CreateBlockCommand(ctx context.Context, data wshrpc.Command
|
|||||||
}
|
}
|
||||||
eventbus.SendEventToWindow(windowId, eventbus.WSEventType{
|
eventbus.SendEventToWindow(windowId, eventbus.WSEventType{
|
||||||
EventType: eventbus.WSEvent_LayoutAction,
|
EventType: eventbus.WSEvent_LayoutAction,
|
||||||
Data: &eventbus.WSLayoutActionData{
|
Data: &waveobj.LayoutActionData{
|
||||||
ActionType: "insert",
|
ActionType: "insert",
|
||||||
TabId: tabId,
|
TabId: tabId,
|
||||||
BlockId: blockData.OID,
|
BlockId: blockRef.OID,
|
||||||
Magnified: data.Magnified,
|
Magnified: data.Magnified,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return &waveobj.ORef{OType: waveobj.OType_Block, OID: blockData.OID}, nil
|
return &waveobj.ORef{OType: waveobj.OType_Block, OID: blockRef.OID}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ws *WshServer) SetViewCommand(ctx context.Context, data wshrpc.CommandBlockSetViewData) error {
|
func (ws *WshServer) SetViewCommand(ctx context.Context, data wshrpc.CommandBlockSetViewData) error {
|
||||||
@ -442,7 +430,7 @@ func (ws *WshServer) DeleteBlockCommand(ctx context.Context, data wshrpc.Command
|
|||||||
}
|
}
|
||||||
eventbus.SendEventToWindow(windowId, eventbus.WSEventType{
|
eventbus.SendEventToWindow(windowId, eventbus.WSEventType{
|
||||||
EventType: eventbus.WSEvent_LayoutAction,
|
EventType: eventbus.WSEvent_LayoutAction,
|
||||||
Data: &eventbus.WSLayoutActionData{
|
Data: &waveobj.LayoutActionData{
|
||||||
ActionType: "delete",
|
ActionType: "delete",
|
||||||
TabId: tabId,
|
TabId: tabId,
|
||||||
BlockId: data.BlockId,
|
BlockId: data.BlockId,
|
||||||
|
@ -6,7 +6,6 @@ package wstore
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/wavetermdev/thenextwave/pkg/util/utilfn"
|
"github.com/wavetermdev/thenextwave/pkg/util/utilfn"
|
||||||
@ -189,56 +188,6 @@ func UpdateObjectMeta(ctx context.Context, oref waveobj.ORef, meta waveobj.MetaM
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateWindow(ctx context.Context, winSize *waveobj.WinSize) (*waveobj.Window, error) {
|
|
||||||
windowId := uuid.NewString()
|
|
||||||
workspaceId := uuid.NewString()
|
|
||||||
if winSize == nil {
|
|
||||||
winSize = &waveobj.WinSize{
|
|
||||||
Width: 1200,
|
|
||||||
Height: 800,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
window := &waveobj.Window{
|
|
||||||
OID: windowId,
|
|
||||||
WorkspaceId: workspaceId,
|
|
||||||
Pos: waveobj.Point{
|
|
||||||
X: 100,
|
|
||||||
Y: 100,
|
|
||||||
},
|
|
||||||
WinSize: *winSize,
|
|
||||||
}
|
|
||||||
err := DBInsert(ctx, window)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error inserting window: %w", err)
|
|
||||||
}
|
|
||||||
ws := &waveobj.Workspace{
|
|
||||||
OID: workspaceId,
|
|
||||||
Name: "w" + workspaceId[0:8],
|
|
||||||
}
|
|
||||||
err = DBInsert(ctx, ws)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error inserting workspace: %w", err)
|
|
||||||
}
|
|
||||||
tab, err := CreateTab(ctx, ws.OID, "T1")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error inserting tab: %w", err)
|
|
||||||
}
|
|
||||||
err = SetActiveTab(ctx, window.OID, tab.OID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error setting active tab: %w", err)
|
|
||||||
}
|
|
||||||
client, err := DBGetSingleton[*waveobj.Client](ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error getting client: %w", err)
|
|
||||||
}
|
|
||||||
client.WindowIds = append(client.WindowIds, windowId)
|
|
||||||
err = DBUpdate(ctx, client)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error updating client: %w", err)
|
|
||||||
}
|
|
||||||
return DBMustGet[*waveobj.Window](ctx, windowId)
|
|
||||||
}
|
|
||||||
|
|
||||||
func MoveBlockToTab(ctx context.Context, currentTabId string, newTabId string, blockId string) error {
|
func MoveBlockToTab(ctx context.Context, currentTabId string, newTabId string, blockId string) error {
|
||||||
return WithTx(ctx, func(tx *TxWrap) error {
|
return WithTx(ctx, func(tx *TxWrap) error {
|
||||||
currentTab, _ := DBGet[*waveobj.Tab](tx.Context(), currentTabId)
|
currentTab, _ := DBGet[*waveobj.Tab](tx.Context(), currentTabId)
|
||||||
@ -260,36 +209,3 @@ func MoveBlockToTab(ctx context.Context, currentTabId string, newTabId string, b
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateClient(ctx context.Context) (*waveobj.Client, error) {
|
|
||||||
client := &waveobj.Client{
|
|
||||||
OID: uuid.NewString(),
|
|
||||||
WindowIds: []string{},
|
|
||||||
}
|
|
||||||
err := DBInsert(ctx, client)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error inserting client: %w", err)
|
|
||||||
}
|
|
||||||
return client, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func EnsureInitialData() 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()
|
|
||||||
client, err := DBGetSingleton[*waveobj.Client](ctx)
|
|
||||||
if err == ErrNotFound {
|
|
||||||
client, err = CreateClient(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error creating client: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(client.WindowIds) > 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
_, err = CreateWindow(ctx, &waveobj.WinSize{Height: 0, Width: 0})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error creating window: %w", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user