feat: allow monospaced font styles to be specified for macOS tray titles (#25059)

* feat: add optional font type to macOS tray title

* test: add tests for tray font type

* docs: update API reference for Tray setTitle

* review: change API to use an options object

* review: fix string enum in docs

Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>

* review: return after throwing errors

* review: don't need thrower anymore now that we have args

Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
This commit is contained in:
Alfred Xing 2020-08-23 14:39:29 -07:00 committed by GitHub
parent 13751c815e
commit a23c66e4e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 106 additions and 13 deletions

View file

@ -212,11 +212,33 @@ void Tray::SetToolTip(const std::string& tool_tip) {
tray_icon_->SetToolTip(tool_tip);
}
void Tray::SetTitle(const std::string& title) {
void Tray::SetTitle(const std::string& title,
const base::Optional<gin_helper::Dictionary>& options,
gin::Arguments* args) {
if (!CheckAlive())
return;
#if defined(OS_MAC)
tray_icon_->SetTitle(title);
TrayIcon::TitleOptions title_options;
if (options) {
if (options->Get("fontType", &title_options.font_type)) {
// Validate the font type if it's passed in
if (title_options.font_type != "monospaced" &&
title_options.font_type != "monospacedDigit") {
args->ThrowTypeError(
"fontType must be one of 'monospaced' or 'monospacedDigit'");
return;
}
} else if (options->Has("fontType")) {
args->ThrowTypeError(
"fontType must be one of 'monospaced' or 'monospacedDigit'");
return;
}
} else if (args->Length() >= 2) {
args->ThrowTypeError("setTitle options must be an object");
return;
}
tray_icon_->SetTitle(title, title_options);
#endif
}