diff --git a/emain/emain.ts b/emain/emain.ts index 9b5808877..0bc8a940d 100644 --- a/emain/emain.ts +++ b/emain/emain.ts @@ -253,11 +253,7 @@ async function handleWSEvent(evtMsg: WSEventType) { } } -async function mainResizeHandler(_: any, windowId: string, win: WaveBrowserWindow) { - if (win == null || win.isDestroyed() || win.fullScreen) { - return; - } - const bounds = win.getBounds(); +async function persistWindowBounds(windowId: string, bounds: electron.Rectangle) { try { await services.WindowService.SetWindowPosAndSize( windowId, @@ -269,6 +265,14 @@ async function mainResizeHandler(_: any, windowId: string, win: WaveBrowserWindo } } +async function mainResizeHandler(_: any, windowId: string, win: WaveBrowserWindow) { + if (win == null || win.isDestroyed() || win.fullScreen) { + return; + } + const bounds = win.getBounds(); + await persistWindowBounds(windowId, bounds); +} + function shNavHandler(event: Electron.Event, url: string) { if (url.startsWith("http://127.0.0.1:5173/index.html") || url.startsWith("http://localhost:5173/index.html")) { // this is a dev-mode hot-reload, ignore it @@ -310,9 +314,42 @@ function shFrameNavHandler(event: Electron.Event 200) { + rtn.x = 100; + } else { + rtn.x = Math.floor(spareWidth / 2); + } + } + if (workSize.height < targetHeight + 2 * targetPadding) { + const spareHeight = workSize.height - targetHeight; + if (spareHeight < 20) { + rtn.y = 10; + rtn.height = workSize.height - 20; + } else if (spareHeight > 200) { + rtn.y = 100; + } else { + rtn.y = Math.floor(spareHeight / 2); + } + } + return rtn; +} + +function computeWinBounds(waveWindow: WaveWindow): Electron.Rectangle { + if (waveWindow.isnew) { + return computeNewWinBounds(waveWindow); + } let winWidth = waveWindow?.winsize?.width; let winHeight = waveWindow?.winsize?.height; let winPosX = waveWindow.pos.x; @@ -339,7 +376,15 @@ function createBrowserWindow(clientId: string, waveWindow: WaveWindow, fullConfi width: winWidth, height: winHeight, }; + return winBounds; +} + +// note, this does not *show* the window. +// to show, await win.readyPromise and then win.show() +function createBrowserWindow(clientId: string, waveWindow: WaveWindow, fullConfig: FullConfigType): WaveBrowserWindow { + let winBounds = computeWinBounds(waveWindow); winBounds = ensureBoundsAreVisible(winBounds); + persistWindowBounds(waveWindow.oid, winBounds); const settings = fullConfig?.settings; const winOpts: Electron.BrowserWindowConstructorOptions = { titleBarStyle: diff --git a/frontend/app/view/webview/webview.less b/frontend/app/view/webview/webview.less index 74377d9e3..a9b8e86ce 100644 --- a/frontend/app/view/webview/webview.less +++ b/frontend/app/view/webview/webview.less @@ -4,6 +4,9 @@ .webview { height: 100%; width: 100%; - border-bottom-left-radius: 4px; - border-bottom-right-radius: 4px; + border: none !important; + outline: none !important; + overflow: hidden; + padding: 0; + margin: 0; } diff --git a/frontend/types/gotypes.d.ts b/frontend/types/gotypes.d.ts index e6378217c..e9613d386 100644 --- a/frontend/types/gotypes.d.ts +++ b/frontend/types/gotypes.d.ts @@ -677,6 +677,7 @@ declare global { type WaveWindow = WaveObj & { workspaceid: string; activetabid: string; + isnew?: boolean; pos: Point; winsize: WinSize; lastfocusts: number; diff --git a/pkg/service/windowservice/windowservice.go b/pkg/service/windowservice/windowservice.go index 6e1a9a2a8..f3702690f 100644 --- a/pkg/service/windowservice/windowservice.go +++ b/pkg/service/windowservice/windowservice.go @@ -38,6 +38,7 @@ func (ws *WindowService) SetWindowPosAndSize(ctx context.Context, windowId strin if size != nil { win.WinSize = *size } + win.IsNew = false err = wstore.DBUpdate(ctx, win) if err != nil { return nil, err diff --git a/pkg/waveobj/wtype.go b/pkg/waveobj/wtype.go index 0268952c7..2f3e87717 100644 --- a/pkg/waveobj/wtype.go +++ b/pkg/waveobj/wtype.go @@ -131,6 +131,7 @@ type Window struct { Version int `json:"version"` WorkspaceId string `json:"workspaceid"` ActiveTabId string `json:"activetabid"` + IsNew bool `json:"isnew,omitempty"` // set when a window is created on the backend so the FE can size it properly. cleared on first resize Pos Point `json:"pos"` WinSize WinSize `json:"winsize"` LastFocusTs int64 `json:"lastfocusts"` diff --git a/pkg/wcore/wcore.go b/pkg/wcore/wcore.go index d53418b20..e2967b7f0 100644 --- a/pkg/wcore/wcore.go +++ b/pkg/wcore/wcore.go @@ -96,16 +96,17 @@ func CreateWindow(ctx context.Context, winSize *waveobj.WinSize) (*waveobj.Windo workspaceId := uuid.NewString() if winSize == nil { winSize = &waveobj.WinSize{ - Width: 1200, - Height: 850, + Width: 0, + Height: 0, } } window := &waveobj.Window{ OID: windowId, WorkspaceId: workspaceId, + IsNew: true, Pos: waveobj.Point{ - X: 100, - Y: 100, + X: 0, + Y: 0, }, WinSize: *winSize, } @@ -178,7 +179,7 @@ func EnsureInitialData() (*waveobj.Window, bool, error) { if len(client.WindowIds) > 0 { return nil, false, nil } - window, err := CreateWindow(ctx, &waveobj.WinSize{Height: 0, Width: 0}) + window, err := CreateWindow(ctx, nil) if err != nil { return nil, false, fmt.Errorf("error creating window: %w", err) }