Closed maddie closed 2 years ago
Why do you need to get bounds
from electron
, isn't it something that is known in GO directly ? 🤔
I didn't find a way to get bounds in Go, can you give me some pointers?
In my use case, I need to get the bounds of the main window when the window is being moved (or moved in place), and pass the X Y values to another program. I tried to read from value directly from the window
object, but it didn't expose the WindowOption
within, and even if I read it by modifying go-astilectron
code, the X Y always returned nothing (nil pointers). The event returned by electron's move
doesn't contain the X Y values, so I added this function.
Thing is, go-astilectron
keeps window options internally. You could create a Window.Bounds()
method that would return w.o.Bounds
as a Rectangle
and that would fix your problem. The more difficult part would be to keep the internal options up to date, since you would need to return from JS the proper bounds attributes everytime a method that creates/moves/resizes a window is called. Does that make sense ?
Yes, that makes sense, and that's what I was gonna do at first, but then find out it gets complicated pretty quickly, so I instead opted to implement it this way.
I know the window options are internal, maybe I'll take some time to look at the code more closely to see if there's a better way to implement this.
And a question: if I update the bounds (x, y, width, height) in the internal window options, will it affect the window (resize or reposition it), or they're there just for reference?
if I update the bounds (x, y, width, height) in the internal window options, will it affect the window (resize or reposition it), or they're there just for reference?
They're just a reference, and the promise is that they're always up to date (which is not really true in reality right now 😠)
if I update the bounds (x, y, width, height) in the internal window options, will it affect the window (resize or reposition it), or they're there just for reference?
They're just a reference, and the promise is that they're always up to date (which is not really true in reality right now 😠)
🤣
So if I'm gonna implement it this way, it would be instead of adding the commands:
windowCreateFinish
, all the events that might affect the Bounds
should call getBounds()
on the object (which is elements[json.targetID]
), and write the payload (bounds) back to the Go sidewindow.go
's newWindow
function, and update the Bounds
within the window optionsBounds()
to return the internal Bounds
attributeExactly. And you should also make sure that current methods that apply changes to bounds (like Resize
, ...), actually update internal options references.
Okay, let me take a shot at this.
Tested and pushed both here and go-astilectron
Could you add
bounds
here as well so that we get proper bounds when the window is created centered for instance ?
Done
fyi I've created a v0.53.0
tag
Thanks, I'll update the dependent version in go-astilectron
soon.
With the implemented event listener and command, users can now obtain the current window's position and size (or other objects I presume, if add support to code).