Skip to content

Commit

Permalink
Merge branch 'meta-dev' into meta
Browse files Browse the repository at this point in the history
  • Loading branch information
mrFq1 committed Feb 21, 2023
2 parents 4ceec7a + bf6184d commit ee2e9d9
Show file tree
Hide file tree
Showing 19 changed files with 167 additions and 60 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
uses: robinraju/[email protected]
with:
repository: 'MetaCubeX/Clash.Meta'
tag: "v1.14.0"
fileName: ".*darwin.*.gz"
tag: "v1.14.2"
fileName: ".*darwin.*64-v.*.gz"
out-file-path: "clash.meta"
token: ${{ secrets.GITHUB_TOKEN }}

Expand Down
58 changes: 58 additions & 0 deletions ClashX/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -197,6 +201,60 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

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
.showNetSpeedIndicatorObservable
Expand Down
13 changes: 6 additions & 7 deletions ClashX/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Settings-->
<scene sceneID="7zJ-aQ-tNg">
<objects>
<tabViewController title="Settings" showSeguePresentationStyle="single" selectedTabViewItemIndex="0" id="LAj-p8-9gd" customClass="SettingTabViewController" customModule="ClashX_Pro" customModuleProvider="target" sceneMemberID="viewController">
<tabViewController title="Settings" showSeguePresentationStyle="single" selectedTabViewItemIndex="0" id="LAj-p8-9gd" customClass="SettingTabViewController" customModule="ClashX_Meta" customModuleProvider="target" sceneMemberID="viewController">
<tabViewItems>
<tabViewItem label="General" identifier="general" image="gearshape" catalog="system" id="Ltt-Vq-Hh1"/>
</tabViewItems>
Expand All @@ -33,7 +33,7 @@
<!--General-->
<scene sceneID="XxM-Ti-kkw">
<objects>
<viewController title="General" showSeguePresentationStyle="single" id="kma-mp-ncL" customClass="GeneralSettingViewController" customModule="ClashX_Pro" customModuleProvider="target" sceneMemberID="viewController">
<viewController title="General" showSeguePresentationStyle="single" id="kma-mp-ncL" customClass="GeneralSettingViewController" customModule="ClashX_Meta" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="dpe-v8-fF7">
<rect key="frame" x="0.0" y="0.0" width="400" height="299"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down Expand Up @@ -99,7 +99,7 @@
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="TVZ-xJ-zK0">
<rect key="frame" x="18" y="145" width="324" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Bypass proxy settings for there Hosts &amp; Domains" id="NPu-V9-f3r">
<textFieldCell key="cell" lineBreakMode="clipping" title="Bypass proxy settings for these Hosts &amp; Domains" id="NPu-V9-f3r">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -125,7 +125,7 @@
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="305" height="100"/>
<size key="maxSize" width="305" height="10000000"/>
<size key="maxSize" width="320" height="10000000"/>
<color key="insertionPointColor" name="textColor" catalog="System" colorSpace="catalog"/>
</textView>
</subviews>
Expand Down Expand Up @@ -733,7 +733,6 @@
</items>
</menu>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<customObject id="fth-rt-saN" customClass="SUUpdater"/>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
<userDefaultsController representsSharedInstance="YES" id="dwS-am-r7H"/>
</objects>
Expand Down
15 changes: 15 additions & 0 deletions ClashX/General/ApiRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,21 @@ class ApiRequest {
}
}

static func getGroupDelay(groupName: String, callback: @escaping (([String: Int]) -> Void)) {
req("/group/\(groupName.encoded)/delay",
method: .get,
parameters: ["timeout": 5000, "url": ConfigManager.shared.benchMarkUrl])
.responseData { res in
switch res.result {
case let .success(value):
let dic = try? JSONDecoder().decode([String: Int].self, from: value)
callback(dic ?? [:])
case .failure:
callback([:])
}
}
}

