Skip to content

Commit 89ab12a

Browse files
feat: added windows.onBoundsChanged() (#133)
* feat: add on bounds changed * fix: use `createWindowDetails` to fix caching issue Co-authored-by: Sam Maddock <[email protected]> --------- Co-authored-by: Sam Maddock <[email protected]>
1 parent 893bc62 commit 89ab12a

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

packages/electron-chrome-extensions/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ See [Electron's Notification tutorial](https://www.electronjs.org/docs/tutorial/
448448
- [x] chrome.windows.onCreated
449449
- [x] chrome.windows.onRemoved
450450
- [x] chrome.windows.onFocusChanged
451-
- [ ] chrome.windows.onBoundsChanged
451+
- [x] chrome.windows.onBoundsChanged
452452
</details>
453453

454454
## Limitations

packages/electron-chrome-extensions/src/browser/api/windows.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ export class WindowsAPI {
3636
this.onFocusChanged(windowId)
3737
})
3838

39+
window.on('resized', () => {
40+
this.onBoundsChanged(windowId)
41+
})
42+
3943
window.once('closed', () => {
4044
this.ctx.store.windowDetailsCache.delete(windowId)
4145
this.ctx.store.removeWindow(window)
@@ -164,4 +168,11 @@ export class WindowsAPI {
164168
this.ctx.store.lastFocusedWindowId = windowId
165169
this.ctx.router.broadcastEvent('windows.onFocusChanged', windowId)
166170
}
171+
172+
onBoundsChanged(windowId: number) {
173+
const window = this.ctx.store.getWindowById(windowId)
174+
if (!window) return
175+
const windowDetails = this.createWindowDetails(window)
176+
this.ctx.router.broadcastEvent('windows.onBoundsChanged', windowDetails)
177+
}
167178
}

packages/electron-chrome-extensions/src/renderer/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ export const injectExtensionAPIs = () => {
636636
onCreated: new ExtensionEvent('windows.onCreated'),
637637
onRemoved: new ExtensionEvent('windows.onRemoved'),
638638
onFocusChanged: new ExtensionEvent('windows.onFocusChanged'),
639+
onBoundsChanged: new ExtensionEvent('windows.onBoundsChanged'),
639640
}
640641
},
641642
},

0 commit comments

Comments
 (0)