feat: add {get|set}AccentColor on Windows (#48017)

* feat: add setAccentColor on Windows

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* refactor: unify GetSystemAccentColor

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* refactor: remove redundant parsing

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* chore: fixup documentation

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* Update docs/api/browser-window.md

Co-authored-by: Will Anderson <andersonw@dropbox.com>

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* Update docs/api/base-window.md

Co-authored-by: Will Anderson <andersonw@dropbox.com>

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2025-08-11 11:17:43 -04:00 committed by GitHub
commit 4b46b6e2f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 265 additions and 24 deletions

View file

@ -2523,6 +2523,92 @@ describe('BrowserWindow module', () => {
});
});
ifdescribe(process.platform === 'win32')('BrowserWindow.{get|set}AccentColor', () => {
afterEach(closeAllWindows);
it('throws if called with an invalid parameter', () => {
const w = new BrowserWindow({ show: false });
expect(() => {
// @ts-ignore this is wrong on purpose.
w.setAccentColor([1, 2, 3]);
}).to.throw('Invalid accent color value - must be a string or boolean');
});
it('returns the accent color after setting it to a string', () => {
const w = new BrowserWindow({ show: false });
const testColor = '#FF0000';
w.setAccentColor(testColor);
const accentColor = w.getAccentColor();
expect(accentColor).to.be.a('string');
expect(accentColor).to.equal(testColor);
});
it('returns the accent color after setting it to false', () => {
const w = new BrowserWindow({ show: false });
w.setAccentColor(false);
const accentColor = w.getAccentColor();
expect(accentColor).to.be.a('boolean');
expect(accentColor).to.equal(false);
});
it('returns a system color when set to true', () => {
const w = new BrowserWindow({ show: false });
w.setAccentColor(true);
const accentColor = w.getAccentColor();
expect(accentColor).to.be.a('string');
expect(accentColor).to.match(/^#[0-9A-F]{6}$/i);
});
it('returns the correct accent color after multiple changes', () => {
const w = new BrowserWindow({ show: false });
const testColor1 = '#00FF00';
w.setAccentColor(testColor1);
expect(w.getAccentColor()).to.equal(testColor1);
w.setAccentColor(false);
expect(w.getAccentColor()).to.equal(false);
const testColor2 = '#0000FF';
w.setAccentColor(testColor2);
expect(w.getAccentColor()).to.equal(testColor2);
w.setAccentColor(true);
const systemColor = w.getAccentColor();
expect(systemColor).to.be.a('string');
expect(systemColor).to.match(/^#[0-9A-F]{6}$/i);
});
it('handles CSS color names correctly', () => {
const w = new BrowserWindow({ show: false });
const testColor = 'red';
w.setAccentColor(testColor);
const accentColor = w.getAccentColor();
expect(accentColor).to.be.a('string');
expect(accentColor).to.equal('#FF0000');
});
it('handles RGB color values correctly', () => {
const w = new BrowserWindow({ show: false });
const testColor = 'rgb(255, 128, 0)';
w.setAccentColor(testColor);
const accentColor = w.getAccentColor();
expect(accentColor).to.be.a('string');
expect(accentColor).to.equal('#FF8000');
});
it('persists accent color across window operations', () => {
const w = new BrowserWindow({ show: false });
const testColor = '#ABCDEF';
w.setAccentColor(testColor);
w.show();
w.hide();
expect(w.getAccentColor()).to.equal(testColor);
});
});
describe('BrowserWindow.setAlwaysOnTop(flag, level)', () => {
let w: BrowserWindow;