mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-04-21 21:50:31 +00:00
BrowserWindow: Add OnBoundsChanged event
While not being an original Electron event, this one includes the bounds values, saving the additional roundtrip for calling GetBoundsAsync
This commit is contained in:
@@ -186,6 +186,19 @@ public class BrowserWindow : ApiBase
|
||||
remove => RemoveEvent(value, Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when the window is moved or resized.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// While not being an original Electron event, this one includes the bounds values,
|
||||
/// saving the additional roundtrip for calling <see cref="GetBoundsAsync"/>.
|
||||
/// </remarks>
|
||||
public event Action<Rectangle> OnBoundsChanged
|
||||
{
|
||||
add => AddEvent(value, Id);
|
||||
remove => RemoveEvent(value, Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// macOS: Emitted once when the window is moved to a new position.
|
||||
/// </summary>
|
||||
|
||||
@@ -112,6 +112,12 @@ module.exports = (socket, app) => {
|
||||
electronSocket.emit("browserWindow-move" + id);
|
||||
});
|
||||
});
|
||||
socket.on("register-browserWindow-bounds-changed", (id) => {
|
||||
const window = getWindowById(id);
|
||||
const cb = () => electronSocket.emit("browserWindow-bounds-changed" + id, window.getBounds());
|
||||
window.on("resize", cb);
|
||||
window.on("move", cb);
|
||||
});
|
||||
socket.on("register-browserWindow-moved", (id) => {
|
||||
getWindowById(id).on("moved", () => {
|
||||
electronSocket.emit("browserWindow-moved" + id);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -139,6 +139,13 @@ export = (socket: Socket, app: Electron.App) => {
|
||||
});
|
||||
});
|
||||
|
||||
socket.on("register-browserWindow-bounds-changed", (id) => {
|
||||
const window = getWindowById(id);
|
||||
const cb = () => electronSocket.emit("browserWindow-bounds-changed" + id, window.getBounds());
|
||||
window.on("resize", cb);
|
||||
window.on("move", cb);
|
||||
});
|
||||
|
||||
socket.on("register-browserWindow-moved", (id) => {
|
||||
getWindowById(id).on("moved", () => {
|
||||
electronSocket.emit("browserWindow-moved" + id);
|
||||
|
||||
Reference in New Issue
Block a user