@@ -64,6 +64,11 @@ function setupResizeHandler(mainWindow: BrowserWindow, handler: () => void) {
6464}
6565
6666type BottomAlignedPosition = { left : number ; bottom : number } ;
67+ type OverlayData = BottomAlignedPosition & {
68+ width : number ;
69+ height : number ;
70+ } ;
71+
6772export class ShellWindow {
6873 public static getInstance ( ) : ShellWindow | undefined {
6974 return this . instance ;
@@ -74,7 +79,7 @@ export class ShellWindow {
7479 public readonly chatView : WebContentsView ;
7580 private readonly overlayWebContentsViews : Map <
7681 WebContentsView ,
77- BottomAlignedPosition
82+ OverlayData
7883 > = new Map ( ) ;
7984
8085 private verticalLayout : boolean ;
@@ -106,34 +111,67 @@ export class ShellWindow {
106111 return activeBrowserView . webContentsView ;
107112 }
108113
114+ private updateOverlayWebContentsViewBounds ( ) {
115+ for ( const [ view , data ] of this . overlayWebContentsViews . entries ( ) ) {
116+ this . setOverlayWebContentsViewBounds ( view , data ) ;
117+ }
118+ }
119+
109120 private setOverlayWebContentsViewBounds (
110121 view : WebContentsView ,
111- position : BottomAlignedPosition ,
122+ data : OverlayData ,
112123 ) {
113124 const chatBounds = this . chatView . getBounds ( ) ;
114- const current = view . getBounds ( ) ;
115125 const zoomFactor = this . chatView . webContents . zoomFactor ;
116- const left = chatBounds . x + position . left * zoomFactor ;
117- const bottom = chatBounds . y + position . bottom * zoomFactor ;
118-
126+ const left = chatBounds . x + data . left * zoomFactor ;
127+ const bottom =
128+ chatBounds . y + chatBounds . height - data . bottom * zoomFactor ;
129+ const width = data . width * zoomFactor ;
130+ const height = data . height * zoomFactor ;
119131 const newBounds = {
120132 x : left ,
121- y : bottom - current . height ,
122- width : current . width ,
123- height : current . height ,
133+ y : bottom - height ,
134+ width,
135+ height,
124136 } ;
125- view . webContents . setZoomFactor ( zoomFactor ) ;
126137 view . setBounds ( newBounds ) ;
138+ view . webContents . setZoomFactor ( zoomFactor ) ;
127139 }
128140
129141 public updateOverlayWebContentsView (
130142 view : WebContentsView ,
131- position ?: BottomAlignedPosition ,
143+ update ?: Partial < OverlayData > ,
132144 ) {
133- if ( position ) {
134- this . overlayWebContentsViews . set ( view , position ) ;
135- this . mainWindow . contentView . addChildView ( view ) ;
136- this . setOverlayWebContentsViewBounds ( view , position ) ;
145+ if ( update ) {
146+ let data = this . overlayWebContentsViews . get ( view ) ;
147+ if ( data === undefined ) {
148+ this . mainWindow . contentView . addChildView ( view ) ;
149+ const bounds = view . getBounds ( ) ;
150+ data = {
151+ left : 0 ,
152+ bottom : 0 ,
153+ width : bounds . width ,
154+ height : bounds . height ,
155+ } ;
156+
157+ this . overlayWebContentsViews . set ( view , data ) ;
158+ }
159+
160+ if ( update . left ) {
161+ data . left = update . left ;
162+ }
163+ if ( update . bottom ) {
164+ data . bottom = update . bottom ;
165+ }
166+
167+ if ( update . width ) {
168+ data . width = update . width ;
169+ }
170+ if ( update . height ) {
171+ data . height = update . height ;
172+ }
173+
174+ this . setOverlayWebContentsViewBounds ( view , data ) ;
137175 } else {
138176 this . overlayWebContentsViews . delete ( view ) ;
139177 this . mainWindow . contentView . removeChildView ( view ) ;
@@ -212,6 +250,7 @@ export class ShellWindow {
212250
213251 const chatView = createChatView ( state ) ;
214252 this . setupZoomHandlers ( chatView . webContents , ( zoomFactor ) => {
253+ this . updateOverlayWebContentsViewBounds ( ) ;
215254 this . updateZoomInTitle ( zoomFactor ) ;
216255 } ) ;
217256
@@ -600,9 +639,7 @@ export class ShellWindow {
600639 debugShellWindow ( `Chat view bounds: ${ JSON . stringify ( chatViewBounds ) } ` ) ;
601640 this . chatView . setBounds ( chatViewBounds ) ;
602641
603- for ( const [ view , position ] of this . overlayWebContentsViews . entries ( ) ) {
604- this . setOverlayWebContentsViewBounds ( view , position ) ;
605- }
642+ this . updateOverlayWebContentsViewBounds ( ) ;
606643
607644 const dividerLayout = {
608645 verticalLayout,
@@ -1041,10 +1078,10 @@ export class ShellWindow {
10411078 onZoomChanged ?: ( zoomFactor : number ) => void ,
10421079 ) {
10431080 // limit zoom factor to reasonable numbers
1044- if ( zoomFactor < 0.1 ) {
1045- zoomFactor = 0.1 ;
1046- } else if ( zoomFactor > 10 ) {
1047- zoomFactor = 10 ;
1081+ if ( zoomFactor < 0.25 ) {
1082+ zoomFactor = 0.25 ;
1083+ } else if ( zoomFactor > 5 ) {
1084+ zoomFactor = 5 ;
10481085 }
10491086
10501087 webContents . zoomFactor = zoomFactor ;
0 commit comments