improve: add should quit check
# Conflicts: # ClashX/AppDelegate.swift # ClashX/Info.plist
This commit is contained in:
parent
f0810289d7
commit
5349a279ce
@ -112,12 +112,46 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
setupNetworkNotifier()
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ aNotification: Notification) {
|
||||
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
|
||||
let group = DispatchGroup()
|
||||
var shouldWait = false
|
||||
|
||||
if ConfigManager.shared.proxyPortAutoSet && !ConfigManager.shared.isProxySetByOtherVariable.value {
|
||||
Logger.log("ClashX quit need clean proxy setting")
|
||||
shouldWait = true
|
||||
group.enter()
|
||||
let port = ConfigManager.shared.currentConfig?.port ?? 0
|
||||
let socketPort = ConfigManager.shared.currentConfig?.socketPort ?? 0
|
||||
SystemProxyManager.shared.disableProxy(port: port, socksPort: socketPort)
|
||||
SystemProxyManager.shared.disableProxy(port: port, socksPort: socketPort) {
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
|
||||
if !shouldWait {
|
||||
Logger.log("ClashX quit without clean waiting")
|
||||
return .terminateNow
|
||||
}
|
||||
|
||||
statusItem.menu = nil
|
||||
|
||||
DispatchQueue.global(qos: .default).async {
|
||||
let res = group.wait(timeout: .now() + 5)
|
||||
switch res {
|
||||
case .success:
|
||||
Logger.log("ClashX quit after clean up finish")
|
||||
case .timedOut:
|
||||
Logger.log("ClashX quit after clean up timeout")
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
NSApp.reply(toApplicationShouldTerminate: true)
|
||||
}
|
||||
}
|
||||
|
||||
Logger.log("ClashX quit wait for clean up")
|
||||
return .terminateLater
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ aNotification: Notification) {
|
||||
UserDefaults.standard.set(0, forKey: "launch_fail_times")
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ class SystemProxyManager: NSObject {
|
||||
SystemProxyManager.shared.disableProxy(port: port, socksPort: socketPort)
|
||||
}
|
||||
|
||||
func disableProxy(port: Int, socksPort: Int, forceDisable: Bool = false) {
|
||||
func disableProxy(port: Int, socksPort: Int, forceDisable: Bool = false, complete: (() -> Void)? = nil) {
|
||||
Logger.log("disableProxy", level: .debug)
|
||||
|
||||
if disableRestoreProxy || forceDisable {
|
||||
@ -78,6 +78,7 @@ class SystemProxyManager: NSObject {
|
||||
if let error = error {
|
||||
Logger.log("disableProxy \(error)", level: .error)
|
||||
}
|
||||
complete?()
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -86,6 +87,7 @@ class SystemProxyManager: NSObject {
|
||||
if let error = error {
|
||||
Logger.log("restoreProxy \(error)", level: .error)
|
||||
}
|
||||
complete?()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -84,6 +84,10 @@
|
||||
<array>
|
||||
<string>identifier "com.west2online.ClashX" and anchor apple generic and certificate leaf[subject.CN] = "Mac Developer: chen yicheng (96U846XGYH)" and certificate 1[field.1.2.840.113635.100.6.2.1] /* exists */</string>
|
||||
</array>
|
||||
<key>NSSupportsAutomaticTermination</key>
|
||||
<false/>
|
||||
<key>NSSupportsSuddenTermination</key>
|
||||
<false/>
|
||||
<key>SMPrivilegedExecutables</key>
|
||||
<dict>
|
||||
<key>com.west2online.ClashX.ProxyConfigHelper</key>
|
||||
|
@ -30,7 +30,7 @@ class ProxyItemView: MenuItemBaseView {
|
||||
delayLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
nameLabel.font = type(of: self).labelFont
|
||||
delayLabel.font = NSFont.monospacedDigitSystemFont(ofSize: 10, weight: .regular)
|
||||
delayLabel.font = NSFont.monospacedDigitSystemFont(ofSize: 10, weight: .medium)
|
||||
nameLabel.alignment = .left
|
||||
delayLabel.alignment = .right
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user