Support geoip database update

This commit is contained in:
yicheng 2019-12-31 21:41:52 +08:00
parent d6611b6057
commit 89bb7dde80
4 changed files with 46 additions and 0 deletions

View File

@ -347,6 +347,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
ConnectionManager.addCloseOptionMenuItem(&experimentalMenu)
AutoUpgardeManager.shared.setup()
AutoUpgardeManager.shared.addChanelMenuItem(&experimentalMenu)
ClashResourceManager.addUpdateMMDBMenuItem(&experimentalMenu)
if WebPortalManager.hasWebProtal {
WebPortalManager.shared.addWebProtalMenuItem(&statusMenu)
}

View File

@ -1,4 +1,5 @@
import Alamofire
import AppKit
import Foundation
@ -86,3 +87,29 @@ class ClashResourceManager {
NSApplication.shared.terminate(nil)
}
}
extension ClashResourceManager {
static func addUpdateMMDBMenuItem(_ menu: inout NSMenu) {
let item = NSMenuItem(title: NSLocalizedString("Update GEOIP Database", comment: ""), action: #selector(updateGeoIP), keyEquivalent: "")
item.target = self
menu.addItem(item)
}
@objc private static func updateGeoIP() {
let url = "https://static.clash.to/GeoIP2/GeoIP2-Country.mmdb"
AF.download(url) { (_, _) -> (destinationURL: URL, options: DownloadRequest.Options) in
let path = ClashResourceManager.kProxyConfigFolder.appending("/Country.mmdb")
return (URL(fileURLWithPath: path), .removePreviousFile)
}.response { res in
let title = NSLocalizedString("Update GEOIP Database", comment: "")
let info: String
switch res.result {
case .success:
info = NSLocalizedString("Success!", comment: "")
case let .failure(err):
info = NSLocalizedString("Fail:", comment: "") + err.localizedDescription
}
NSUserNotificationCenter.default.post(title: title, info: info)
}
}
}

View File

@ -44,6 +44,9 @@
/* No comment provided by engineer. */
"Download fail" = "Download fail";
/* No comment provided by engineer. */
"Fail:" = "Fail:";
/* No comment provided by engineer. */
"Global" = "Global";
@ -104,6 +107,9 @@
/* No comment provided by engineer. */
"Succees" = "Succees";
/* No comment provided by engineer. */
"Success!" = "Success!";
/* No comment provided by engineer. */
"Tap to reload config" = "Tap to reload config";
@ -113,6 +119,9 @@
/* No comment provided by engineer. */
"The remote config name is duplicated" = "The remote config name is duplicated";
/* No comment provided by engineer. */
"Update GEOIP Database" = "Update GEOIP Database";
/* No comment provided by engineer. */
"Updating" = "Updating";

View File

@ -44,6 +44,9 @@
/* No comment provided by engineer. */
"Download fail" = "下载失败";
/* No comment provided by engineer. */
"Fail:" = "失败:";
/* No comment provided by engineer. */
"Global" = "全局";
@ -104,6 +107,9 @@
/* No comment provided by engineer. */
"Succees" = "成功";
/* No comment provided by engineer. */
"Success!" = "成功!";
/* No comment provided by engineer. */
"Tap to reload config" = "点击重载配置文件";
@ -113,6 +119,9 @@
/* No comment provided by engineer. */
"The remote config name is duplicated" = "托管配置文件名称重复";
/* No comment provided by engineer. */
"Update GEOIP Database" = "更新IP数据库";
/* No comment provided by engineer. */
"Updating" = "更新中";