feat: add notice if status icon is covered by notch
This commit is contained in:
parent
267f75b631
commit
447c1c63a2
@ -86,6 +86,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
func postFinishLaunching() {
|
||||
defer {
|
||||
statusItem.menu = statusMenu
|
||||
DispatchQueue.main.asyncAfter(deadline: .now()+1) {
|
||||
self.checkMenuIconVisable()
|
||||
}
|
||||
|
||||
}
|
||||
setupStatusMenuItemData()
|
||||
AppVersionUtil.showUpgradeAlert()
|
||||
@ -183,6 +187,61 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
SystemProxyManager.shared.disableProxy()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func buttonRectOnScreen() -> CGRect {
|
||||
guard let button = statusItem.button else { return .zero }
|
||||
guard let window = button.window else { return .zero }
|
||||
let buttonRect = button.convert(button.bounds, to: nil)
|
||||
let onScreenRect = window.convertToScreen(buttonRect)
|
||||
return onScreenRect
|
||||
}
|
||||
|
||||
func leftScreenX() -> CGFloat {
|
||||
let screens = NSScreen.screens
|
||||
|
||||
var left: CGFloat = 0
|
||||
|
||||
for screen in screens {
|
||||
if screen.frame.origin.x < left {
|
||||
left = screen.frame.origin.x
|
||||
}
|
||||
}
|
||||
return left
|
||||
}
|
||||
|
||||
func checkMenuIconVisable() {
|
||||
guard let button = statusItem.button else {assertionFailure(); return }
|
||||
guard let window = button.window else {assertionFailure(); return }
|
||||
let buttonRect = button.convert(button.bounds, to: nil)
|
||||
let onScreenRect = window.convertToScreen(buttonRect)
|
||||
var leftScreenX: CGFloat = 0
|
||||
for screen in NSScreen.screens {
|
||||
if screen.frame.origin.x < leftScreenX {
|
||||
leftScreenX = screen.frame.origin.x
|
||||
}
|
||||
}
|
||||
let isMenuIconHidden = onScreenRect.midX < leftScreenX
|
||||
|
||||
var isCoverdByNotch = false
|
||||
if #available(macOS 12, *), NSScreen.screens.count == 1, let screen = NSScreen.screens.first, let leftArea = screen.auxiliaryTopLeftArea, let rightArea = screen.auxiliaryTopRightArea {
|
||||
if onScreenRect.minX > leftArea.maxX, onScreenRect.maxX<rightArea.minX {
|
||||
isCoverdByNotch = true
|
||||
}
|
||||
}
|
||||
|
||||
Logger.log("checkMenuIconVisable: \(onScreenRect) \(leftScreenX), hidden: \(isMenuIconHidden), coverd by notch:\(isCoverdByNotch)")
|
||||
|
||||
if (isMenuIconHidden || isCoverdByNotch), !Settings.disableMenubarNotice {
|
||||
let alert = NSAlert()
|
||||
alert.messageText = NSLocalizedString("The status icon is coverd or hide by other app.", comment: "")
|
||||
alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
|
||||
alert.addButton(withTitle: NSLocalizedString("Never show again", comment: ""))
|
||||
if alert.runModal() == .alertSecondButtonReturn {
|
||||
Settings.disableMenubarNotice = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func setupStatusMenuItemData() {
|
||||
ConfigManager.shared
|
||||
|
@ -33,4 +33,7 @@ enum Settings {
|
||||
"sequoia.apple.com",
|
||||
"seed-sequoia.siri.apple.com"])
|
||||
static var proxyIgnoreList: [String]
|
||||
|
||||
@UserDefault("disableMenubarNotice",defaultValue: false)
|
||||
static var disableMenubarNotice: Bool
|
||||
}
|
||||
|
@ -99,6 +99,9 @@
|
||||
/* No comment provided by engineer. */
|
||||
"Never" = "Never";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"Never show again" = "Never show again";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"OK" = "OK";
|
||||
|
||||
@ -180,6 +183,9 @@
|
||||
/* No comment provided by engineer. */
|
||||
"The remote config name is duplicated" = "The remote config name is duplicated";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"The status icon is coverd or hide by other app." = "The status icon is coverd or hide by other app.";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"This version of ClashX contains a break change due to clash core 1.0 released. Check if your config is not working properly." = "This version of ClashX contains a break change due to clash core 1.0 released. Check if your config is not working properly.";
|
||||
|
||||
|
@ -99,6 +99,9 @@
|
||||
/* No comment provided by engineer. */
|
||||
"Never" = "从未";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"Never show again" = "不再提示";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"OK" = "确定";
|
||||
|
||||
@ -180,6 +183,9 @@
|
||||
/* No comment provided by engineer. */
|
||||
"The remote config name is duplicated" = "托管配置文件名称重复";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"The status icon is coverd or hide by other app." = "菜单栏图标被刘海屏遮挡或者被其他app隐藏,请检查菜单栏状态。";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"This version of ClashX contains a break change due to clash core 1.0 released. Check if your config is not working properly." = "由于Clash Core发布1.0版本,使用此版本的 ClashX 可能需要更新配置内容\n前往 https://github.com/Dreamacro/clash/wiki/breaking-changes-in-1.0.0 查看详情";
|
||||
|
||||
|
@ -120,6 +120,8 @@ extension NSStatusItem {
|
||||
img.addRepresentation(rep)
|
||||
img.isTemplate = true
|
||||
button?.image = img
|
||||
} else {
|
||||
Logger.log("generate status menu icon fail", level: .error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user