@@ -21,7 +21,7 @@ export interface DragOptions {
2121 /** Enable double-click to maximize/unmaximize. */
2222 maximize ?: boolean ;
2323 /** Frames per second for drag updates. Default: Screen refresh rate */
24- fps ?: number ;
24+ fps ?: number | null ;
2525 /** If true, auto-attach the window's webContents on initialization. Default: true */
2626 attachOnInit ?: boolean ;
2727
@@ -110,6 +110,7 @@ export class Draggable {
110110 private constructor ( window : DraggableWindow , options : DragOptions = { } ) {
111111 this . setWindow ( window ) ;
112112 this . options = options ;
113+ if ( options . fps === undefined ) { options . fps = null }
113114 Draggable . normalizeOptions ( this . options ) ;
114115
115116 // Auto-attach for BrowserWindow (has its own webContents)
@@ -346,17 +347,18 @@ export class Draggable {
346347 private static normalizeOptions ( options : InternalDragOptions ) : void {
347348 if ( options . selector ) { options . selector = JSON . stringify ( options . selector ) ; }
348349 if ( options . exclude ) { options . exclude = JSON . stringify ( options . exclude ) ; }
349- if ( ! options . fps || options . fps < 0 ) {
350- try {
350+ if ( options . fps === null || ( options . fps && options . fps < 0 ) ) { options . fps = Draggable . getDefaultFps ( ) ; }
351+ if ( options . fps !== undefined ) { options . intervalDelay = Math . floor ( 1000 / options . fps ) ; }
352+ }
353+
354+ private static getDefaultFps ( ) : number {
355+ try {
351356 const refreshRate = screen . getAllDisplays ( ) . reduce ( ( max , d ) => Math . max ( max , d . displayFrequency ) , 0 ) ;
352- options . fps = refreshRate ;
357+ return refreshRate ;
353358 } catch ( e ) {
354359 console . warn ( 'Failed to get display refresh rate, defaulting to 60fps' , e ) ;
355- } finally {
356- options . fps = options . fps || 60 ;
360+ return 60 ;
357361 }
358- }
359- options . intervalDelay = Math . floor ( 1000 / options . fps ) ;
360362 }
361363
362364 private static closest ( webContents : WebContents , p : Point , selector : string , negate ?: true ) : Promise < boolean > {
0 commit comments