Skip to content

Commit

Permalink
updated services to support iterables
Browse files Browse the repository at this point in the history
  • Loading branch information
esimkowitz committed Nov 22, 2024
1 parent 808b2cf commit 124584a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 21 deletions.
14 changes: 9 additions & 5 deletions emain/emain-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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<WaveBrowserWindow> {
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);
Expand Down
10 changes: 4 additions & 6 deletions emain/emain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -374,7 +374,7 @@ async function createNewWaveWindow(): Promise<void> {
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;
Expand All @@ -383,9 +383,7 @@ async function createNewWaveWindow(): Promise<void> {
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();
}
Expand Down Expand Up @@ -660,7 +658,7 @@ async function relaunchBrowserWindows(): Promise<void> {
});
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) {
Expand Down
1 change: 1 addition & 0 deletions frontend/app/store/wos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package service
import (
"context"
"fmt"
"log"
"reflect"
"strings"

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions pkg/service/windowservice/windowservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 0 additions & 4 deletions pkg/wcore/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 124584a

Please sign in to comment.