Skip to content

Commit b65193d

Browse files
authored
Merge pull request #2082 from rak-phillip/bugfix/auto-size-dialog
Make auto-sizing dialogs more consistent
2 parents 9aa5f67 + 9535f75 commit b65193d

File tree

5 files changed

+67
-66
lines changed

5 files changed

+67
-66
lines changed

src/layouts/dialog.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,8 @@ export default Vue.extend({
4747
html {
4848
height: initial;
4949
}
50-
:root[data-flex~="width"] #__layout > .wrapper[data-loaded] {
51-
width: 100vw;
52-
}
53-
:root[data-flex~="height"] #__layout > .wrapper[data-loaded] {
54-
height: 100vh;
50+
body {
51+
overflow: hidden;
5552
}
5653
</style>
5754

src/pages/KubernetesError.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div>
2+
<div class="container">
33
<div class="page-body">
44
<div class="error-header">
55
<img id="logo" src="../../resources/icons/[email protected]" />
@@ -94,6 +94,10 @@ export default Vue.extend({
9494
</script>
9595

9696
<style lang="scss" scoped>
97+
.container {
98+
min-width: 52rem;
99+
}
100+
97101
.error-header {
98102
display: flex;
99103
gap: 0.75rem;

src/pages/LegacyIntegrationNotification.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ipcRenderer } from 'electron';
44
import paths from '@/utils/paths';
55
66
export default Vue.extend({
7-
layout: 'dialog',
7+
layout: 'dialog',
88
computed: {
99
oldIntegrationPath() {
1010
return paths.oldIntegration;
@@ -22,7 +22,7 @@ export default Vue.extend({
2222
</script>
2323

2424
<template>
25-
<div>
25+
<div class="container">
2626
<h3>{{ t('legacyIntegrations.title') }}</h3>
2727
<p>
2828
{{ t('legacyIntegrations.messageFirstPart') }}
@@ -50,9 +50,19 @@ export default Vue.extend({
5050
</template>
5151

5252
<style lang="scss" scoped>
53+
.container {
54+
min-width: 32rem;
55+
}
56+
5357
.button-area {
5458
align-self: flex-end;
5559
}
60+
61+
summary {
62+
user-select: none;
63+
cursor: pointer;
64+
}
65+
5666
code {
5767
user-select: text;
5868
cursor: text;

src/pages/SudoPrompt.vue

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ export default Vue.extend({
7575
};
7676
},
7777
mounted() {
78-
ipcRenderer.on('dialog/size', (event, size: {width: number, height: number}) => {
79-
this.checkSize(size);
80-
});
8178
ipcRenderer.on('dialog/populate', (event, explanations: Partial<Record<SudoReason, string[]>>) => {
8279
this.explanations = explanations;
8380
});
@@ -87,31 +84,6 @@ export default Vue.extend({
8784
(this.$refs.accept as HTMLButtonElement)?.focus();
8885
},
8986
methods: {
90-
/**
91-
* checkSize is triggered when the window's preferred size changes; we use
92-
* this in response to the user opening one of the <details> disclosures to
93-
* ensure the whole text is visible.
94-
*/
95-
checkSize(size: {width: number, height: number}) {
96-
if (!this.sized) {
97-
// Initial window layout isn't done yet, don't do any sizing.
98-
// Check the window size again (in a timeout) to give the window time to
99-
// change sizes.
100-
setTimeout(() => {
101-
this.sized ||= size.width === window.outerWidth && size.height === window.outerHeight;
102-
}, 0);
103-
104-
return;
105-
}
106-
107-
// Because increasing the width can reduce the height requirement, we
108-
// should do the resizing in two steps to get the minimum size.
109-
if (size.width > window.outerWidth) {
110-
window.resizeTo(size.width, window.outerHeight);
111-
} else if (size.height > window.outerHeight) {
112-
window.resizeTo(window.outerWidth, size.height);
113-
}
114-
},
11587
close() {
11688
// Manually send the result, because we won't get an event here.
11789
ipcRenderer.send('sudo-prompt/closed', this.suppress);
@@ -131,20 +103,30 @@ export default Vue.extend({
131103
.contents {
132104
padding: 2em;
133105
}
106+
107+
summary {
108+
user-select: none;
109+
cursor: pointer;
110+
}
111+
134112
li, p {
135113
margin: 0.5em;
136114
}
115+
137116
ul.reasons {
138117
list-style-type: none;
139118
padding-left: 0;
140119
}
120+
141121
li.monospace {
142122
/* font-family is set in _typography.scss */
143123
white-space: pre;
144124
}
125+
145126
#suppress {
146127
margin: 1em;
147128
}
129+
148130
.primary-action {
149131
align-self: flex-end;
150132
}

src/window/index.ts

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os from 'os';
12
import Electron, { BrowserWindow, app, shell } from 'electron';
23
import _ from 'lodash';
34

@@ -110,6 +111,32 @@ export function openPreferences() {
110111
app.dock?.show();
111112
}
112113

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+
113140
/**
114141
* Internal helper function to open a given modal dialog.
115142
*
@@ -126,8 +153,9 @@ function openDialog(id: string, opts?: Electron.BrowserWindowConstructorOptions)
126153
{
127154
autoHideMenuBar: !app.isPackaged,
128155
show: false,
129-
useContentSize: true,
130156
modal: true,
157+
resizable: false,
158+
frame: !(os.platform() === 'linux'),
131159
...opts ?? {},
132160
webPreferences: {
133161
devTools: !app.isPackaged,
@@ -139,35 +167,18 @@ function openDialog(id: string, opts?: Electron.BrowserWindowConstructorOptions)
139167
}
140168
);
141169

142-
let windowState: 'hidden' | 'shown' | 'sized' = 'hidden';
143-
144170
window.menuBarVisible = false;
145171

146-
window.webContents.on('ipc-message', (event, channel) => {
147-
if (channel === 'dialog/ready') {
148-
window.show();
149-
windowState = 'shown';
150-
}
151-
});
152-
153172
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);
158177
}
159-
window.setMinimumSize(width, height);
160-
window.setContentSize(width, height);
161-
162-
const [windowWidth, windowHeight] = window.getSize();
163178

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();
171182
}
172183
});
173184

@@ -179,7 +190,7 @@ function openDialog(id: string, opts?: Electron.BrowserWindowConstructorOptions)
179190
* configuration required.
180191
*/
181192
export async function openFirstRun() {
182-
const window = openDialog('FirstRun');
193+
const window = openDialog('FirstRun', { frame: true });
183194

184195
await (new Promise<void>((resolve) => {
185196
window.on('closed', resolve);
@@ -195,6 +206,7 @@ export async function openKubernetesErrorMessageWindow(titlePart: string, mainMe
195206
width: 800,
196207
height: 494,
197208
parent: getWindow('preferences') ?? undefined,
209+
frame: true,
198210
});
199211

200212
window.webContents.on('ipc-message', (event, channel) => {
@@ -257,10 +269,6 @@ export async function openLegacyIntegrations(): Promise<void> {
257269
'LegacyIntegrationNotification',
258270
{
259271
title: 'Rancher Desktop - Legacy Integrations',
260-
frame: true,
261-
width: 500,
262-
height: 240,
263-
webPreferences: { enablePreferredSizeMode: false },
264272
parent: getWindow('preferences') ?? undefined,
265273
}
266274
);

0 commit comments

Comments
 (0)