diff --git a/ClashX/AppDelegate.swift b/ClashX/AppDelegate.swift index 680f192..cf8f7f2 100644 --- a/ClashX/AppDelegate.swift +++ b/ClashX/AppDelegate.swift @@ -73,8 +73,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { var dashboardWindowController: ClashWebViewWindowController? func applicationWillFinishLaunching(_ notification: Notification) { + Logger.log("applicationWillFinishLaunching") signal(SIGPIPE, SIG_IGN) - // crash recorder failLaunchProtect() NSAppleEventManager.shared() .setEventHandler(self, @@ -103,13 +103,13 @@ class AppDelegate: NSObject, NSApplicationDelegate { statusItemView.updateSize(width: statusItemLengthWithSpeed) statusMenu.delegate = self - registCrashLogger() DispatchQueue.main.async { self.postFinishLaunching() } } func postFinishLaunching() { + Logger.log("postFinishLaunching") defer { statusItem.menu = statusMenu DispatchQueue.main.asyncAfter(deadline: .now()+1) { @@ -144,6 +144,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { RemoteConfigManager.shared.autoUpdateCheck() setupNetworkNotifier() + registCrashLogger() } func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply { @@ -1420,7 +1421,8 @@ extension AppDelegate { #else DispatchQueue.main.asyncAfter(deadline: .now() + 5) { AppCenter.start(withAppSecret: "dce6e9a3-b6e3-4fd2-9f2d-35c767a99663", services: [ - Analytics.self + Analytics.self, + Crashes.self ]) } diff --git a/ClashX/General/ApiRequest.swift b/ClashX/General/ApiRequest.swift index 3cc86c5..64e6c59 100644 --- a/ClashX/General/ApiRequest.swift +++ b/ClashX/General/ApiRequest.swift @@ -460,7 +460,7 @@ extension ApiRequest { private func requestTrafficInfo() { trafficWebSocketRetryTimer?.invalidate() trafficWebSocketRetryTimer = nil - trafficWebSocket?.disconnect(forceTimeout: 0, closeCode: 0) + trafficWebSocket?.disconnect(forceTimeout: 0.5) let socket = WebSocket(url: URL(string: ConfigManager.apiUrl.appending("/traffic"))!) @@ -475,7 +475,7 @@ extension ApiRequest { private func requestLog() { loggingWebSocketRetryTimer?.invalidate() loggingWebSocketRetryTimer = nil - loggingWebSocket?.disconnect() + loggingWebSocket?.disconnect(forceTimeout: 1) let uriString = "/logs?level=".appending(ConfigManager.selectLoggingApiLevel.rawValue) let socket = WebSocket(url: URL(string: ConfigManager.apiUrl.appending(uriString))!) diff --git a/ClashX/Models/ClashConfig.swift b/ClashX/Models/ClashConfig.swift index aa8c756..c23aa4b 100644 --- a/ClashX/Models/ClashConfig.swift +++ b/ClashX/Models/ClashConfig.swift @@ -26,7 +26,7 @@ extension ClashProxyMode { enum ClashLogLevel: String, Codable { case info - case warning = "warn" + case warning case error case debug case silent diff --git a/ClashX/ViewControllers/ClashWebViewContoller.swift b/ClashX/ViewControllers/ClashWebViewContoller.swift index 36fce56..8282fac 100644 --- a/ClashX/ViewControllers/ClashWebViewContoller.swift +++ b/ClashX/ViewControllers/ClashWebViewContoller.swift @@ -216,12 +216,23 @@ class CustomWKWebView: WKWebView { var dragableAreaHeight: CGFloat = 30 let alwaysDragableLeftAreaWidth: CGFloat = 150 - override func mouseDown(with event: NSEvent) { - super.mouseDown(with: event) + private func isInDargArea(with event:NSEvent?) -> Bool { + guard let event = event else { return false } let x = event.locationInWindow.x let y = (window?.frame.size.height ?? 0) - event.locationInWindow.y + return x < alwaysDragableLeftAreaWidth || y < dragableAreaHeight + } - if x < alwaysDragableLeftAreaWidth || y < dragableAreaHeight { + override func acceptsFirstMouse(for event: NSEvent?) -> Bool { + if isInDargArea(with: event) { + return true + } + return super.acceptsFirstMouse(for: event) + } + + override func mouseDown(with event: NSEvent) { + super.mouseDown(with: event) + if isInDargArea(with: event) { window?.performDrag(with: event) } }