feat: support "only when external display show menu bar icon" option (#1817)

Co-authored-by: neo <yifei0727@no-reply.users.github.io>
This commit is contained in:
NEO 2025-11-16 17:58:59 +08:00 committed by GitHub
parent f62c7e66ce
commit d4309e6ec5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 72 additions and 1 deletions

View file

@ -191,6 +191,7 @@ enum MenuIcon: Int {
case show = 0
case sliderOnly = 1
case hide = 2
case externalOnly = 3
}
enum MenuItemStyle: Int {

View file

@ -33,7 +33,19 @@ class MenuHandler: NSMenu, NSMenuDelegate {
if !dontClose {
self.cancelTrackingWithoutAnimation()
}
app.updateStatusItemVisibility(prefs.integer(forKey: PrefKey.menuIcon.rawValue) == MenuIcon.show.rawValue ? true : false)
let menuIconPref = prefs.integer(forKey: PrefKey.menuIcon.rawValue)
var showIcon = false
if menuIconPref == MenuIcon.show.rawValue {
showIcon = true
} else if menuIconPref == MenuIcon.externalOnly.rawValue {
let externalDisplays = DisplayManager.shared.displays.filter {
CGDisplayIsBuiltin($0.identifier) == 0
}
if externalDisplays.count > 0 {
showIcon = true
}
}
app.updateStatusItemVisibility(showIcon)
self.clearMenu()
let currentDisplay = DisplayManager.shared.getCurrentDisplay()
var displays: [Display] = []

View file

@ -368,6 +368,7 @@
<items>
<menuItem title="Always show in the menu bar" state="on" id="MM0-Lf-VgF"/>
<menuItem title="Only if at least one slider is present" tag="1" id="xLa-PN-rsq"/>
+ <menuItem title="Only when external display is present" tag="3" id="Tb1-6s-qOo"/>
<menuItem title="Always hide" tag="2" id="6mo-7S-oOO"/>
</items>
</menu>

View file

@ -376,6 +376,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "Jen pokud je k dispozici alespoň jeden posuvník";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "Pouze když je externí displej přítomen";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "Standardní i vlastní zkratky";

View file

@ -376,6 +376,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "Nur wenn mindestens ein Regler vorhanden ist";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "Nur wenn externer Bildschirm vorhanden ist";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "Sowohl Standard- als auch benutzerdefinierte Tastenkombinationen";

View file

@ -376,6 +376,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "Only if at least one slider is present";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "Only when external display is present";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "Both standard and custom shortcuts";

View file

@ -376,6 +376,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "Sólo si hay presente al menos un slider";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "Solo cuando la pantalla externa está presente";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "Ambos, atajos estándar y personalizados";

View file

@ -376,6 +376,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "Uniquement si au moins un curseur est présent";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "Seulement lorsqu'un écran externe est présent";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "Raccourcis standard et personnalisés";

View file

@ -428,6 +428,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "केवल तभी जब कम से कम एक स्लाइडर मौजूद हो";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "केवल तभी जब बाहरी डिस्प्ले मौजूद हो";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "मानक और कस्टम दोनों शॉर्टकट";

View file

@ -376,6 +376,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "Csak ha legalább egy vezérlő megjelenik";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "Csak ha külső kijelző van jelen";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "Hagyományos és egyedi billentyűkombinációk";

View file

@ -376,6 +376,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "Solo se è presente almeno uno slider";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "Solo quando è presente un display esterno";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "Entrambe le abbreviazioni standard e personalizzate";

View file

@ -428,6 +428,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "少なくとも 1 つのスライダーが存在する場合のみ";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "外部ディスプレイがある場合のみ";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "標準ショートカットとカスタムショートカットの両方";

View file

@ -376,6 +376,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "슬라이더가 하나 이상 있는 경우에만";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "외부 디스플레이가 있을 때만";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "표준 및 사용자 정의 단축키 둘 다";

View file

@ -376,6 +376,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "Alleen als er ten minste één schuifregelaar aanwezig is";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "Alleen wanneer een extern beeldscherm aanwezig is";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "Zowel standaard als aangepaste sneltoetsen";

View file

@ -376,6 +376,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "Tylko w przypadku obecności co najmniej jednego suwaka";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "Tylko gdy monitor zewnętrzny jest obecny";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "Skróty standardowe oraz użytkownika";

View file

@ -379,6 +379,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "Apenas se pelo menos um controle deslizante estiver presente";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "Somente quando o monitor externo estiver presente";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "Atalhos padrão e personalizados";

View file

@ -379,6 +379,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "Apenas se pelo menos um controle deslizante estiver presente";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "Apenas quando um ecrã externo estiver presente";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "Atalhos padrão e personalizados";

View file

@ -376,6 +376,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "Только при наличии хотя бы одного ползунка";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "Только при наличии внешнего дисплея";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "Как стандартные, так и пользовательские сочетания клавиш";

View file

@ -401,6 +401,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "Iba ak je prítomný aspoň jeden posuvník";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "Iba keď je prítomný externý displej";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "Štandardné aj vlastné skratky";

View file

@ -376,6 +376,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "Yalnızca en az bir kaydırıcı varsa";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "Yalnızca harici ekran mevcut olduğunda";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "Hem standart hem de özel kısayollar";

View file

@ -376,6 +376,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "只有当至少一个滑杆可用时";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "仅当存在外置显示器时";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "标准及自定义快捷键";

View file

@ -376,6 +376,9 @@
/* Class = "NSMenuItem"; title = "Only if at least one slider is present"; ObjectID = "xLa-PN-rsq"; */
"xLa-PN-rsq.title" = "只有當至少一個滑桿可用時";
/* Class = "NSMenuItem"; title = "Only when external display is present"; ObjectID = "Tb1-6s-qOo"; */
"Tb1-6s-qOo.title" = "僅當存在外置顯示器時";
/* Class = "NSMenuItem"; title = "Both standard and custom shortcuts"; ObjectID = "xQJ-aJ-VhH"; */
"xQJ-aJ-VhH.title" = "標準及自定快速鍵";