diff --git a/.gitignore b/.gitignore index d00b715..679a6d4 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ ClashX.app .idea *.pyc ClashX/clash/ +.DS_Store diff --git a/ClashX/AppDelegate.swift b/ClashX/AppDelegate.swift index a7e5597..24f98ac 100644 --- a/ClashX/AppDelegate.swift +++ b/ClashX/AppDelegate.swift @@ -12,6 +12,8 @@ import LetsMove import RxCocoa import RxSwift +import AppCenter +import AppCenterAnalytics import Crashlytics import Fabric @@ -605,6 +607,12 @@ extension AppDelegate { return #else Fabric.with([Crashlytics.self]) + DispatchQueue.main.asyncAfter(deadline: .now() + 5) { + MSAppCenter.start("dce6e9a3-b6e3-4fd2-9f2d-35c767a99663", withServices: [ + MSAnalytics.self, + ]) + } + #endif } diff --git a/ClashX/Extensions/AppDelegate+..swift b/ClashX/Extensions/AppDelegate+..swift index 5f227cd..167f2d5 100644 --- a/ClashX/Extensions/AppDelegate+..swift +++ b/ClashX/Extensions/AppDelegate+..swift @@ -11,4 +11,11 @@ extension AppDelegate { static var shared: AppDelegate { return NSApplication.shared.delegate as! AppDelegate } + + static var isAboveMacOS14: Bool { + if #available(macOS 10.14, *) { + return true + } + return false + } } diff --git a/ClashX/General/Managers/ClashResourceManager.swift b/ClashX/General/Managers/ClashResourceManager.swift index f8f6e11..b9ffa00 100644 --- a/ClashX/General/Managers/ClashResourceManager.swift +++ b/ClashX/General/Managers/ClashResourceManager.swift @@ -42,7 +42,6 @@ class ClashResourceManager { } } - static func showCreateConfigDirFailAlert() { let alert = NSAlert() alert.messageText = NSLocalizedString("ClashX fail to create ~/.config/clash folder. Please check privileges or manually create folder and restart ClashX.", comment: "") diff --git a/ClashX/General/Managers/ConfigManager.swift b/ClashX/General/Managers/ConfigManager.swift index 56d069e..093bdd9 100644 --- a/ClashX/General/Managers/ConfigManager.swift +++ b/ClashX/General/Managers/ConfigManager.swift @@ -17,16 +17,6 @@ class ConfigManager { var apiPort = "8080" var apiSecret: String = "" - init() { - let defaultValue: Bool - if #available(macOS 10.14, *) { - defaultValue = false - } else { - defaultValue = true - } - disableShowCurrentProxyInMenu = UserDefaults.standard.object(forKey: "kSDisableShowCurrentProxyInMenu") as? Bool ?? defaultValue - } - var currentConfig: ClashConfig? { get { return currentConfigVariable.value @@ -141,7 +131,7 @@ class ConfigManager { } } - var disableShowCurrentProxyInMenu: Bool { + var disableShowCurrentProxyInMenu: Bool = UserDefaults.standard.object(forKey: "kSDisableShowCurrentProxyInMenu") as? Bool ?? !AppDelegate.isAboveMacOS14 { didSet { UserDefaults.standard.set(disableShowCurrentProxyInMenu, forKey: "kSDisableShowCurrentProxyInMenu") } diff --git a/ClashX/General/Managers/MenuItemFactory.swift b/ClashX/General/Managers/MenuItemFactory.swift index 7df71d0..5f9bc21 100644 --- a/ClashX/General/Managers/MenuItemFactory.swift +++ b/ClashX/General/Managers/MenuItemFactory.swift @@ -12,7 +12,7 @@ import SwiftyJSON class MenuItemFactory { private static var cachedProxyMenuItem: [NSMenuItem]? - private static var showSpeedTestItemAtTop: Bool = UserDefaults.standard.object(forKey: "kShowSpeedTestItemAtTop") as? Bool ?? true { + private static var showSpeedTestItemAtTop: Bool = UserDefaults.standard.object(forKey: "kShowSpeedTestItemAtTop") as? Bool ?? AppDelegate.isAboveMacOS14 { didSet { UserDefaults.standard.set(showSpeedTestItemAtTop, forKey: "kShowSpeedTestItemAtTop") } @@ -35,33 +35,51 @@ class MenuItemFactory { completionHandler?(cached) } + let group = DispatchGroup() + group.enter() + group.enter() + + var provider: ClashProviderResp? + var proxyInfo: ClashProxyResp? + + group.notify(queue: .main) { + guard let proxyInfo = proxyInfo, let proxyprovider = provider else { + assertionFailure() + return + } + proxyInfo.updateProvider(proxyprovider) + + var menuItems = [NSMenuItem]() + for proxy in proxyInfo.proxyGroups { + var menu: NSMenuItem? + switch proxy.type { + case .select: menu = self.generateSelectorMenuItem(proxyGroup: proxy, proxyInfo: proxyInfo) + case .urltest, .fallback: menu = generateUrlTestFallBackMenuItem(proxyGroup: proxy, proxyInfo: proxyInfo) + case .loadBalance: + menu = generateLoadBalanceMenuItem(proxyGroup: proxy, proxyInfo: proxyInfo) + default: continue + } + + if let menu = menu { + menuItems.append(menu) + menu.isEnabled = true + } + } + let items = Array(menuItems.reversed()) + cachedProxyMenuItem = items + completionHandler?(items) + } + ApiRequest.requestProxyProviderList { proxyprovider in + provider = proxyprovider + group.leave() + } - ApiRequest.requestProxyGroupList { - proxyInfo in - proxyInfo.updateProvider(proxyprovider) - - var menuItems = [NSMenuItem]() - for proxy in proxyInfo.proxyGroups { - var menu: NSMenuItem? - switch proxy.type { - case .select: menu = self.generateSelectorMenuItem(proxyGroup: proxy, proxyInfo: proxyInfo) - case .urltest, .fallback: menu = generateUrlTestFallBackMenuItem(proxyGroup: proxy, proxyInfo: proxyInfo) - case .loadBalance: - menu = generateLoadBalanceMenuItem(proxyGroup: proxy, proxyInfo: proxyInfo) - default: continue - } - - if let menu = menu { - menuItems.append(menu) - menu.isEnabled = true - } - } - let items = Array(menuItems.reversed()) - cachedProxyMenuItem = items - completionHandler?(items) - } + ApiRequest.requestProxyGroupList { + proxy in + proxyInfo = proxy + group.leave() } } diff --git a/ClashX/ViewControllers/ClashWebViewContoller.swift b/ClashX/ViewControllers/ClashWebViewContoller.swift index 47f8784..901a39c 100644 --- a/ClashX/ViewControllers/ClashWebViewContoller.swift +++ b/ClashX/ViewControllers/ClashWebViewContoller.swift @@ -102,7 +102,7 @@ class ClashWebViewContoller: NSViewController { view.window?.styleMask.insert(.resizable) view.window?.styleMask.insert(.miniaturizable) view.window?.center() - + view.window?.minSize = minSize if NSApp.activationPolicy() == .accessory { @@ -114,12 +114,11 @@ class ClashWebViewContoller: NSViewController { view.addSubview(effectView) view.addSubview(webview) } - + override func viewDidLayout() { super.viewDidLayout() effectView.frame = view.bounds webview.frame = view.bounds - } func loadWebRecourses() { diff --git a/ClashX/Views/StatusItemView.swift b/ClashX/Views/StatusItemView.swift index 9773195..b24fe01 100644 --- a/ClashX/Views/StatusItemView.swift +++ b/ClashX/Views/StatusItemView.swift @@ -98,9 +98,6 @@ class StatusItemView: NSView { } func updateStatusItemView() { - if #available(macOS 10.14, *) {} else { - layout() - } statusItem?.updateImage(withView: self) } } diff --git a/Podfile b/Podfile index 85fca37..4db31f8 100644 --- a/Podfile +++ b/Podfile @@ -21,9 +21,8 @@ target 'ClashX' do pod 'CocoaLumberjack/Swift' pod 'WebViewJavascriptBridge' pod 'Starscream','3.1.1' - pod 'Fabric' + pod 'AppCenter/Analytics' pod 'Crashlytics' pod 'Sparkle' - end diff --git a/Podfile.lock b/Podfile.lock index 116d4cf..627911b 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,5 +1,8 @@ PODS: - Alamofire (5.0.2) + - AppCenter/Analytics (3.0.0): + - AppCenter/Core + - AppCenter/Core (3.0.0) - CocoaLumberjack/Core (3.6.1) - CocoaLumberjack/Swift (3.6.1): - CocoaLumberjack/Core @@ -20,9 +23,9 @@ PODS: DEPENDENCIES: - Alamofire (~> 5.0) + - AppCenter/Analytics - CocoaLumberjack/Swift - Crashlytics - - Fabric - LetsMove - RxCocoa - RxSwift @@ -34,6 +37,7 @@ DEPENDENCIES: SPEC REPOS: https://cdn.cocoapods.org/: - Alamofire + - AppCenter - CocoaLumberjack - Crashlytics - Fabric @@ -48,6 +52,7 @@ SPEC REPOS: SPEC CHECKSUMS: Alamofire: 3ba7a4db18b4f62c4a1c0e1cb39d7f3d52e10ada + AppCenter: 7a0bbe928d07467ac8b2d7f6f2a675872a6471d8 CocoaLumberjack: b17ae15142558d08bbacf69775fa10c4abbebcc9 Crashlytics: 540b7e5f5da5a042647227a5e3ac51d85eed06df Fabric: 706c8b8098fff96c33c0db69cbf81f9c551d0d74 @@ -60,6 +65,6 @@ SPEC CHECKSUMS: SwiftyJSON: 36413e04c44ee145039d332b4f4e2d3e8d6c4db7 WebViewJavascriptBridge: 7f5bc4d3581e672e8f32bd0f812d54bc69bb8e29 -PODFILE CHECKSUM: b104b5e59f0be7cdf17282b19ab5917132171e6f +PODFILE CHECKSUM: 0e50d93c7f4d302a0c99f40db22ed72fd71b4557 COCOAPODS: 1.7.5 diff --git a/README.md b/README.md index 97eb9b1..891bdd5 100644 --- a/README.md +++ b/README.md @@ -23,15 +23,13 @@ A rule based proxy For Mac base on [Clash](https://github.com/Dreamacro/clash). You can download from [release](https://github.com/yichengchen/clashX/releases) page ## Build +- Make sure have python3 and golang installed in your computer. + - Download deps ``` bash install_dependency.sh ``` -- Build clash core. - ``` - cd ClashX - python3 build_clash.py - ``` + - Build and run. ## Config