@@ -142,44 +142,22 @@ function getWindowOptions() {
142142}
143143
144144/**
145- * Track window state changes and save on close.
145+ * Track window state and save on close.
146146 * Call this after creating the BrowserWindow.
147147 */
148148function trackWindowState ( win ) {
149- let windowState = {
150- width : DEFAULTS . width ,
151- height : DEFAULTS . height ,
152- x : undefined ,
153- y : undefined ,
154- isMaximized : false
155- } ;
156-
157- // Update state from current window bounds
158- function updateState ( ) {
159- if ( ! win . isMaximized ( ) && ! win . isMinimized ( ) && ! win . isFullScreen ( ) ) {
160- const bounds = win . getBounds ( ) ;
161- windowState . width = bounds . width ;
162- windowState . height = bounds . height ;
163- windowState . x = bounds . x ;
164- windowState . y = bounds . y ;
165- }
166- windowState . isMaximized = win . isMaximized ( ) ;
167- }
168-
169- // Listen for state changes
170- win . on ( 'resize' , updateState ) ;
171- win . on ( 'move' , updateState ) ;
172- win . on ( 'maximize' , updateState ) ;
173- win . on ( 'unmaximize' , updateState ) ;
174-
175- // Save state before window closes
176149 win . on ( 'close' , ( ) => {
177- updateState ( ) ;
150+ // getNormalBounds() returns the non-maximized bounds even when maximized
151+ const bounds = win . getNormalBounds ( ) ;
152+ const windowState = {
153+ width : bounds . width ,
154+ height : bounds . height ,
155+ x : bounds . x ,
156+ y : bounds . y ,
157+ isMaximized : win . isMaximized ( )
158+ } ;
178159 saveWindowState ( windowState ) ;
179160 } ) ;
180-
181- // Initialize state
182- updateState ( ) ;
183161}
184162
185163module . exports = {
0 commit comments