Open jarrodek opened 4 years ago
Having the same issue here with Electron 7.1.8 on Windows 10 x64. The weird thing is that when I run the Electron app locally, it works, but when running tests (Spectron 9.0.0), it doesn't and nativeTheme
is undefined:
FAIL app/test/unit/stats-store-test.ts
● Test suite failed to run
TypeError: Cannot read property 'addListener' of undefined
20 | }
21 |
> 22 | remote.nativeTheme.addListener('updated', this.onThemeNotificationFromOS)
| ^
23 | }
24 |
25 | private onThemeNotificationFromOS = (event: string, userInfo: any) => {
at ThemeChangeMonitor.subscribe (src/ui/lib/theme-change-monitor.ts:22:24)
at new ThemeChangeMonitor (src/ui/lib/theme-change-monitor.ts:10:10)
at Object.<anonymous> (src/ui/lib/theme-change-monitor.ts:44:35)
at Object.<anonymous> (src/lib/stores/app-store.ts:65:1)
at Object.<anonymous> (src/lib/stores/index.ts:2:1)
at Object.<anonymous> (src/lib/stats/stats-store.ts:13:1)
at Object.<anonymous> (src/lib/stats/index.ts:2:1)
at Object.<anonymous> (test/helpers/databases/test-stats-database.ts:1:1)
at Object.<anonymous> (test/helpers/databases/index.ts:4:1)
at Object.<anonymous> (test/unit/stats-store-test.ts:1:1)
@jarrodek were you able to resolve your issue in the meantime?
Update: nativeTheme
only seems to be undefined in test environments, not when running an Electron app manually on Windows 10 1809+/Server 2019+. Not sure if this is related to Spectron or Electon itself though. See https://github.com/desktop/desktop/issues/9699
Just to provide a quick update here: GitHub Desktop uses a mock service for Electron remote, there the nativeTheme
property was missing. So that issue is solved. See https://github.com/desktop/desktop/pull/9709/files
Electron 7 introduced new API called
nativeTheme
, howeverapp.electron.nativeTheme
is undefined. It should have properties likethemeSource
,shouldUseDarkColors
, and others. When I am printing to the consoleapp.electron
it looks good but it does not havenativeTheme
property.Electron version: 7.0.0 Spectron version: 9.0.0