Skip to content

Commit

Permalink
Merge pull request #229 from rarango9/bugfix/issue-228
Browse files Browse the repository at this point in the history
Bugfix/issue 228
  • Loading branch information
melonamin authored Oct 4, 2021
2 parents 9c82c39 + 179fdf5 commit 88f43a1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions SwiftBar/MenuBar/MenuBarItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ extension MenubarItem: NSMenuDelegate {
params.params["color"] = "white"
params.params["sfcolor"] = "white"
if !AppShared.isReduceTransparencyEnabled {
barItem.button?.attributedTitle = atributedTitle(with: params).title
barItem.button?.attributedTitle = atributedTitle(with: params, pad: true).title
}

hotKeys.forEach { $0.isPaused = true }
Expand Down Expand Up @@ -500,7 +500,7 @@ extension MenubarItem {
barItem.button?.image = image
barItem.button?.imagePosition = .imageLeft
}
barItem.button?.attributedTitle = atributedTitle(with: params).title
barItem.button?.attributedTitle = atributedTitle(with: params, pad: true).title
}

func cycleThroughTitles() {
Expand All @@ -511,7 +511,7 @@ extension MenubarItem {
setMenuTitle(title: titleLines[currentTitleLineIndex])
}

func atributedTitle(with params: MenuLineParameters) -> (title: NSAttributedString, tooltip: String) {
func atributedTitle(with params: MenuLineParameters, pad: Bool = false) -> (title: NSAttributedString, tooltip: String) {
var title = params.trim ? params.title.trimmingCharacters(in: .whitespaces) : params.title
guard !title.isEmpty else { return (NSAttributedString(), "") }

Expand Down Expand Up @@ -541,6 +541,11 @@ extension MenubarItem {
if params.ansi {
attributedTitle = title.colorizedWithANSIColor()
}

if attributedTitle.length > 0, pad {
attributedTitle.insert(NSAttributedString(string: " "), at: 0)
}

if !params.ansi {
attributedTitle.addAttributes([.foregroundColor: color],
range: NSRange(0 ..< attributedTitle.length))
Expand Down Expand Up @@ -622,7 +627,7 @@ extension MenubarItem {

if params.refresh {
plugin?.refresh()
updateMenu(content: plugin?.content) //dumb fix for #221, ideally come up with something better...
updateMenu(content: plugin?.content) // dumb fix for #221, ideally come up with something better...
return true
}
return false
Expand Down

0 comments on commit 88f43a1

Please sign in to comment.