Feature: show error description for error config file.

This commit is contained in:
yicheng 2018-08-19 12:57:15 +08:00
parent a61e4955a7
commit 39303bcddd
3 changed files with 33 additions and 10 deletions

View File

@ -35,6 +35,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let ssQueue = DispatchQueue(label: "com.w2fzu.ssqueue", attributes: .concurrent)
var statusItemView:StatusItemView!
var isRunning = false
func applicationDidFinishLaunching(_ aNotification: Notification) {
signal(SIGPIPE, SIG_IGN)
failLaunchProtect()
@ -197,11 +199,21 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func startProxy() {
ssQueue.async {
run()
if self.isRunning {return}
self.isRunning = true
print("Trying start proxy")
if let cstring = run() {
// self.isRunning = false
let error = String(cString: cstring)
if (error != "success") {
NSUserNotificationCenter.default.postConfigErrorNotice(msg:error)
} else {
self.resetStreamApi()
self.selectOutBoundModeWithMenory()
}
}
self.resetStreamApi()
self.selectOutBoundModeWithMenory()
}
func syncConfig(){
@ -272,17 +284,19 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
@IBAction func actionUpdateConfig(_ sender: Any) {
ApiRequest.requestConfigUpdate() { [unowned self] success in
if (success) {
ApiRequest.requestConfigUpdate() { [unowned self] error in
if (error == nil) {
self.syncConfig()
self.resetStreamApi()
self.selectProxyGroupWithMemory()
self.selectOutBoundModeWithMenory()
NSUserNotificationCenter
.default
.post(title: "Reload Config Succeed", info: "succees")
} else {
NSUserNotificationCenter
.default
.post(title: "Reload Config Fail", info: "Please Check Config Fils")
.post(title: "Reload Config Fail", info: error ?? "")
}
}

View File

@ -32,6 +32,10 @@ extension NSUserNotificationCenter {
self.post(title: "\(api) api connect error!", info: "Use reload config to try reconnect.")
}
func postConfigErrorNotice(msg:String) {
self.post(title: "Config loading Fail!", info: msg)
}
}
class UserNotificationCenterDelegate:NSObject,NSUserNotificationCenterDelegate {

View File

@ -94,9 +94,14 @@ class ApiRequest{
}
}
static func requestConfigUpdate(callback:@escaping ((Bool)->())){
let success = updateAllConfig()
callback(success==0)
static func requestConfigUpdate(callback:@escaping ((String?)->())){
if let errMSg = updateAllConfig() {
let err = String(cString: errMSg)
callback(err == "" ? nil : err)
} else {
callback("unknown error")
}
}
static func updateOutBoundMode(mode:ClashProxyMode, callback:@escaping ((Bool)->())) {