Skip to content
This repository was archived by the owner on Sep 13, 2024. It is now read-only.

Commit d29b38a

Browse files
committed
fix(bgColor): 🐛 Fixed a background color
Fix TypeError: backgroundColor?.isLighter is not a function, using updateBackground function
1 parent 6550eeb commit d29b38a

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

src/menubar/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,6 @@ export class MenuBar extends Disposable {
575575
const cleanMenuLabel = cleanMnemonic(label)
576576

577577
// Update the button label to reflect mnemonics
578-
579578
if (this.options.enableMnemonics) {
580579
const cleanLabel = strings.escape(label)
581580

@@ -593,9 +592,9 @@ export class MenuBar extends Disposable {
593592
if (escMatch) {
594593
titleElement.innerText = ''
595594
titleElement.append(
596-
strings.ltrim(replaceDoubleEscapes(cleanLabel.substr(0, escMatch.index)), ' '),
595+
strings.ltrim(replaceDoubleEscapes(cleanLabel.substring(0, escMatch.index)), ' '),
597596
$('mnemonic', { 'aria-hidden': 'true' }, escMatch[3]),
598-
strings.rtrim(replaceDoubleEscapes(cleanLabel.substr(escMatch.index + escMatch[0].length)), ' ')
597+
strings.rtrim(replaceDoubleEscapes(cleanLabel.substring(escMatch.index + escMatch[0].length)), ' ')
599598
)
600599
} else {
601600
titleElement.innerText = replaceDoubleEscapes(cleanLabel).trim()

src/menubar/menubar-options.ts

-7
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ export interface MenuBarOptions {
2121
* **The default is undefined**
2222
*/
2323
itemBackgroundColor?: Color;
24-
/**
25-
* @deprecated Use `setupTitlebar` method instead.
26-
* The menu to show in the title bar.
27-
* You can use `Menu` or not add this option and the menu created in the main process will be taken.
28-
* **The default menu is undefined**
29-
*/
30-
menu?: Menu;
3124
/**
3225
* The background color of the menu.
3326
* **The default is automatic**

src/titlebar/index.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class CustomTitlebar extends ThemeBar {
3737
}
3838

3939
private currentOptions: TitleBarOptions = {
40+
backgroundColor: Color.WHITE,
4041
closeable: true,
4142
enableMnemonics: true,
4243
// hideWhenClickingClose: false,
@@ -396,25 +397,24 @@ export class CustomTitlebar extends ThemeBar {
396397
: ACTIVE_FOREGROUND
397398
}
398399

399-
this.titlebar.style.color = foregroundColor.toString()
400+
this.titlebar.style.color = foregroundColor?.toString()
400401

401402
if (this.menuBar) {
402403
let fgColor
403-
const backgroundColor = this.currentOptions.menuBarBackgroundColor ?? this.currentOptions.backgroundColor?.darken(0.12)
404+
const backgroundColor = this.currentOptions.menuBarBackgroundColor || this.currentOptions.backgroundColor!.darken(0.12)
404405

405406
const foregroundColor = backgroundColor?.isLighter()
406407
? INACTIVE_FOREGROUND_DARK
407408
: INACTIVE_FOREGROUND
408409

409-
const bgColor = !this.currentOptions.itemBackgroundColor || this.currentOptions.itemBackgroundColor.equals(backgroundColor!)
410-
? DEFAULT_ITEM_SELECTOR
411-
: this.currentOptions.itemBackgroundColor
410+
const bgColor = this.currentOptions.itemBackgroundColor && !this.currentOptions.itemBackgroundColor.equals(backgroundColor)
411+
? this.currentOptions.itemBackgroundColor
412+
: DEFAULT_ITEM_SELECTOR
412413

413-
414-
if (bgColor.equals(DEFAULT_ITEM_SELECTOR)) {
414+
if (bgColor?.equals(DEFAULT_ITEM_SELECTOR)) {
415415
fgColor = backgroundColor?.isLighter() ? ACTIVE_FOREGROUND_DARK : ACTIVE_FOREGROUND
416416
} else {
417-
fgColor = bgColor.isLighter() ? ACTIVE_FOREGROUND_DARK : ACTIVE_FOREGROUND
417+
fgColor = bgColor?.isLighter() ? ACTIVE_FOREGROUND_DARK : ACTIVE_FOREGROUND
418418
}
419419

420420
this.menuBar.setStyles({
@@ -549,6 +549,7 @@ export class CustomTitlebar extends ThemeBar {
549549
* @param backgroundColor The color for the background
550550
*/
551551
public updateBackground(backgroundColor: Color) {
552+
if (typeof backgroundColor === 'string') backgroundColor = Color.fromHex(backgroundColor)
552553
this.currentOptions.backgroundColor = backgroundColor
553554
this.updateStyles()
554555

@@ -560,6 +561,7 @@ export class CustomTitlebar extends ThemeBar {
560561
* @param itemBGColor The color for the item background
561562
*/
562563
public updateItemBGColor(itemBGColor: Color) {
564+
if (typeof itemBGColor === 'string') itemBGColor = Color.fromHex(itemBGColor)
563565
this.currentOptions.itemBackgroundColor = itemBGColor
564566
this.updateStyles()
565567

0 commit comments

Comments
 (0)