Skip to content

Commit ca08003

Browse files
committed
fix: stop the window resizing itself out of control
This was the crash. The window sized itself to the device proportions by reading innerSize() — physical pixels — and writing it back as a LogicalSize. On a Retina display those differ by the scale factor, so every run through doubled the window: 470 wide became 940, then 1880, until the frame filled the screen and the editor was left rendering into a window several times its size, showing nothing but background. The calculation is gone rather than corrected. The device already holds its own aspect ratio whatever the window does, so a window that does not exactly match letterboxes it — which is all the resize was ever avoiding, at the price of fighting the user's own window size.
1 parent a990789 commit ca08003

2 files changed

Lines changed: 2 additions & 23 deletions

File tree

app/src/app.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { LogicalSize, getCurrentWindow } from '@tauri-apps/api/window'
1+
import { getCurrentWindow } from '@tauri-apps/api/window'
22
import { Toaster } from 'sonner'
33
import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react'
44

5-
import { deviceAspect, limitsFrom, windowHeightFor } from './features/editor/editor.constants'
5+
import { deviceAspect, limitsFrom } from './features/editor/editor.constants'
66
import { editorReducer, initialEditorState, toIconState } from './features/editor/editor.reducer'
77
import HomeEditor from './features/editor/home-editor'
88
import DiffReview from './features/diff-review/diff-review'
@@ -202,20 +202,6 @@ export default function App() {
202202
getCurrentWindow().setTitle(device ? `${device}${system}` : 'IconState')
203203
}, [device, system])
204204

205-
useEffect(() => {
206-
if (!metrics) return
207-
const window_ = getCurrentWindow()
208-
window_.innerSize().then(async size => {
209-
const factor = await window_.scaleFactor()
210-
const logical = size.toLogical(factor)
211-
const width = Math.round(logical.width)
212-
const wanted = windowHeightFor(metrics, width)
213-
if (Math.abs(wanted - Math.round(logical.height)) > 2) {
214-
await window_.setSize(new LogicalSize(width, wanted))
215-
}
216-
})
217-
}, [metrics])
218-
219205
return (
220206
<>
221207
<HomeEditor

app/src/features/editor/editor.constants.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,8 @@ export const limitsFrom = (metrics: Metrics | null): Limits => {
6464
}
6565
}
6666

67-
/** Padding around the device inside the window. */
68-
const OUTER = 10 * 2
69-
7067
export const deviceAspect = (metrics: Metrics | null): number => {
7168
const width = metrics?.homeScreenWidth ?? 440
7269
const height = metrics?.homeScreenHeight ?? 956
7370
return width / height
7471
}
75-
76-
/** Window height that leaves no letterboxing around the device. */
77-
export const windowHeightFor = (metrics: Metrics | null, width: number) =>
78-
Math.round((width - OUTER) / deviceAspect(metrics)) + OUTER

0 commit comments

Comments
 (0)