add appcenter

This commit is contained in:
yicheng 2020-03-13 18:17:34 +08:00
parent f7eb634a9d
commit 98ce79584f
11 changed files with 73 additions and 52 deletions

1
.gitignore vendored
View File

@ -10,3 +10,4 @@ ClashX.app
.idea
*.pyc
ClashX/clash/
.DS_Store

View File

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

View File

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

View File

@ -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: "")

View File

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

View File

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

View File

@ -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() {

View File

@ -98,9 +98,6 @@ class StatusItemView: NSView {
}
func updateStatusItemView() {
if #available(macOS 10.14, *) {} else {
layout()
}
statusItem?.updateImage(withView: self)
}
}

View File

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

View File

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

View File

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