'Get accent color in Windows dark mode

Program-building with electron

The idea:
I want the accent color of my program to be the same as the one from Windows.

The problem:
For the Light Mode of Windows, everything works, the passed color matches the Windows accent color. But when switching to Dark Mode, I still get the accent color of the Light Mode.

Possible solutions:
How does the Windows selection for the Dark Mode accent color work? Is the color always increased by a certain brightness level? Or are there pre-saved patterns?


Here is my current code:

main.js

let color = systemPreferences.getAccentColor()

  mainWindow.on('ready-to-show', function() {
    mainWindow.webContents.send('accColor', {'Color': color});
  })

ipc.js

ipc.on('accColor', (evt, message) => {
    let color = message['Color']
    const hex2rgb = (hex) => {
        const r = parseInt(hex.slice(1, 3), 16)
        const g = parseInt(hex.slice(3, 5), 16)
        const b = parseInt(hex.slice(5, 7), 16)
        return [ r, g, b ]
    }
    let baseRGB = hex2rgb('#' + color)
    document.querySelector('body').style.setProperty('--accent-default-rgb', baseRGB)
})


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source