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 2, 2024
2 parents dc8217a + 658d898 commit ff4d506
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 53 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ jobs:
build:
runs-on: macos-13
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: FranzDiebold/github-env-vars-action@v2

- name: download meta core
uses: robinraju/release-downloader@v1.8
uses: robinraju/release-downloader@v1.9
with:
repository: 'MetaCubeX/mihomo'
tag: "v1.18.0"
tag: "v1.18.1"
fileName: ".*darwin.*64-v.*.gz"

# releaseId: "62870807"
Expand All @@ -35,8 +33,8 @@ jobs:
/usr/libexec/PlistBuddy -c "Set CFBundleVersion $(git rev-list --count origin/master..origin/meta)" ClashX/Info.plist
/usr/libexec/PlistBuddy -c "Set CFBundleShortVersionString $(git describe --tags --abbrev=0)" ClashX/Info.plist
/usr/libexec/PlistBuddy -c "Add coreVersion string $(ls clash.meta | grep -m1 "" | sed -ne 's/.*64-\(.*\).gz/\1/p')" ClashX/Info.plist
/usr/libexec/PlistBuddy -c "Add gitBranch string $CI_ACTION_REF_NAME" ClashX/Info.plist
/usr/libexec/PlistBuddy -c "Add gitCommit string $CI_SHA_SHORT" ClashX/Info.plist
/usr/libexec/PlistBuddy -c "Add gitBranch string $GITHUB_REF_NAME" ClashX/Info.plist
/usr/libexec/PlistBuddy -c "Add gitCommit string ${GITHUB_SHA::7}" ClashX/Info.plist
/usr/libexec/PlistBuddy -c "Add buildTime string $(date +%Y-%m-%d\ %H:%M)" ClashX/Info.plist
/usr/libexec/PlistBuddy -c 'Print CFBundleVersion' ClashX/Info.plist
Expand All @@ -51,8 +49,8 @@ jobs:
/usr/libexec/PlistBuddy -c "Set CFBundleVersion $(git rev-list --count origin/master..origin/meta)" ClashX/ClashX\ Meta\ SwiftUI-Info.plist
/usr/libexec/PlistBuddy -c "Set CFBundleShortVersionString $(git describe --tags --abbrev=0)" ClashX/ClashX\ Meta\ SwiftUI-Info.plist
/usr/libexec/PlistBuddy -c "Add coreVersion string $(ls clash.meta | grep -m1 "" | sed -ne 's/.*64-\(.*\).gz/\1/p')" ClashX/ClashX\ Meta\ SwiftUI-Info.plist
/usr/libexec/PlistBuddy -c "Add gitBranch string $CI_ACTION_REF_NAME" ClashX/ClashX\ Meta\ SwiftUI-Info.plist
/usr/libexec/PlistBuddy -c "Add gitCommit string $CI_SHA_SHORT" ClashX/ClashX\ Meta\ SwiftUI-Info.plist
/usr/libexec/PlistBuddy -c "Add gitBranch string $GITHUB_REF_NAME" ClashX/ClashX\ Meta\ SwiftUI-Info.plist
/usr/libexec/PlistBuddy -c "Add gitCommit string ${GITHUB_SHA::7}" ClashX/ClashX\ Meta\ SwiftUI-Info.plist
/usr/libexec/PlistBuddy -c "Add buildTime string $(date +%Y-%m-%d\ %H:%M)" ClashX/ClashX\ Meta\ SwiftUI-Info.plist
/usr/libexec/PlistBuddy -c 'Print CFBundleVersion' ClashX/ClashX\ Meta\ SwiftUI-Info.plist
Expand Down Expand Up @@ -88,7 +86,7 @@ jobs:


