diff --git a/ClashX/AppDelegate.swift b/ClashX/AppDelegate.swift index c170fb8..d83fda2 100644 --- a/ClashX/AppDelegate.swift +++ b/ClashX/AppDelegate.swift @@ -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) } diff --git a/ClashX/General/Managers/ClashResourceManager.swift b/ClashX/General/Managers/ClashResourceManager.swift index 5c8a4f4..4967557 100644 --- a/ClashX/General/Managers/ClashResourceManager.swift +++ b/ClashX/General/Managers/ClashResourceManager.swift @@ -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) + } + } +} diff --git a/ClashX/Support Files/en.lproj/Localizable.strings b/ClashX/Support Files/en.lproj/Localizable.strings index db8dde8..9918f4c 100644 --- a/ClashX/Support Files/en.lproj/Localizable.strings +++ b/ClashX/Support Files/en.lproj/Localizable.strings @@ -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"; diff --git a/ClashX/Support Files/zh-Hans.lproj/Localizable.strings b/ClashX/Support Files/zh-Hans.lproj/Localizable.strings index 2dedcb1..0962b3b 100644 --- a/ClashX/Support Files/zh-Hans.lproj/Localizable.strings +++ b/ClashX/Support Files/zh-Hans.lproj/Localizable.strings @@ -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" = "更新中";