asticode / astilectron

Electron app that provides an API over a TCP socket that allows executing Electron's method as well as capturing Electron's events
MIT License
285 stars 67 forks source link

Return updated bounds on change #55

Closed maddie closed 2 years ago

maddie commented 2 years ago

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).

asticode commented 2 years ago

Why do you need to get bounds from electron, isn't it something that is known in GO directly ? 🤔

maddie commented 2 years ago

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.

asticode commented 2 years ago

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 ?

maddie commented 2 years ago

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?

asticode commented 2 years ago

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 😭 )

maddie commented 2 years ago

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:

asticode commented 2 years ago

Exactly. And you should also make sure that current methods that apply changes to bounds (like Resize, ...), actually update internal options references.

maddie commented 2 years ago

Okay, let me take a shot at this.

maddie commented 2 years ago

Tested and pushed both here and go-astilectron

maddie commented 2 years ago

Could you add bounds here as well so that we get proper bounds when the window is created centered for instance ?

Done

asticode commented 2 years ago

fyi I've created a v0.53.0 tag

maddie commented 2 years ago

Thanks, I'll update the dependent version in go-astilectron soon.