mirror of
https://github.com/electron/electron.git
synced 2026-01-09 15:38:08 -05:00
feat: enable resetting accent color (#48274)
This commit is contained in:
@@ -1262,15 +1262,16 @@ Sets the properties for the window's taskbar button.
|
|||||||
|
|
||||||
#### `win.setAccentColor(accentColor)` _Windows_
|
#### `win.setAccentColor(accentColor)` _Windows_
|
||||||
|
|
||||||
* `accentColor` boolean | string - The accent color for the window. By default, follows user preference in System Settings.
|
* `accentColor` boolean | string | null - The accent color for the window. By default, follows user preference in System Settings. To reset to system default, pass `null`.
|
||||||
|
|
||||||
Sets the system accent color and highlighting of active window border.
|
Sets the system accent color and highlighting of active window border.
|
||||||
|
|
||||||
The `accentColor` parameter accepts the following values:
|
The `accentColor` parameter accepts the following values:
|
||||||
|
|
||||||
* **Color string** - Sets a custom accent color using standard CSS color formats (Hex, RGB, RGBA, HSL, HSLA, or named colors). Alpha values in RGBA/HSLA formats are ignored and the color is treated as fully opaque.
|
* **Color string** - Like `true`, but sets a custom accent color using standard CSS color formats (Hex, RGB, RGBA, HSL, HSLA, or named colors). Alpha values in RGBA/HSLA formats are ignored and the color is treated as fully opaque.
|
||||||
* **`true`** - Uses the system's default accent color from user preferences in System Settings.
|
* **`true`** - Enable accent color highlighting for the window with the system accent color regardless of whether accent colors are enabled for windows in System `Settings.`
|
||||||
* **`false`** - Explicitly disables accent color highlighting for the window.
|
* **`false`** - Disable accent color highlighting for the window regardless of whether accent colors are currently enabled for windows in System Settings.
|
||||||
|
* **`null`** - Reset window accent color behavior to follow behavior set in System Settings.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
@@ -1283,11 +1284,14 @@ win.setAccentColor('#ff0000')
|
|||||||
// RGB format (alpha ignored if present).
|
// RGB format (alpha ignored if present).
|
||||||
win.setAccentColor('rgba(255,0,0,0.5)')
|
win.setAccentColor('rgba(255,0,0,0.5)')
|
||||||
|
|
||||||
// Use system accent color.
|
// Enable accent color, using the color specified in System Settings.
|
||||||
win.setAccentColor(true)
|
win.setAccentColor(true)
|
||||||
|
|
||||||
// Disable accent color.
|
// Disable accent color.
|
||||||
win.setAccentColor(false)
|
win.setAccentColor(false)
|
||||||
|
|
||||||
|
// Reset window accent color behavior to follow behavior set in System Settings.
|
||||||
|
win.setAccentColor(null)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `win.getAccentColor()` _Windows_
|
#### `win.getAccentColor()` _Windows_
|
||||||
|
|||||||
@@ -1442,15 +1442,16 @@ Sets the properties for the window's taskbar button.
|
|||||||
|
|
||||||
#### `win.setAccentColor(accentColor)` _Windows_
|
#### `win.setAccentColor(accentColor)` _Windows_
|
||||||
|
|
||||||
* `accentColor` boolean | string - The accent color for the window. By default, follows user preference in System Settings.
|
* `accentColor` boolean | string | null - The accent color for the window. By default, follows user preference in System Settings. To reset to system default, pass `null`.
|
||||||
|
|
||||||
Sets the system accent color and highlighting of active window border.
|
Sets the system accent color and highlighting of active window border.
|
||||||
|
|
||||||
The `accentColor` parameter accepts the following values:
|
The `accentColor` parameter accepts the following values:
|
||||||
|
|
||||||
* **Color string** - Sets a custom accent color using standard CSS color formats (Hex, RGB, RGBA, HSL, HSLA, or named colors). Alpha values in RGBA/HSLA formats are ignored and the color is treated as fully opaque.
|
* **Color string** - Like `true`, but sets a custom accent color using standard CSS color formats (Hex, RGB, RGBA, HSL, HSLA, or named colors). Alpha values in RGBA/HSLA formats are ignored and the color is treated as fully opaque.
|
||||||
* **`true`** - Uses the system's default accent color from user preferences in System Settings.
|
* **`true`** - Enable accent color highlighting for the window with the system accent color regardless of whether accent colors are enabled for windows in System `Settings.`
|
||||||
* **`false`** - Explicitly disables accent color highlighting for the window.
|
* **`false`** - Disable accent color highlighting for the window regardless of whether accent colors are currently enabled for windows in System Settings.
|
||||||
|
* **`null`** - Reset window accent color behavior to follow behavior set in System Settings.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
@@ -1463,11 +1464,14 @@ win.setAccentColor('#ff0000')
|
|||||||
// RGB format (alpha ignored if present).
|
// RGB format (alpha ignored if present).
|
||||||
win.setAccentColor('rgba(255,0,0,0.5)')
|
win.setAccentColor('rgba(255,0,0,0.5)')
|
||||||
|
|
||||||
// Use system accent color.
|
// Enable accent color, using the color specified in System Settings.
|
||||||
win.setAccentColor(true)
|
win.setAccentColor(true)
|
||||||
|
|
||||||
// Disable accent color.
|
// Disable accent color.
|
||||||
win.setAccentColor(false)
|
win.setAccentColor(false)
|
||||||
|
|
||||||
|
// Reset window accent color behavior to follow behavior set in System Settings.
|
||||||
|
win.setAccentColor(null)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `win.getAccentColor()` _Windows_
|
#### `win.getAccentColor()` _Windows_
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if BUILDFLAG(IS_WIN)
|
#if BUILDFLAG(IS_WIN)
|
||||||
|
#include <variant>
|
||||||
#include "shell/browser/ui/views/win_frame_view.h"
|
#include "shell/browser/ui/views/win_frame_view.h"
|
||||||
#include "shell/browser/ui/win/taskbar_host.h"
|
#include "shell/browser/ui/win/taskbar_host.h"
|
||||||
#include "ui/base/win/shell.h"
|
#include "ui/base/win/shell.h"
|
||||||
@@ -1100,6 +1101,12 @@ void BaseWindow::SetAccentColor(gin::Arguments* const args) {
|
|||||||
v8::Local<v8::Value> ac_val;
|
v8::Local<v8::Value> ac_val;
|
||||||
args->GetNext(&ac_val);
|
args->GetNext(&ac_val);
|
||||||
|
|
||||||
|
if (!ac_val.IsEmpty() && ac_val->IsNull()) {
|
||||||
|
window_->SetAccentColor(std::monostate{});
|
||||||
|
window_->UpdateWindowAccentColor(window_->IsActive());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ac_val.IsEmpty() && ac_val->IsBoolean()) {
|
if (!ac_val.IsEmpty() && ac_val->IsBoolean()) {
|
||||||
const bool ac_flag = ac_val->BooleanValue(args->isolate());
|
const bool ac_flag = ac_val->BooleanValue(args->isolate());
|
||||||
window_->SetAccentColor(ac_flag);
|
window_->SetAccentColor(ac_flag);
|
||||||
@@ -1118,7 +1125,7 @@ void BaseWindow::SetAccentColor(gin::Arguments* const args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
args->ThrowTypeError(
|
args->ThrowTypeError(
|
||||||
"Invalid accent color value - must be a string or boolean");
|
"Invalid accent color value - must be null, hex string, or boolean");
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> BaseWindow::GetAccentColor() const {
|
v8::Local<v8::Value> BaseWindow::GetAccentColor() const {
|
||||||
|
|||||||
@@ -2562,7 +2562,23 @@ describe('BrowserWindow module', () => {
|
|||||||
expect(() => {
|
expect(() => {
|
||||||
// @ts-ignore this is wrong on purpose.
|
// @ts-ignore this is wrong on purpose.
|
||||||
w.setAccentColor([1, 2, 3]);
|
w.setAccentColor([1, 2, 3]);
|
||||||
}).to.throw('Invalid accent color value - must be a string or boolean');
|
}).to.throw('Invalid accent color value - must be null, hex string, or boolean');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws if called with an invalid parameter', () => {
|
||||||
|
const w = new BrowserWindow({ show: false });
|
||||||
|
expect(() => {
|
||||||
|
// @ts-ignore this is wrong on purpose.
|
||||||
|
w.setAccentColor(new Date());
|
||||||
|
}).to.throw('Invalid accent color value - must be null, hex string, or boolean');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can be reset with null', () => {
|
||||||
|
const w = new BrowserWindow({ show: false });
|
||||||
|
w.setAccentColor('#FF0000');
|
||||||
|
expect(w.getAccentColor()).to.equal('#FF0000');
|
||||||
|
w.setAccentColor(null);
|
||||||
|
expect(w.getAccentColor()).to.not.equal('#FF0000');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns the accent color after setting it to a string', () => {
|
it('returns the accent color after setting it to a string', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user