@@ -166,15 +166,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
166166
167167 // Initialize the Settings Window
168168 settingsWindow = NSWindow (
169- contentRect: NSRect ( x: 0 , y: 0 , width: 246 , height: 870 ) ,
169+ contentRect: NSRect ( x: 0 , y: 0 , width: 246 , height: 300 ) ,
170170 styleMask: [ . titled, . closable, . miniaturizable, . resizable] ,
171171 backing: . buffered,
172172 defer: false
173173 )
174174 settingsWindow. setValue ( " SettingsWindow3 " , forKey: " frameAutosaveName " )
175175 settingsWindow. delegate = self
176176 settingsWindow. minSize = NSSize ( width: 246 , height: 300 )
177- settingsWindow. maxSize = NSSize ( width: 246 , height: 870 )
178177 let visualEffect = NSVisualEffectView ( )
179178 visualEffect. material = . hudWindow
180179 visualEffect. blendingMode = . behindWindow
@@ -220,6 +219,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
220219 hostingView. trailingAnchor. constraint ( equalTo: visualEffect. trailingAnchor) ,
221220 ] )
222221
222+ // Compute max height dynamically from the SwiftUI content's intrinsic size
223+ // so we never need to hardcode a pixel value when settings are added/removed.
224+ let fittingSize = hostingView. fittingSize
225+ let titleBarHeight : CGFloat = 28
226+ let idealHeight = ceil ( fittingSize. height + titleBarHeight)
227+ settingsWindow. maxSize = NSSize ( width: 246 , height: idealHeight)
228+ settingsWindow. setContentSize ( NSSize ( width: 246 , height: fittingSize. height) )
229+
223230 settingsWindow. title = " exhale "
224231 toggleSettings ( nil )
225232 setUpStatusItem ( )
@@ -442,7 +449,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
442449 x: screenOrigin. x + x,
443450 y: screenOrigin. y + y,
444451 width: min ( w, 246 ) ,
445- height: min ( h, 870 )
452+ height: min ( h, settingsWindow . maxSize . height )
446453 )
447454 settingsWindow. setFrame ( restoredFrame, display: true )
448455 }
0 commit comments