Skip to content

Commit e0f720e

Browse files
committed
fix: search for base and browser windows
1 parent d07b752 commit e0f720e

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { promises as fs } from 'node:fs'
22
import * as path from 'node:path'
3-
import { nativeImage } from 'electron'
3+
import { BaseWindow, BrowserWindow, nativeImage } from 'electron'
44

55
export interface TabContents extends Electron.WebContents {
66
favicon?: string
@@ -120,3 +120,5 @@ export const matchesTitlePattern = (pattern: string, title: string) => {
120120
const regexp = new RegExp(`^${pattern.split('*').map(escapePattern).join('.*')}$`)
121121
return title.match(regexp)
122122
}
123+
124+
export const getAllWindows = () => [...BaseWindow.getAllWindows(), ...BrowserWindow.getAllWindows()]

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { BrowserWindow } from 'electron'
21
import { ExtensionContext } from '../context'
32
import { ExtensionEvent } from '../router'
4-
import { matchesPattern, matchesTitlePattern, TabContents } from './common'
3+
import { getAllWindows, matchesPattern, matchesTitlePattern, TabContents } from './common'
54
import { WindowsAPI } from './windows'
65

76
const debug = require('debug')('electron-chrome-extensions:tabs')
@@ -357,7 +356,7 @@ export class TabsAPI {
357356
const windowId = details ? details.windowId : WindowsAPI.WINDOW_ID_NONE
358357
const win =
359358
typeof windowId !== 'undefined' && windowId > -1
360-
? BrowserWindow.getAllWindows().find((win) => win.id === windowId)
359+
? getAllWindows().find((win) => win.id === windowId)
361360
: null
362361

363362
this.ctx.router.broadcastEvent('tabs.onRemoved', tabId, {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { BrowserWindow, Session } from 'electron'
1+
import { BaseWindow, BrowserWindow, Session } from 'electron'
2+
import { getAllWindows } from './api/common'
23

34
const debug = require('debug')('electron-chrome-extensions:popup')
45

@@ -185,7 +186,7 @@ export class PopupView {
185186
// For extension popups with a login form, the user may need to access a
186187
// program outside of the app. Closing the popup would then add
187188
// inconvenience.
188-
if (!BrowserWindow.getFocusedWindow()) {
189+
if (!getAllWindows().some((win) => win.isFocused())) {
189190
debug('preventing close due to focus residing outside of the app')
190191
return
191192
}

0 commit comments

Comments
 (0)