diff --git a/emain/emain-window.ts b/emain/emain-window.ts index 761da97c1..0f6e4d431 100644 --- a/emain/emain-window.ts +++ b/emain/emain-window.ts @@ -245,7 +245,7 @@ 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) { + if (curWorkspace.tabids.length > 1 && (!curWorkspace.name || !curWorkspace.icon)) { const choice = dialog.showMessageBoxSync(this, { type: "question", buttons: ["Cancel", "Open in New Window", "Yes"], @@ -487,20 +487,24 @@ export function getAllWaveWindows(): WaveBrowserWindow[] { return Array.from(waveWindowMap.values()); } -// TODO: // note, this does not *show* the window. // to show, await win.readyPromise and then win.show() export async function createBrowserWindow( - clientId: string, waveWindow: WaveWindow, fullConfig: FullConfigType, opts: WindowOpts ): Promise { + let workspace: Workspace; + if (!waveWindow) { + [waveWindow, workspace] = await WindowService.CreateWindow(null, ""); + } else { + workspace = await WorkspaceService.GetWorkspace(waveWindow.workspaceid); + } + console.log("workspace", workspace); + console.log("createBrowserWindow", waveWindow.oid); const bwin = new WaveBrowserWindow(waveWindow, fullConfig, opts); - const workspace = await WorkspaceService.GetWorkspace(waveWindow.workspaceid); - console.log("workspace", workspace); if (workspace.activetabid) { console.log("set active tab id"); await bwin.setActiveTab(workspace.activetabid); diff --git a/emain/emain.ts b/emain/emain.ts index 3a3486d80..b07826b1d 100644 --- a/emain/emain.ts +++ b/emain/emain.ts @@ -114,7 +114,7 @@ function handleWSEvent(evtMsg: WSEventType) { } const clientData = await services.ClientService.GetClientData(); const fullConfig = await services.FileService.GetFullConfig(); - const newWin = await createBrowserWindow(clientData.oid, windowData, fullConfig, { unamePlatform }); + const newWin = await createBrowserWindow(windowData, fullConfig, { unamePlatform }); await newWin.waveReadyPromise; newWin.show(); } else if (evtMsg.eventtype == "electron:closewindow") { @@ -374,7 +374,7 @@ async function createNewWaveWindow(): Promise { const existingWindowId = clientData.windowids[0]; const existingWindowData = (await services.ObjectService.GetObject("window:" + existingWindowId)) as WaveWindow; if (existingWindowData != null) { - const win = await createBrowserWindow(clientData.oid, existingWindowData, fullConfig, { unamePlatform }); + const win = await createBrowserWindow(existingWindowData, fullConfig, { unamePlatform }); await win.waveReadyPromise; win.show(); recreatedWindow = true; @@ -383,9 +383,7 @@ async function createNewWaveWindow(): Promise { if (recreatedWindow) { return; } - console.log("makewindow"); - const newWindow = await services.WindowService.MakeWindow(); - const newBrowserWindow = await createBrowserWindow(clientData.oid, newWindow, fullConfig, { unamePlatform }); + const newBrowserWindow = await createBrowserWindow(null, fullConfig, { unamePlatform }); await newBrowserWindow.waveReadyPromise; newBrowserWindow.show(); } @@ -660,7 +658,7 @@ async function relaunchBrowserWindows(): Promise { }); continue; } - const win = await createBrowserWindow(clientData.oid, windowData, fullConfig, { unamePlatform }); + const win = await createBrowserWindow(windowData, fullConfig, { unamePlatform }); wins.push(win); } for (const win of wins) { diff --git a/frontend/app/store/wos.ts b/frontend/app/store/wos.ts index dadb43d49..72b29a4c9 100644 --- a/frontend/app/store/wos.ts +++ b/frontend/app/store/wos.ts @@ -128,6 +128,7 @@ function callBackendService(service: string, method: string, args: any[], noUICo } const durationStr = Date.now() - startTs + "ms"; debugLogBackendCall(methodName, durationStr, args); + console.log("callBackendService", methodName, durationStr, respData); return respData.data; }); return prtn; diff --git a/pkg/service/service.go b/pkg/service/service.go index c0373db12..72a234cb2 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -6,6 +6,7 @@ package service import ( "context" "fmt" + "log" "reflect" "strings" @@ -172,6 +173,7 @@ func convertSpecial(argType reflect.Type, jsonArg any) (any, error) { } func convertSpecialForReturn(argType reflect.Type, nativeArg any) (any, error) { + log.Printf("convertSpecialForReturn(%s, %T)", argType, nativeArg) if argType == waveObjRType { return waveobj.ToJsonMap(nativeArg.(waveobj.WaveObj)) } else if argType == waveObjSliceRType { @@ -279,6 +281,7 @@ func convertReturnValues(rtnVals []reflect.Value) *WebReturnType { if len(rtnVals) == 0 { return rtn } + rtnData := make([]any, 0) for _, val := range rtnVals { if isNilable(val) && val.IsNil() { continue @@ -299,10 +302,15 @@ func convertReturnValues(rtnVals []reflect.Value) *WebReturnType { rtn.Error = fmt.Errorf("cannot convert special return value: %v", err).Error() continue } - rtn.Data = jsonVal + rtnData = append(rtnData, jsonVal) continue } - rtn.Data = val.Interface() + rtnData = append(rtnData, val.Interface()) + } + if len(rtnData) > 1 { + rtn.Data = rtnData + } else if len(rtnData) == 1 { + rtn.Data = rtnData[0] } if rtn.Error == "" { rtn.Success = true diff --git a/pkg/service/windowservice/windowservice.go b/pkg/service/windowservice/windowservice.go index 77f672d5a..01c7d14ee 100644 --- a/pkg/service/windowservice/windowservice.go +++ b/pkg/service/windowservice/windowservice.go @@ -55,15 +55,19 @@ func (svc *WindowService) CreateWindow(ctx context.Context, winSize *waveobj.Win return nil, nil, fmt.Errorf("error getting workspace: %w", err) } if len(ws.TabIds) == 0 { + _, err = wcore.CreateTab(ctx, ws.OID, "", true) + if err != nil { + return window, ws, fmt.Errorf("error creating tab: %w", err) + } + ws, err = wcore.GetWorkspace(ctx, window.WorkspaceId) + if err != nil { + return nil, nil, fmt.Errorf("error getting updated workspace: %w", err) + } 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, ws, fmt.Errorf("error getting updated workspace: %w", err) - } return window, ws, nil } diff --git a/pkg/wcore/workspace.go b/pkg/wcore/workspace.go index f541fcebc..c0c65c672 100644 --- a/pkg/wcore/workspace.go +++ b/pkg/wcore/workspace.go @@ -19,10 +19,6 @@ func CreateWorkspace(ctx context.Context) (*waveobj.Workspace, error) { TabIds: []string{}, } wstore.DBInsert(ctx, ws) - _, err := CreateTab(ctx, ws.OID, "", true) - if err != nil { - return nil, fmt.Errorf("error inserting tab: %w", err) - } return ws, nil }