Skip to content

Commit b779650

Browse files
committed
feat: emit some events on PopupView
1 parent 331dc5f commit b779650

File tree

1 file changed

+18
-7
lines changed
  • packages/electron-chrome-extensions/src/browser

1 file changed

+18
-7
lines changed

packages/electron-chrome-extensions/src/browser/popup.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { EventEmitter } from 'node:events'
12
import { BrowserWindow, Session } from 'electron'
23
import { getAllWindows } from './api/common'
34
import debug from 'debug'
@@ -25,7 +26,7 @@ const supportsPreferredSize = () => {
2526
return major >= 12
2627
}
2728

28-
export class PopupView {
29+
export class PopupView extends EventEmitter {
2930
static POSITION_PADDING = 5
3031

3132
static BOUNDS = {
@@ -50,6 +51,8 @@ export class PopupView {
5051
private readyPromise: Promise<void>
5152

5253
constructor(opts: PopupViewOptions) {
54+
super()
55+
5356
this.parent = opts.parent
5457
this.extensionId = opts.extensionId
5558
this.anchorRect = opts.anchorRect
@@ -173,13 +176,17 @@ export class PopupView {
173176
Math.min(PopupView.BOUNDS.maxHeight, Math.max(rect.height || 0, PopupView.BOUNDS.minHeight)),
174177
)
175178

176-
d(`setSize`, { width, height })
179+
const size = { width, height }
180+
d(`setSize`, size)
181+
182+
this.emit('will-resize', size)
177183

178184
this.browserWindow?.setBounds({
179185
...this.browserWindow.getBounds(),
180-
width,
181-
height,
186+
...size,
182187
})
188+
189+
this.emit('resized')
183190
}
184191

185192
private maybeClose = () => {
@@ -231,13 +238,17 @@ export class PopupView {
231238
x = Math.floor(x)
232239
y = Math.floor(y)
233240

234-
d(`updatePosition`, { x, y })
241+
const position = { x, y }
242+
d(`updatePosition`, position)
243+
244+
this.emit('will-move', position)
235245

236246
this.browserWindow.setBounds({
237247
...this.browserWindow.getBounds(),
238-
x,
239-
y,
248+
...position,
240249
})
250+
251+
this.emit('moved')
241252
}
242253

243254
/** Backwards compat for Electron <12 */

0 commit comments

Comments
 (0)