Electron window resize event


#1

Hello,

I’ve a problem with resizing event. I wish to attach my custom listener which would update my three.js canvas whenever the main window size will change. I was trying to use global window object and add my custom listener in traditional way:

document.addEventListener('resize', onWindowResize(), false);

But it dosen’t seem to work.


#2

What if you attach your event listener to the window object instead of document?


#3

The same, dosen’t matter it’s a window object or document the resolut from this is the same.

but anyway i’ve solved a problem just second a go using debounce method from loadash:

    let currentWindow = remote.getCurrentWindow().removeAllListeners();
    
    currentWindow.on('resize', _.debounce(function () {
      that.onWindowResize();
    }, 100));

If you know better solution then this i’d appricicate.


#4

Unless your onWindowResize function returns a function that is meant to handle the resize event that code doesn’t actually do what you think it does.


#5

You’re totally right. My onWindowResize() function isn’t an actual handler for my event, it’s just a function statement. Adding first class function has solve the problem with running my function. Here is modified code:

    window.addEventListener('resize', function(e){
      e.preventDefault();
      that.onWindowResize();
    })

Thank you for your help guys!