- name: upload Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: "!startsWith(github.ref, 'refs/tags/')"
with:
name: "ClashX Meta.zip"
Expand Down
10 changes: 9 additions & 1 deletion ClashX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 53;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -32,6 +32,9 @@
01B2274B29B845F100FE35C9 /* country.mmdb.gz in Resources */ = {isa = PBXBuildFile; fileRef = 01B2274A29B845F100FE35C9 /* country.mmdb.gz */; };
01BC9ABE2928EB5A00F9B177 /* MetaDNS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01BC9ABD2928E5C600F9B177 /* MetaDNS.swift */; };
01C1462A28962E4E00346AF3 /* com.metacubex.ClashX.ProxyConfigHelper.meta.gz in Resources */ = {isa = PBXBuildFile; fileRef = 01C1462928962E4E00346AF3 /* com.metacubex.ClashX.ProxyConfigHelper.meta.gz */; };
01CA6BC02B6A1B3100E386D6 /* MetaServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01CA6BBF2B6A1B3100E386D6 /* MetaServer.swift */; };
01CA6BC12B6A1B3100E386D6 /* MetaServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01CA6BBF2B6A1B3100E386D6 /* MetaServer.swift */; };
01CA6BC22B6A1B3100E386D6 /* MetaServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01CA6BBF2B6A1B3100E386D6 /* MetaServer.swift */; };
01D567E32AD158B600CDA0AE /* MetaPrefs.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 01D567E12AD158B500CDA0AE /* MetaPrefs.storyboard */; };
01D567E42AD158B600CDA0AE /* MetaPrefs.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 01D567E12AD158B500CDA0AE /* MetaPrefs.storyboard */; };
01D567E52AD158B600CDA0AE /* MetaPrefsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01D567E22AD158B500CDA0AE /* MetaPrefsViewController.swift */; };
Expand Down Expand Up @@ -314,6 +317,7 @@
01B2274A29B845F100FE35C9 /* country.mmdb.gz */ = {isa = PBXFileReference; lastKnownFileType = archive.gzip; path = country.mmdb.gz; sourceTree = "<group>"; };
01BC9ABD2928E5C600F9B177 /* MetaDNS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetaDNS.swift; sourceTree = "<group>"; };
01C1462928962E4E00346AF3 /* com.metacubex.ClashX.ProxyConfigHelper.meta.gz */ = {isa = PBXFileReference; lastKnownFileType = archive.gzip; path = com.metacubex.ClashX.ProxyConfigHelper.meta.gz; sourceTree = "<group>"; };
01CA6BBF2B6A1B3100E386D6 /* MetaServer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetaServer.swift; sourceTree = "<group>"; };
01D567DF2AD1562700CDA0AE /* ClashX Meta SwiftUI-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "ClashX Meta SwiftUI-Info.plist"; sourceTree = "<group>"; };
01D567E12AD158B500CDA0AE /* MetaPrefs.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = MetaPrefs.storyboard; sourceTree = "<group>"; };
01D567E22AD158B500CDA0AE /* MetaPrefsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetaPrefsViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -778,6 +782,7 @@
498960722340F21C00AFB7EC /* com.metacubex.ClashX.ProxyConfigHelper.entitlements */,
019A239528657A7A00AE5698 /* main.swift */,
0162E74E2864B819007218A6 /* MetaTask.swift */,
01CA6BBF2B6A1B3100E386D6 /* MetaServer.swift */,
01BC9ABD2928E5C600F9B177 /* MetaDNS.swift */,
F935B2F12307C802009E4D33 /* Helper-Launchd.plist */,
F935B2EA2307B6BA009E4D33 /* Helper-Info.plist */,
Expand Down Expand Up @@ -994,6 +999,7 @@
files = (
01F335CD2AD10D0B0048AF77 /* UnsafePointer+bridge.swift in Sources */,
01F335CE2AD10D0B0048AF77 /* RemoteConfigViewController.swift in Sources */,
01CA6BC22B6A1B3100E386D6 /* MetaServer.swift in Sources */,
01F335CF2AD10D0B0048AF77 /* StatusItemTool.swift in Sources */,
01F335D02AD10D0B0048AF77 /* ClashResourceManager.swift in Sources */,
01F335D12AD10D0B0048AF77 /* ConfigFileManager.swift in Sources */,
Expand Down Expand Up @@ -1089,6 +1095,7 @@
files = (
49ABB749236B0F9E00535CD7 /* UnsafePointer+bridge.swift in Sources */,
499A485522ED707300F6C675 /* RemoteConfigViewController.swift in Sources */,
01CA6BC02B6A1B3100E386D6 /* MetaServer.swift in Sources */,
49D6A45229AEEC15006487EF /* StatusItemTool.swift in Sources */,
49CF3B5C20CE8068001EBF94 /* ClashResourceManager.swift in Sources */,
4952C3D02117027C004A4FA8 /* ConfigFileManager.swift in Sources */,
Expand Down Expand Up @@ -1187,6 +1194,7 @@
019A239628657A7A00AE5698 /* main.swift in Sources */,
491E6203258A424D00313AEF /* CommonUtils.m in Sources */,
01BC9ABE2928EB5A00F9B177 /* MetaDNS.swift in Sources */,
01CA6BC12B6A1B3100E386D6 /* MetaServer.swift in Sources */,
F935B2FA23083EE6009E4D33 /* ProxySettingTool.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
3 changes: 3 additions & 0 deletions ClashX/Actions/TerminalCleanUpAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ enum TerminalConfirmAction {
PrivilegedHelperManager.shared.helper()?.stopMeta()
PrivilegedHelperManager.shared.helper()?.updateTun(with: false)

let path = Paths.tempPath() + "/cacheConfigs"
try? FileManager.default.removeItem(atPath: path)

if ConfigManager.shared.proxyPortAutoSet && !ConfigManager.shared.isProxySetByOtherVariable.value || NetworkChangeNotifier.isCurrentSystemSetToClash(looser: true) ||
NetworkChangeNotifier.hasInterfaceProxySetToClash() {
Logger.log("ClashX quit need clean proxy setting")
Expand Down
25 changes: 11 additions & 14 deletions ClashX/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -777,33 +777,27 @@ extension AppDelegate {
case pushConfigFailed(String)
}

struct StartProxyResp: Codable {
let externalController: String
let secret: String
let log: String?
}

func startProxy() {
if ConfigManager.shared.isRunning { return }

Logger.log("Trying start meta core")

prepareConfigFile().then {
self.generateInitConfig()
}.then {
}.then {
self.startMeta($0)
}.get { res in
if let log = res.log {
if res.log != "" {
Logger.log("""
\n######## Clash Meta Start Log #########
\(log)
\(res.log)
######## END #########
""", level: .info)
}

let port = res.externalController.components(separatedBy: ":").last ?? "9090"
ConfigManager.shared.apiPort = port
ConfigManager.shared.apiSecret = res.secret
ConfigManager.shared.apiSecret = res.secret
ConfigManager.shared.isRunning = true
self.proxyModeMenuItem.isEnabled = true
self.dashboardMenuItem.isEnabled = true
Expand Down Expand Up @@ -893,16 +887,19 @@ extension AppDelegate {
}
}

func startMeta(_ config: ClashMetaConfig.Config) -> Promise<StartProxyResp> {
func startMeta(_ config: ClashMetaConfig.Config) -> Promise<MetaServer> {
.init { resolver in
let confJSON = MetaServer(externalController: config.externalController, secret: config.secret ?? "").jsonString()

PrivilegedHelperManager.shared.helper {
Logger.log("helperNotFound, startMeta failed", level: .error)
resolver.reject(StartMetaError.helperNotFound)
}?.startMeta(withConfPath: kConfigFolderPath,
confFilePath: config.path) {
confFilePath: config.path,
confJSON: confJSON) {
if let string = $0 {
guard let jsonData = string.data(using: .utf8),
let res = try? JSONDecoder().decode(StartProxyResp.self, from: jsonData) else {
let res = try? JSONDecoder().decode(MetaServer.self, from: jsonData) else {
resolver.reject(StartMetaError.startMetaFailed(string))
return
}
Expand Down
4 changes: 4 additions & 0 deletions ClashX/General/Managers/MenuItemFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class MenuItemFactory {
guard let menu = menu else {
continue
}

if let hidden = proxy.hidden, hidden {
continue
}

switch hideState {
case .mixed where [.urltest, .fallback, .loadBalance, .relay].contains(proxy.type):
Expand Down
10 changes: 9 additions & 1 deletion ClashX/Macro/Paths.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ enum Paths {
}

static func tempPath() -> String {
NSTemporaryDirectory().appending("com.MetaCubeX.ClashX.meta")
guard let url = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)
.first?
.appendingPathComponent("com.MetaCubeX.ClashX.meta") else {
return NSTemporaryDirectory().appending("com.MetaCubeX.ClashX.meta")
}

try? FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)

return url.path
}
}
6 changes: 4 additions & 2 deletions ClashX/Models/ClashProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ enum ClashProxyType: String, Codable, CaseIterable {

static func isBuiltInProxy(_ proxy: ClashProxy) -> Bool {
switch proxy.name {
case "DIRECT", "REJECT", "PASS": return true
case "DIRECT", "REJECT", "REJECT-DROP", "PASS", "COMPATIBLE": return true
default: return false
}
}
Expand Down Expand Up @@ -108,6 +108,8 @@ class ClashProxy: Codable {
let alive: Bool?
weak var enclosingResp: ClashProxyResp?
weak var enclosingProvider: ClashProvider?

let hidden: Bool?

enum SpeedtestAbleItem {
case proxy(name: ClashProxyName)
Expand Down Expand Up @@ -138,7 +140,7 @@ class ClashProxy: Codable {
lazy var isSpeedTestable: Bool = !speedtestAble.isEmpty

private enum CodingKeys: String, CodingKey {
case type, all, history, now, name, alive
case type, all, history, now, name, alive, hidden
}

lazy var maxProxyNameLength: CGFloat = {
Expand Down
15 changes: 15 additions & 0 deletions ClashX/Views/ProxyItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ class ProxyItemView: MenuItemBaseView {
let nameLabel: NSTextField
let delayLabel: NSTextField
var imageView: NSImageView?

let isBuiltInProxy: Bool

static let fixedPlaceHolderWidth: CGFloat = 20 + 50 + 25

init(proxy: ClashProxy) {
isBuiltInProxy = ClashProxyType.isBuiltInProxy(proxy)

nameLabel = VibrancyTextField(labelWithString: proxy.name)
delayLabel = VibrancyTextField(labelWithString: "").setup(allowsVibrancy: false)
let cell = PaddedNSTextFieldCell()
Expand Down Expand Up @@ -63,8 +67,19 @@ class ProxyItemView: MenuItemBaseView {
width: delayLabel.bounds.width,
height: delayLabel.bounds.height)
}

func updateBuiltIn() {
delayLabel.stringValue = "IN"
needsLayout = true
delayLabel.layer?.backgroundColor = NSColor.systemBlue.cgColor
}

func update(str: String?, value: Int?) {
guard !isBuiltInProxy else {
updateBuiltIn()
return
}

delayLabel.stringValue = str ?? ""
needsLayout = true

Expand Down
4 changes: 2 additions & 2 deletions ProxyConfigHelper/Helper-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<key>CFBundleName</key>
<string>com.metacubex.ClashX.ProxyConfigHelper</string>
<key>CFBundleShortVersionString</key>
<string>1.8</string>
<string>1.11</string>
<key>CFBundleVersion</key>
<string>18</string>
<string>21</string>
<key>SMAuthorizedClients</key>
<array>
<string>anchor apple generic and identifier &quot;com.metacubex.ClashX.ProxyConfigHelper&quot; and (certificate leaf[field.1.2.840.113635.100.6.1.9] /* exists */ or certificate 1[field.1.2.840.113635.100.6.2.6] /* exists */ and certificate leaf[field.1.2.840.113635.100.6.1.13] /* exists */ and certificate leaf[subject.OU] = MEWHFZ92DY)</string>
Expand Down
25 changes: 25 additions & 0 deletions ProxyConfigHelper/MetaServer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// MetaServer.swift
// ClashX
//
// Copyright © 2024 west2online. All rights reserved.
//

import Cocoa

struct MetaServer: Codable {
var externalController: String
let secret: String
var log: String = ""

func jsonString() -> String {
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted

guard let data = try? encoder.encode(self),
let string = String(data: data, encoding: .utf8) else {
return ""
}
return string
}
}
25 changes: 5 additions & 20 deletions ProxyConfigHelper/MetaTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,6 @@ import Cocoa

class MetaTask: NSObject {

struct MetaServer: Encodable {
var externalController: String
let secret: String
var log: String = ""

func jsonString() -> String {
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted

guard let data = try? encoder.encode(self),
let string = String(data: data, encoding: .utf8) else {
return ""
}
return string
}
}

struct MetaCurl: Decodable {
let hello: String
}
Expand All @@ -38,8 +21,9 @@ class MetaTask: NSObject {
}

@objc func start(_ confPath: String,
confFilePath: String,
result: @escaping stringReplyBlock) {
confFilePath: String,
confJSON: String,
result: @escaping stringReplyBlock) {

var resultReturned = false

Expand Down Expand Up @@ -73,7 +57,8 @@ class MetaTask: NSObject {
print("Test meta config success.")
}

guard var serverResult = self.parseConfFile(confPath, confFilePath: confFilePath) else {
guard let confData = confJSON.data(using: .utf8),
var serverResult = try? JSONDecoder().decode(MetaServer.self, from: confData) else {
returnResult("Can't decode config file.")
return
}
Expand Down
5 changes: 2 additions & 3 deletions ProxyConfigHelper/ProxyConfigHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,9 @@ - (void)initMetaCoreWithPath:(NSString *)path {
});
}


- (void)startMetaWithConfPath:(NSString *)confPath ConfFilePath:(NSString *)confFilePath result:(stringReplyBlock)reply {
- (void)startMetaWithConfPath:(NSString *)confPath ConfFilePath:(NSString *)confFilePath ConfJSON:(NSString *)confJSON result:(stringReplyBlock)reply {
dispatch_async(dispatch_get_main_queue(), ^{
[self.metaTask start:confPath confFilePath:confFilePath result:reply];
[self.metaTask start:confPath confFilePath:confFilePath confJSON:confJSON result:reply];
});
}

Expand Down
1 change: 1 addition & 0 deletions ProxyConfigHelper/ProxyConfigRemoteProcessProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ typedef void(^dictReplyBlock)(NSDictionary *);

- (void)startMetaWithConfPath:(NSString *)confPath
ConfFilePath:(NSString *)confFilePath
ConfJSON:(NSString *)confJSON
result:(stringReplyBlock)reply;

- (void)verifyMetaWithConfPath:(NSString *)confPath
Expand Down

0 comments on commit ff4d506

Please sign in to comment.