1
+ import os from 'os' ;
1
2
import Electron , { BrowserWindow , app , shell } from 'electron' ;
2
3
import _ from 'lodash' ;
3
4
@@ -110,6 +111,32 @@ export function openPreferences() {
110
111
app . dock ?. show ( ) ;
111
112
}
112
113
114
+ /**
115
+ * Attempts to resize and center window on parent or screen
116
+ * @param window Electron Browser Window that needs to be resized
117
+ * @param width Width of the browser window
118
+ * @param height Height of the browser window
119
+ */
120
+ function resizeWindow ( window : Electron . BrowserWindow , width : number , height : number ) : void {
121
+ const parent = window . getParentWindow ( ) ;
122
+
123
+ if ( ! parent ) {
124
+ window . center ( ) ;
125
+ window . setContentSize ( width , height ) ;
126
+
127
+ return ;
128
+ }
129
+
130
+ const { x : prefX , y : prefY , width : prefWidth } = parent . getBounds ( ) ;
131
+ const centered = prefX + Math . round ( ( prefWidth / 2 ) - ( width / 2 ) ) ;
132
+
133
+ window . setContentBounds (
134
+ {
135
+ x : centered , y : prefY , width, height
136
+ }
137
+ ) ;
138
+ }
139
+
113
140
/**
114
141
* Internal helper function to open a given modal dialog.
115
142
*
@@ -126,8 +153,9 @@ function openDialog(id: string, opts?: Electron.BrowserWindowConstructorOptions)
126
153
{
127
154
autoHideMenuBar : ! app . isPackaged ,
128
155
show : false ,
129
- useContentSize : true ,
130
156
modal : true ,
157
+ resizable : false ,
158
+ frame : ! ( os . platform ( ) === 'linux' ) ,
131
159
...opts ?? { } ,
132
160
webPreferences : {
133
161
devTools : ! app . isPackaged ,
@@ -139,35 +167,18 @@ function openDialog(id: string, opts?: Electron.BrowserWindowConstructorOptions)
139
167
}
140
168
) ;
141
169
142
- let windowState : 'hidden' | 'shown' | 'sized' = 'hidden' ;
143
-
144
170
window . menuBarVisible = false ;
145
171
146
- window . webContents . on ( 'ipc-message' , ( event , channel ) => {
147
- if ( channel === 'dialog/ready' ) {
148
- window . show ( ) ;
149
- windowState = 'shown' ;
150
- }
151
- } ) ;
152
-
153
172
window . webContents . on ( 'preferred-size-changed' , ( _event , { width, height } ) => {
154
- window . webContents . send ( 'dialog/size' , { width , height } ) ;
155
- if ( windowState === 'sized' ) {
156
- // Once the window is done sizing, don't do any more automatic resizing.
157
- return ;
173
+ if ( os . platform ( ) === 'linux' ) {
174
+ resizeWindow ( window , width , height ) ;
175
+ } else {
176
+ window . setContentSize ( width , height , true ) ;
158
177
}
159
- window . setMinimumSize ( width , height ) ;
160
- window . setContentSize ( width , height ) ;
161
-
162
- const [ windowWidth , windowHeight ] = window . getSize ( ) ;
163
178
164
- window . setMinimumSize ( windowWidth , windowHeight ) ;
165
- if ( windowState === 'shown' ) {
166
- // We get a few resizes in a row until things settle down; use a timeout
167
- // to let things stablize before we stop responding resize events.
168
- setTimeout ( ( ) => {
169
- windowState = 'sized' ;
170
- } , 100 ) ;
179
+ if ( ! window . isVisible ( ) ) {
180
+ window . show ( ) ;
181
+ window . focus ( ) ;
171
182
}
172
183
} ) ;
173
184
@@ -179,7 +190,7 @@ function openDialog(id: string, opts?: Electron.BrowserWindowConstructorOptions)
179
190
* configuration required.
180
191
*/
181
192
export async function openFirstRun ( ) {
182
- const window = openDialog ( 'FirstRun' ) ;
193
+ const window = openDialog ( 'FirstRun' , { frame : true } ) ;
183
194
184
195
await ( new Promise < void > ( ( resolve ) => {
185
196
window . on ( 'closed' , resolve ) ;
@@ -195,6 +206,7 @@ export async function openKubernetesErrorMessageWindow(titlePart: string, mainMe
195
206
width : 800 ,
196
207
height : 494 ,
197
208
parent : getWindow ( 'preferences' ) ?? undefined ,
209
+ frame : true ,
198
210
} ) ;
199
211
200
212
window . webContents . on ( 'ipc-message' , ( event , channel ) => {
@@ -257,10 +269,6 @@ export async function openLegacyIntegrations(): Promise<void> {
257
269
'LegacyIntegrationNotification' ,
258
270
{
259
271
title : 'Rancher Desktop - Legacy Integrations' ,
260
- frame : true ,
261
- width : 500 ,
262
- height : 240 ,
263
- webPreferences : { enablePreferredSizeMode : false } ,
264
272
parent : getWindow ( 'preferences' ) ?? undefined ,
265
273
}
266
274
) ;
0 commit comments