feature: add jsbridge support for break connection
This commit is contained in:
parent
648c9737ea
commit
0e2be2dac4
@ -15,10 +15,13 @@ class ConnectionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static var closeMenuItem: NSMenuItem?
|
||||||
|
|
||||||
static func addCloseOptionMenuItem(_ menu: inout NSMenu) {
|
static func addCloseOptionMenuItem(_ menu: inout NSMenu) {
|
||||||
let item = NSMenuItem(title: NSLocalizedString("Auto Close Connection", comment: ""), action: #selector(optionMenuItemTap(sender:)), keyEquivalent: "")
|
let item = NSMenuItem(title: NSLocalizedString("Auto Close Connection", comment: ""), action: #selector(optionMenuItemTap(sender:)), keyEquivalent: "")
|
||||||
item.target = ConnectionManager.self
|
item.target = ConnectionManager.self
|
||||||
menu.addItem(item)
|
menu.addItem(item)
|
||||||
|
closeMenuItem = item
|
||||||
updateMenuItemStatus(item)
|
updateMenuItemStatus(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,9 +41,9 @@ class ConnectionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension ConnectionManager {
|
extension ConnectionManager {
|
||||||
static func updateMenuItemStatus(_ item: NSMenuItem) {
|
static func updateMenuItemStatus(_ item: NSMenuItem? = closeMenuItem) {
|
||||||
item.state = enableAutoClose ? .on : .off
|
item?.state = enableAutoClose ? .on : .off
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc static func optionMenuItemTap(sender: NSMenuItem) {
|
@objc static func optionMenuItemTap(sender: NSMenuItem) {
|
||||||
|
@ -85,6 +85,20 @@ class JsBridgeUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bridge.registerHandler("getBreakConnections") { _, responseCallback in
|
||||||
|
responseCallback?(ConnectionManager.enableAutoClose)
|
||||||
|
}
|
||||||
|
|
||||||
|
bridge.registerHandler("setBreakConnections") { anydata, responseCallback in
|
||||||
|
if let enable = anydata as? Bool {
|
||||||
|
ConnectionManager.enableAutoClose = enable
|
||||||
|
ConnectionManager.updateMenuItemStatus()
|
||||||
|
responseCallback?(true)
|
||||||
|
} else {
|
||||||
|
responseCallback?(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bridge.registerHandler("speedTest") { anydata, responseCallback in
|
bridge.registerHandler("speedTest") { anydata, responseCallback in
|
||||||
if let proxyName = anydata as? String {
|
if let proxyName = anydata as? String {
|
||||||
ApiRequest.getProxyDelay(proxyName: proxyName) { delay in
|
ApiRequest.getProxyDelay(proxyName: proxyName) { delay in
|
||||||
|
Loading…
Reference in New Issue
Block a user