electron-util
Version:
Useful utilities for Electron apps and modules
38 lines (35 loc) • 804 B
JavaScript
import { nativeTheme } from 'electron';
import { is } from '../shared/is.js';
/**
@example
```
import {darkMode} from 'electron-util';
console.log(darkMode.isEnabled);
//=> false
darkMode.onChange(() => {
console.log(darkMode.isEnabled);
//=> true
});
```
*/
export const darkMode = {
get isEnabled() {
if (!is.macos) {
return false;
}
return nativeTheme.shouldUseDarkColors;
},
onChange(callback) {
if (!is.macos) {
// eslint-disable-next-line @typescript-eslint/no-empty-function
return () => { };
}
const handler = () => {
callback();
};
nativeTheme.on('updated', handler);
return () => {
nativeTheme.off('updated', handler);
};
},
};