Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
esimkowitz committed Nov 22, 2024
1 parent 61779db commit a833dae
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 31 deletions.
17 changes: 17 additions & 0 deletions emain/emain-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,23 @@ export class WaveBrowserWindow extends BaseWindow {
}

async switchWorkspace(workspaceId: string) {
const curWorkspace = await WorkspaceService.GetWorkspace(this.workspaceId);
if ((curWorkspace.tabids.length > 1 && !curWorkspace.name) || !curWorkspace.icon) {
const choice = dialog.showMessageBoxSync(this, {
type: "question",
buttons: ["Cancel", "Open in New Window", "Yes"],
title: "Confirm",
message:
"This window has unsaved tabs, switching workspaces will delete the existing tabs. Would you like to continue?",
});
if (choice === 0) {
console.log("user cancelled switch workspace", this.waveWindowId);
return;
} else if (choice === 1) {
await WindowService.CreateWindow(null, workspaceId);
return;
}
}
const newWs = await WindowService.SwitchWorkspace(this.waveWindowId, workspaceId);
if (!newWs) {
return;
Expand Down
32 changes: 16 additions & 16 deletions frontend/app/store/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BlockServiceType {
}

// save the terminal state to a blockfile
SaveTerminalState(blockId: string, state: string, stateType: string, ptyOffset: number, termSize: TermSize): Promise<void> {
SaveTerminalState(ctx: string, blockId: string, state: string, stateType: number, ptyOffset: TermSize): Promise<void> {
return WOS.callBackendService("block", "SaveTerminalState", Array.from(arguments))
}
SaveWaveAiData(arg2: string, arg3: OpenAIPromptMessageType[]): Promise<void> {
Expand Down Expand Up @@ -81,12 +81,12 @@ export const FileService = new FileServiceType();
// objectservice.ObjectService (object)
class ObjectServiceType {
// @returns blockId (and object updates)
CreateBlock(blockDef: BlockDef, rtOpts: RuntimeOpts): Promise<string> {
CreateBlock(uiContext: BlockDef, blockDef: RuntimeOpts): Promise<string> {
return WOS.callBackendService("object", "CreateBlock", Array.from(arguments))
}

// @returns object updates
DeleteBlock(blockId: string): Promise<void> {
DeleteBlock(uiContext: string): Promise<void> {
return WOS.callBackendService("object", "DeleteBlock", Array.from(arguments))
}

Expand All @@ -101,17 +101,17 @@ class ObjectServiceType {
}

// @returns object updates
UpdateObject(waveObj: WaveObj, returnUpdates: boolean): Promise<void> {
UpdateObject(uiContext: WaveObj, waveObj: boolean): Promise<void> {
return WOS.callBackendService("object", "UpdateObject", Array.from(arguments))
}

// @returns object updates
UpdateObjectMeta(oref: string, meta: MetaType): Promise<void> {
UpdateObjectMeta(uiContext: string, oref: MetaType): Promise<void> {
return WOS.callBackendService("object", "UpdateObjectMeta", Array.from(arguments))
}

// @returns object updates
UpdateTabName(tabId: string, name: string): Promise<void> {
UpdateTabName(uiContext: string, tabId: string): Promise<void> {
return WOS.callBackendService("object", "UpdateTabName", Array.from(arguments))
}
}
Expand All @@ -129,28 +129,28 @@ export const UserInputService = new UserInputServiceType();

// windowservice.WindowService (window)
class WindowServiceType {
CloseWindow(fromElectron: string, arg3: boolean): Promise<void> {
CloseWindow(windowId: string, fromElectron: boolean): Promise<void> {
return WOS.callBackendService("window", "CloseWindow", Array.from(arguments))
}
GetWindow(arg1: string): Promise<WaveWindow> {
return WOS.callBackendService("window", "GetWindow", Array.from(arguments))
CreateWindow(winSize: WinSize, workspaceId: string): Promise<WaveWindow>Promise<Workspace> {
return WOS.callBackendService("window", "CreateWindow", Array.from(arguments))
}
MakeWindow(): Promise<WaveWindow> {
return WOS.callBackendService("window", "MakeWindow", Array.from(arguments))
GetWindow(windowId: string): Promise<WaveWindow> {
return WOS.callBackendService("window", "GetWindow", Array.from(arguments))
}

// move block to new window
// @returns object updates
MoveBlockToNewWindow(currentTabId: string, blockId: string): Promise<void> {
MoveBlockToNewWindow(ctx: string, currentTabId: string): Promise<void> {
return WOS.callBackendService("window", "MoveBlockToNewWindow", Array.from(arguments))
}

// set window position and size
// @returns object updates
SetWindowPosAndSize(pos: string, size: Point, arg4: WinSize): Promise<void> {
SetWindowPosAndSize(windowId: string, pos: Point, size: WinSize): Promise<void> {
return WOS.callBackendService("window", "SetWindowPosAndSize", Array.from(arguments))
}
SwitchWorkspace(workspaceId: string, arg3: string): Promise<Workspace> {
SwitchWorkspace(windowId: string, workspaceId: string): Promise<Workspace> {
return WOS.callBackendService("window", "SwitchWorkspace", Array.from(arguments))
}
}
Expand All @@ -160,7 +160,7 @@ export const WindowService = new WindowServiceType();
// workspaceservice.WorkspaceService (workspace)
class WorkspaceServiceType {
// @returns object updates
CloseTab(tabId: string, fromElectron: string, arg4: boolean): Promise<CloseTabRtnType> {
CloseTab(workspaceId: string, tabId: string, fromElectron: boolean): Promise<CloseTabRtnType> {
return WOS.callBackendService("workspace", "CloseTab", Array.from(arguments))
}

Expand All @@ -186,7 +186,7 @@ class WorkspaceServiceType {
}

// @returns object updates
UpdateTabIds(workspaceId: string, tabIds: string[]): Promise<void> {
UpdateTabIds(uiContext: string, workspaceId: string[]): Promise<void> {
return WOS.callBackendService("workspace", "UpdateTabIds", Array.from(arguments))
}
}
Expand Down
37 changes: 25 additions & 12 deletions pkg/service/windowservice/windowservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const DefaultTimeout = 2 * time.Second

type WindowService struct{}

func (svc *WindowService) GetWindow_Meta() tsgenmeta.MethodMeta {
return tsgenmeta.MethodMeta{
ArgNames: []string{"windowId"},
}
}

func (svc *WindowService) GetWindow(windowId string) (*waveobj.Window, error) {
ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout)
defer cancelFn()
Expand All @@ -33,25 +39,32 @@ func (svc *WindowService) GetWindow(windowId string) (*waveobj.Window, error) {
return window, nil
}

func (svc *WindowService) MakeWindow(ctx context.Context) (*waveobj.Window, error) {
log.Println("MakeWindow")
window, err := wcore.CreateWindow(ctx, nil, "")
func (svc *WindowService) CreateWindow_Meta() tsgenmeta.MethodMeta {
return tsgenmeta.MethodMeta{
ArgNames: []string{"winSize", "workspaceId"},
}
}

func (svc *WindowService) CreateWindow(ctx context.Context, winSize *waveobj.WinSize, workspaceId string) (*waveobj.Window, *waveobj.Workspace, error) {
window, err := wcore.CreateWindow(ctx, winSize, workspaceId)
if err != nil {
log.Printf("error creating window: %v\n", err)
return nil, err
return nil, nil, fmt.Errorf("error creating window: %w", err)
}
log.Printf("New window: %v\n", window)
ws, err := wcore.GetWorkspace(ctx, window.WorkspaceId)
if err != nil {
log.Printf("error getting workspace: %v\n", err)
return nil, err
return nil, nil, fmt.Errorf("error getting workspace: %w", err)
}
log.Printf("New workspace: %v\n", ws)
err = wlayout.BootstrapNewWorkspaceLayout(ctx, ws)
if len(ws.TabIds) == 0 {
err = wlayout.BootstrapNewWorkspaceLayout(ctx, ws)
if err != nil {
return window, ws, fmt.Errorf("error bootstrapping new workspace layout: %w", err)
}
}
ws, err = wcore.GetWorkspace(ctx, window.WorkspaceId)
if err != nil {
return window, err
return window, ws, fmt.Errorf("error getting updated workspace: %w", err)
}
return window, nil
return window, ws, nil
}

func (svc *WindowService) SetWindowPosAndSize_Meta() tsgenmeta.MethodMeta {
Expand Down
21 changes: 18 additions & 3 deletions pkg/wcore/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,45 @@ import (
)

func SwitchWorkspace(ctx context.Context, windowId string, workspaceId string) (*waveobj.Workspace, error) {
log.Printf("SwitchWorkspace %s %s\n", windowId, workspaceId)
ws, err := GetWorkspace(ctx, workspaceId)
if err != nil {
return nil, err
return nil, fmt.Errorf("error getting new workspace: %w", err)
}
window, err := GetWindow(ctx, windowId)
if err != nil {
return nil, err
return nil, fmt.Errorf("error getting window: %w", err)
}
if window.WorkspaceId == workspaceId {
return nil, nil
}

curWs, err := GetWorkspace(ctx, window.WorkspaceId)
if err != nil {
return nil, fmt.Errorf("error getting current workspace: %w", err)
}
if curWs.Name == "" || curWs.Icon == "" {
log.Printf("current workspace %s is not named, deleting it\n", curWs.OID)
err = DeleteWorkspace(ctx, curWs.OID, false)
if err != nil {
return nil, fmt.Errorf("error deleting current workspace: %w", err)
}
}

allWindows, err := wstore.DBGetAllObjsByType[*waveobj.Window](ctx, waveobj.OType_Window)
if err != nil {
return nil, err
return nil, fmt.Errorf("error getting all windows: %w", err)
}

for _, w := range allWindows {
if w.WorkspaceId == workspaceId {
log.Printf("workspace %s already has a window %s, focusing that window\n", workspaceId, w.OID)
return nil, FocusWindow(ctx, w.OID)
}
}

window.WorkspaceId = workspaceId
log.Printf("switching window %s to workspace %s\n", windowId, workspaceId)
return ws, wstore.DBUpdate(ctx, window)
}

Expand Down

0 comments on commit a833dae

Please sign in to comment.