Merge remote-tracking branch 'origin/master' into meta-dev

# Conflicts:
#	ClashX/Support Files/en.lproj/Localizable.strings
#	ClashX/Support Files/zh-Hans.lproj/Localizable.strings
#	ClashX/Views/StatusItemView.swift
This commit is contained in:
mrFq1 2023-02-19 12:08:40 +08:00
commit be7a62478d
5 changed files with 74 additions and 3 deletions

View File

@ -103,6 +103,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func postFinishLaunching() {
defer {
statusItem.menu = statusMenu
DispatchQueue.main.asyncAfter(deadline: .now()+1) {
self.checkMenuIconVisable()
}
}
setupStatusMenuItemData()
AppVersionUtil.showUpgradeAlert()
@ -196,6 +200,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

View File

@ -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
}

View File

@ -110,7 +110,8 @@
"Load Balance" = "Load Balance";
/* No comment provided by engineer. */
"Never" = "Never";
"Never show again" = "Never show again";
/* No comment provided by engineer. */
"No new release found." = "No new release found.";
@ -202,6 +203,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.";

View File

@ -110,7 +110,7 @@
"Load Balance" = "负载均衡";
/* No comment provided by engineer. */
"Never" = "从未";
"Never show again" = "不再提示";
/* No comment provided by engineer. */
"No new release found." = "未找到更新.";
@ -202,6 +202,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 查看详情";

View File

@ -118,7 +118,9 @@ extension NSStatusItem {
let img = NSImage(size: view.bounds.size)
img.addRepresentation(rep)
img.isTemplate = true
image = img
button?.image = img
} else {
Logger.log("generate status menu icon fail", level: .error)
}
}
}