Electron: Trying to set `nativeTheme.themeSource`, but `nativeTheme` is undefined

后端 未结 1 402
暗喜
暗喜 2021-01-26 16:38

I\'m unable to set the themeSource of my electron app. Platform is Windows 8.1.

const electron = require(\'el         


        
相关标签:
1条回答
  • 2021-01-26 17:05
    nativeTheme = electron.nativeTheme;
    

    This is the problem. You need to do:

    const nativeTheme = electron.nativeTheme;
    

    Although in this case there's no need for the extra variable - just do electron.nativeTheme.themeSource = 'dark';.

    I strongly suggest you use Typescript - it would tell you this:

    Edit: I'm sure I mentioned this in the comments but it seems to have been removed somehow: You also need to make sure you are using Electron 7.0.0 or greater - nativeTheme was not available before that.

    0 讨论(0)
提交回复
热议问题