static func getRules(completeHandler: @escaping ([ClashRule]) -> Void) {
req("/rules").responseData { res in
guard let data = try? res.result.get() else { return }
Expand Down
3 changes: 3 additions & 0 deletions ClashX/General/ClashMetaConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class ClashMetaConfig: NSObject {
var socksPort: Int?
var mixedPort: Int?

var geodataMode: Bool?

var logLevel = ConfigManager.selectLoggingApiLevel.rawValue

var path: String {
Expand All @@ -43,6 +45,7 @@ class ClashMetaConfig: NSObject {
port,
socksPort = "socks-port",
logLevel = "log-level",
geodataMode = "geodata-mode",
secret
}

Expand Down
4 changes: 2 additions & 2 deletions ClashX/General/Managers/ClashResourceManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import Gzip
class ClashResourceManager {
enum RuleFiles: String {
case mmdb = "Country.mmdb"
case geosite = "geosite.dat"
case geoip = "geoip.dat"
case geosite = "Geosite.dat"
case geoip = "Geoip.dat"
}

static func check() -> Bool {
Expand Down
3 changes: 3 additions & 0 deletions ClashX/General/Managers/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 5 additions & 1 deletion ClashX/Support Files/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down Expand Up @@ -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.";

Expand Down
5 changes: 4 additions & 1 deletion ClashX/Support Files/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"Load Balance" = "负载均衡";

/* No comment provided by engineer. */
"Never" = "从未";
"Never show again" = "不再提示";

/* No comment provided by engineer. */
"No new release found." = "未找到更新.";
Expand Down Expand Up @@ -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 查看详情";

Expand Down
41 changes: 3 additions & 38 deletions ClashX/Views/ProxyGroupSpeedTestMenuItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,53 +99,18 @@ private class ProxyGroupSpeedTestMenuItemView: MenuItemBaseView {
private func startBenchmark() {
guard let group = (enclosingMenuItem as? ProxyGroupSpeedTestMenuItem)?.proxyGroup
else { return }
let testGroup = DispatchGroup()

var proxies = [ClashProxyName]()
var providers = Set<ClashProviderName>()
for testable in group.speedtestAble {
switch testable {
case let .provider(_, provider):
providers.insert(provider)
case let .proxy(name):
proxies.append(name)
case let .group(name):
proxies.append(name)
}
}

for proxyName in proxies {
testGroup.enter()
ApiRequest.getProxyDelay(proxyName: proxyName) { delay in
let delayStr = delay == 0 ? NSLocalizedString("fail", comment: "") : "\(delay) ms"
NotificationCenter.default.post(name: .speedTestFinishForProxy,
object: nil,
userInfo: ["proxyName": proxyName, "delay": delayStr, "rawValue": delay])
testGroup.leave()
}
}

label.stringValue = NSLocalizedString("Testing", comment: "")
enclosingMenuItem?.isEnabled = false
setNeedsDisplay()

for provider in providers {
testGroup.enter()

ApiRequest.healthCheck(proxy: provider) {
testGroup.leave()
}
}

testGroup.notify(queue: .main) {
[weak self] in
ApiRequest.getGroupDelay(groupName: group.name) {
[weak self] _ in
guard let self = self, let menu = self.enclosingMenuItem else { return }
self.label.stringValue = menu.title
menu.isEnabled = true
self.setNeedsDisplay()
if providers.count > 0 {
MenuItemFactory.refreshExistingMenuItems()
}
MenuItemFactory.refreshExistingMenuItems()
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion ClashX/Views/StatusItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
55 changes: 55 additions & 0 deletions ClashX/goClash/build_clash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import subprocess
import datetime
import plistlib
import os

def get_version():
with open('./go.mod') as file:
for line in file.readlines():
if "clash" in line and "ClashX" not in line:
return line.split("-")[-1].strip()[:6]
return "unknown"

def get_full_version():
with open('./go.mod') as file:
for line in file.readlines():
if "clash" in line and "ClashX" not in line:
return line.split(" ")[-1].strip()

def build_clash(version):
build_time = datetime.datetime.now().strftime("%Y-%m-%d-%H%M")
command = f"""CGO_CFLAGS=-mmacosx-version-min=10.12 \
CGO_LDFLAGS=-mmacosx-version-min=10.12 \
go build -trimpath -ldflags '-X "github.com/Dreamacro/clash/constant.Version={version}" \
-X "github.com/Dreamacro/clash/constant.BuildTime={build_time}"' \
-buildmode=c-archive -o goClash.a """
subprocess.check_output(command, shell=True)


def write_to_info(version):
path = "../info.plist"

with open(path, 'rb') as f:
contents = plistlib.load(f)

if not contents:
exit(-1)

contents["coreVersion"] = version
with open(path, 'wb') as f:
plistlib.dump(contents, f, sort_keys=False)


def run():
version = get_version()
print("current clash version:", version)
build_clash(version)
print("build static library complete!")
if os.environ.get("CI", False) or os.environ.get("GITHUB_ACTIONS", False):
print("writing info.plist")
write_to_info(version)
print("done")


if __name__ == "__main__":
run()
2 changes: 1 addition & 1 deletion ClashX/zh-Hans.lproj/Main.strings
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
/* Class = "NSTabViewItem"; label = "General"; ObjectID = "Ltt-Vq-Hh1"; */
"Ltt-Vq-Hh1.label" = "通用";

/* Class = "NSTextFieldCell"; title = "Bypass proxy settings for there Hosts & Domains"; ObjectID = "NPu-V9-f3r"; */
/* Class = "NSTextFieldCell"; title = "Bypass proxy settings for these Hosts & Domains"; ObjectID = "NPu-V9-f3r"; */
"NPu-V9-f3r.title" = "忽略这些主机与域的代理设置";

/* Class = "NSButtonCell"; title = "Launch at login"; ObjectID = "dV6-4Z-2SO"; */
Expand Down
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- Alamofire (5.6.2)
- Alamofire (5.6.4)
- CocoaLumberjack/Core (3.8.0)
- CocoaLumberjack/Swift (3.8.0):
- CocoaLumberjack/Core
Expand Down Expand Up @@ -55,7 +55,7 @@ SPEC REPOS:
- Yams

SPEC CHECKSUMS:
Alamofire: d368e1ff8a298e6dde360e35a3e68e6c610e7204
Alamofire: 4e95d97098eacb88856099c4fc79b526a299e48c
CocoaLumberjack: 78abfb691154e2a9df8ded4350d504ee19d90732
FlexibleDiff: b9ee9b8305b42c784f5dd40589203c97c55bbaa0
GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa
Expand Down
2 changes: 1 addition & 1 deletion ProxyConfigHelper/ProxyConfigHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ - (void)restoreProxyWithCurrentPort:(int)port
error:(stringReplyBlock)reply {
dispatch_async(dispatch_get_main_queue(), ^{
ProxySettingTool *tool = [ProxySettingTool new];
[tool restoreProxySettint:dict currentPort:port currentSocksPort:socksPort filterInterface:filterInterface];
[tool restoreProxySetting:dict currentPort:port currentSocksPort:socksPort filterInterface:filterInterface];
reply(nil);
});
}
Expand Down
Loading

0 comments on commit ee2e9d9

Please sign in to comment.