Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nativeTheme is undefined #466

Open
jarrodek opened this issue Oct 29, 2019 · 3 comments
Open

nativeTheme is undefined #466

jarrodek opened this issue Oct 29, 2019 · 3 comments

Comments

@jarrodek
Copy link

Electron 7 introduced new API called nativeTheme, however app.electron.nativeTheme is undefined. It should have properties like themeSource, shouldUseDarkColors, and others.
When I am printing to the console app.electron it looks good but it does not have nativeTheme property.

Electron version: 7.0.0
Spectron version: 9.0.0

@dennisameling
Copy link

dennisameling commented May 3, 2020

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?

@dennisameling
Copy link

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 desktop/desktop#9699

@dennisameling
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants