Skip to content

Commit b0cd59d

Browse files
committed
Another bandaid for window size restoration on linux
1 parent a69ccb2 commit b0cd59d

1 file changed

Lines changed: 37 additions & 17 deletions

File tree

src/index.tsx

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,29 +134,49 @@ async function run(config: Config) {
134134

135135
if (TAURI) {
136136
setupTauriEvents(config, app);
137+
137138
if (config.values.app.showTrayIcon) {
138139
void invoke("create_tray");
139140
}
140-
} else {
141-
setupWebEvents(config);
142-
}
143141

144-
const size = config.values.app.window.size;
145-
if (size.length === 2 && size[0] > 100 && size[1] > 100) {
146-
await appWindow.setSize(size);
147-
const sz = await appWindow.getSize();
148-
const delta = [sz.width - size[0], sz.height - size[1]];
149-
if (delta[0] != 0 || delta[1] != 0) {
150-
console.log("Window size delta", delta);
151-
await appWindow.setSize([size[0] - delta[0], size[1] - delta[1]]);
142+
const positionWindow = async function () {
143+
const pos = config.values.app.window.position;
144+
if (pos?.length === 2 && pos?.[0] > -32000 && pos?.[1] > -32000) {
145+
await appWindow.setPosition(pos);
146+
} else {
147+
await appWindow.center();
148+
}
149+
};
150+
151+
const sizeCheck = async function () {
152+
const sz = await appWindow.getSize();
153+
const delta = [sz.width - size[0], sz.height - size[1]];
154+
if (delta[0] != 0 || delta[1] != 0) {
155+
console.log("Window size delta", delta);
156+
await appWindow.setSize([size[0] - delta[0], size[1] - delta[1]]);
157+
}
158+
};
159+
160+
const sleep20ms = async function () {
161+
await new Promise<void>((r) => setTimeout(r, 20));
162+
};
163+
164+
const size = config.values.app.window.size;
165+
166+
if (size.length === 2 && size[0] > 100 && size[1] > 100) {
167+
await appWindow.setSize(size);
168+
169+
// Run the size verification a bit later to allow the window system to apply the size
170+
// (on some platforms the immediate getSize() after setSize() returns the old value).
171+
void sleep20ms()
172+
.then(sizeCheck)
173+
.then(sleep20ms)
174+
.then(positionWindow);
175+
} else {
176+
void positionWindow();
152177
}
153-
}
154-
155-
const pos = config.values.app.window.position;
156-
if (pos?.length === 2 && pos?.[0] > -32000 && pos?.[1] > -32000) {
157-
await appWindow.setPosition(pos);
158178
} else {
159-
await appWindow.center();
179+
setupWebEvents(config);
160180
}
161181

162182
app.render(

0 commit comments

Comments
 (0)