diff --git a/.DS_Store b/.DS_Store index 7d2b2d0..fc88411 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/HostsToolForMac/HostsToolForMac.xcodeproj/project.pbxproj b/HostsToolForMac/HostsToolForMac.xcodeproj/project.pbxproj index f28de16..e82191f 100644 --- a/HostsToolForMac/HostsToolForMac.xcodeproj/project.pbxproj +++ b/HostsToolForMac/HostsToolForMac.xcodeproj/project.pbxproj @@ -9,19 +9,21 @@ /* Begin PBXBuildFile section */ 1F1AB29B1E666D9F00171458 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F1AB29A1E666D9F00171458 /* AppDelegate.swift */; }; 1F1AB29D1E666D9F00171458 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1F1AB29C1E666D9F00171458 /* Assets.xcassets */; }; - 1F1AB2A01E666DA000171458 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1F1AB29E1E666DA000171458 /* MainMenu.xib */; }; 1F2396D320B5065E00618BB8 /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F2396D220B5065E00618BB8 /* MainMenu.swift */; }; 1F338EBF1E696A1D004A3265 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 1F338EC11E696A1D004A3265 /* Localizable.strings */; }; 1FA54A9A20B2BAB5005B2515 /* Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FA54A9920B2BAB5005B2515 /* Helper.swift */; }; 1FA54AA420B2BD52005B2515 /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FA54AA320B2BD52005B2515 /* Network.swift */; }; 980E5FA62378359900EEF756 /* Foundation+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 980E5FA52378359900EEF756 /* Foundation+Extension.swift */; }; - 984F41E22446E22000ED4EB9 /* SettingsPanel.xib in Resources */ = {isa = PBXBuildFile; fileRef = 984F41E12446E22000ED4EB9 /* SettingsPanel.xib */; }; + 982DA17825636C6E008173F8 /* DownloadPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 982DA17725636C6E008173F8 /* DownloadPanel.swift */; }; + 982DA17D25636FFB008173F8 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 982DA17F25636FFB008173F8 /* MainMenu.xib */; }; + 982DA1852563A396008173F8 /* SettingsPanel.xib in Resources */ = {isa = PBXBuildFile; fileRef = 982DA1872563A396008173F8 /* SettingsPanel.xib */; }; + 982DA1932563A712008173F8 /* DownloadPanel.xib in Resources */ = {isa = PBXBuildFile; fileRef = 982DA1952563A712008173F8 /* DownloadPanel.xib */; }; 98A85E0A237CF3D4006DA99F /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A85E09237CF3D4006DA99F /* Constant.swift */; }; 98A85E0C237CFD72006DA99F /* AppDelegate+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A85E0B237CFD72006DA99F /* AppDelegate+Extension.swift */; }; 98D9FA6723BAE523008DD433 /* SettingsPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98D9FA6623BAE523008DD433 /* SettingsPanel.swift */; }; 98D9FA6B23BAE6AD008DD433 /* AppKit+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98D9FA6A23BAE6AD008DD433 /* AppKit+Extension.swift */; }; 98D9FA6D23BB3493008DD433 /* Hosts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98D9FA6C23BB3493008DD433 /* Hosts.swift */; }; - B3E94D772B692099C453B883 /* libPods-HostsToolForMac.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DE7430F5CFA6F986E2407DCD /* libPods-HostsToolForMac.a */; }; + C437A074FFC4A0B0A6CC1937 /* Pods_HostsToolForMac.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 23456CEF06BD9B7F2246B07E /* Pods_HostsToolForMac.framework */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -40,7 +42,6 @@ 0B523D9EBF2E1DFF49704BB3 /* Pods-HostsToolForMac.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HostsToolForMac.release.xcconfig"; path = "Target Support Files/Pods-HostsToolForMac/Pods-HostsToolForMac.release.xcconfig"; sourceTree = ""; }; 1F1AB29A1E666D9F00171458 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 1F1AB29C1E666D9F00171458 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 1F1AB29F1E666DA000171458 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; 1F1AB2A11E666DA000171458 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 1F2396D220B5065E00618BB8 /* MainMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenu.swift; sourceTree = ""; }; 1F338EC21E696A1F004A3265 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; @@ -48,15 +49,21 @@ 1FA54A9620B2BA72005B2515 /* HostsToolForMac.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HostsToolForMac.app; sourceTree = BUILT_PRODUCTS_DIR; }; 1FA54A9920B2BAB5005B2515 /* Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helper.swift; sourceTree = ""; }; 1FA54AA320B2BD52005B2515 /* Network.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Network.swift; sourceTree = ""; }; + 23456CEF06BD9B7F2246B07E /* Pods_HostsToolForMac.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HostsToolForMac.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 980E5FA52378359900EEF756 /* Foundation+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Foundation+Extension.swift"; sourceTree = ""; }; - 984F41E12446E22000ED4EB9 /* SettingsPanel.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SettingsPanel.xib; sourceTree = ""; }; + 982DA17725636C6E008173F8 /* DownloadPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadPanel.swift; sourceTree = ""; }; + 982DA1832563703B008173F8 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "zh-Hans"; path = "zh-Hans.lproj/MainMenu.xib"; sourceTree = ""; }; + 982DA18425637048008173F8 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = ""; }; + 982DA1862563A396008173F8 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/SettingsPanel.xib; sourceTree = ""; }; + 982DA18A2563A3A0008173F8 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "zh-Hans"; path = "zh-Hans.lproj/SettingsPanel.xib"; sourceTree = ""; }; + 982DA19A2563A71E008173F8 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/DownloadPanel.xib; sourceTree = ""; }; + 982DA19E2563B7E6008173F8 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "zh-Hans"; path = "zh-Hans.lproj/DownloadPanel.xib"; sourceTree = ""; }; 986A75BE23B7763000815C9D /* HostsToolForMac.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HostsToolForMac.entitlements; sourceTree = ""; }; 98A85E09237CF3D4006DA99F /* Constant.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; 98A85E0B237CFD72006DA99F /* AppDelegate+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+Extension.swift"; sourceTree = ""; }; 98D9FA6623BAE523008DD433 /* SettingsPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsPanel.swift; sourceTree = ""; }; 98D9FA6A23BAE6AD008DD433 /* AppKit+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppKit+Extension.swift"; sourceTree = ""; }; 98D9FA6C23BB3493008DD433 /* Hosts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Hosts.swift; sourceTree = ""; }; - DE7430F5CFA6F986E2407DCD /* libPods-HostsToolForMac.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-HostsToolForMac.a"; sourceTree = BUILT_PRODUCTS_DIR; }; F9C9A81E32EF5EDE9CF0BDEB /* Pods-HostsToolForMac.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HostsToolForMac.debug.xcconfig"; path = "Target Support Files/Pods-HostsToolForMac/Pods-HostsToolForMac.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -65,7 +72,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - B3E94D772B692099C453B883 /* libPods-HostsToolForMac.a in Frameworks */, + C437A074FFC4A0B0A6CC1937 /* Pods_HostsToolForMac.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -75,7 +82,7 @@ 1C8C76E1E2F19A023C7DB35B /* Frameworks */ = { isa = PBXGroup; children = ( - DE7430F5CFA6F986E2407DCD /* libPods-HostsToolForMac.a */, + 23456CEF06BD9B7F2246B07E /* Pods_HostsToolForMac.framework */, ); name = Frameworks; sourceTree = ""; @@ -130,8 +137,10 @@ children = ( 1F2396D220B5065E00618BB8 /* MainMenu.swift */, 98D9FA6623BAE523008DD433 /* SettingsPanel.swift */, - 1F1AB29E1E666DA000171458 /* MainMenu.xib */, - 984F41E12446E22000ED4EB9 /* SettingsPanel.xib */, + 982DA17725636C6E008173F8 /* DownloadPanel.swift */, + 982DA1952563A712008173F8 /* DownloadPanel.xib */, + 982DA17F25636FFB008173F8 /* MainMenu.xib */, + 982DA1872563A396008173F8 /* SettingsPanel.xib */, ); path = View; sourceTree = ""; @@ -185,7 +194,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0820; - LastUpgradeCheck = 1100; + LastUpgradeCheck = 1200; ORGANIZATIONNAME = ZzzM; TargetAttributes = { 1F1AB2961E666D9F00171458 = { @@ -220,9 +229,10 @@ buildActionMask = 2147483647; files = ( 1F1AB29D1E666D9F00171458 /* Assets.xcassets in Resources */, - 984F41E22446E22000ED4EB9 /* SettingsPanel.xib in Resources */, - 1F1AB2A01E666DA000171458 /* MainMenu.xib in Resources */, + 982DA17D25636FFB008173F8 /* MainMenu.xib in Resources */, + 982DA1852563A396008173F8 /* SettingsPanel.xib in Resources */, 1F338EBF1E696A1D004A3265 /* Localizable.strings in Resources */, + 982DA1932563A712008173F8 /* DownloadPanel.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -298,6 +308,7 @@ 98A85E0C237CFD72006DA99F /* AppDelegate+Extension.swift in Sources */, 98D9FA6723BAE523008DD433 /* SettingsPanel.swift in Sources */, 1FA54AA420B2BD52005B2515 /* Network.swift in Sources */, + 982DA17825636C6E008173F8 /* DownloadPanel.swift in Sources */, 1F1AB29B1E666D9F00171458 /* AppDelegate.swift in Sources */, 1FA54A9A20B2BAB5005B2515 /* Helper.swift in Sources */, 980E5FA62378359900EEF756 /* Foundation+Extension.swift in Sources */, @@ -307,21 +318,40 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ - 1F1AB29E1E666DA000171458 /* MainMenu.xib */ = { + 1F338EC11E696A1D004A3265 /* Localizable.strings */ = { + isa = PBXVariantGroup; + children = ( + 1F338EC21E696A1F004A3265 /* en */, + 1F338EC31E696A20004A3265 /* zh-Hans */, + ); + name = Localizable.strings; + sourceTree = ""; + }; + 982DA17F25636FFB008173F8 /* MainMenu.xib */ = { isa = PBXVariantGroup; children = ( - 1F1AB29F1E666DA000171458 /* Base */, + 982DA1832563703B008173F8 /* zh-Hans */, + 982DA18425637048008173F8 /* en */, ); name = MainMenu.xib; sourceTree = ""; }; - 1F338EC11E696A1D004A3265 /* Localizable.strings */ = { + 982DA1872563A396008173F8 /* SettingsPanel.xib */ = { isa = PBXVariantGroup; children = ( - 1F338EC21E696A1F004A3265 /* en */, - 1F338EC31E696A20004A3265 /* zh-Hans */, + 982DA1862563A396008173F8 /* en */, + 982DA18A2563A3A0008173F8 /* zh-Hans */, ); - name = Localizable.strings; + name = SettingsPanel.xib; + sourceTree = ""; + }; + 982DA1952563A712008173F8 /* DownloadPanel.xib */ = { + isa = PBXVariantGroup; + children = ( + 982DA19A2563A71E008173F8 /* en */, + 982DA19E2563B7E6008173F8 /* zh-Hans */, + ); + name = DownloadPanel.xib; sourceTree = ""; }; /* End PBXVariantGroup section */ @@ -352,6 +382,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -411,6 +442,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -445,12 +477,12 @@ CODE_SIGN_ENTITLEMENTS = HostsToolForMac/HostsToolForMac.entitlements; CODE_SIGN_IDENTITY = "-"; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 2.6.1; + CURRENT_PROJECT_VERSION = 2.7.0; DEVELOPMENT_TEAM = 7823BJG877; INFOPLIST_FILE = HostsToolForMac/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.12; - MARKETING_VERSION = 2.6.1; + MARKETING_VERSION = 2.7.0; PRODUCT_BUNDLE_IDENTIFIER = ZzzM.HostsToolForMac; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -466,12 +498,12 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 2.6.1; + CURRENT_PROJECT_VERSION = 2.7.0; DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = HostsToolForMac/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.12; - MARKETING_VERSION = 2.6.1; + MARKETING_VERSION = 2.7.0; PRODUCT_BUNDLE_IDENTIFIER = zzzm.mac.hostTool; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/HostsToolForMac/HostsToolForMac/AppDelegate.swift b/HostsToolForMac/HostsToolForMac/AppDelegate.swift index f1421a7..81ce816 100644 --- a/HostsToolForMac/HostsToolForMac/AppDelegate.swift +++ b/HostsToolForMac/HostsToolForMac/AppDelegate.swift @@ -23,6 +23,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ aNotification: Notification) { setupBarItem(statusItem) setupNotification() + } diff --git a/HostsToolForMac/HostsToolForMac/Extension/AppKit+Extension.swift b/HostsToolForMac/HostsToolForMac/Extension/AppKit+Extension.swift index 838093e..f7a7809 100644 --- a/HostsToolForMac/HostsToolForMac/Extension/AppKit+Extension.swift +++ b/HostsToolForMac/HostsToolForMac/Extension/AppKit+Extension.swift @@ -32,3 +32,17 @@ extension NSWindow { }) as! Self } } + +extension NSApplication { + + + + func open(_ type: T.Type) { + + if !NSApp.isActive { + NSApp.activate(ignoringOtherApps: true) + } + + NSApp.runModal(for: T.loadFromNib()) + } +} diff --git a/HostsToolForMac/HostsToolForMac/Utils/Network.swift b/HostsToolForMac/HostsToolForMac/Utils/Network.swift index 4b18b5e..7d7c5ad 100644 --- a/HostsToolForMac/HostsToolForMac/Utils/Network.swift +++ b/HostsToolForMac/HostsToolForMac/Utils/Network.swift @@ -11,12 +11,12 @@ import Cocoa struct Network { - - - private static func request(url: URL, + + static func request(url: URL, success: ((Data) -> Void)? = .none, - failure: FailureHandler? = .none) { - URLSession.shared + failure: FailureHandler? = .none) -> URLSessionTask { + + let task = URLSession.shared .dataTask(with: url) { (data, response, error) in if error != nil { failure? (error!) @@ -27,7 +27,12 @@ struct Network { success? (data!) } - }.resume() + } + + task.resume() + + return task + } } diff --git a/HostsToolForMac/HostsToolForMac/View/DownloadPanel.swift b/HostsToolForMac/HostsToolForMac/View/DownloadPanel.swift new file mode 100644 index 0000000..ff6181f --- /dev/null +++ b/HostsToolForMac/HostsToolForMac/View/DownloadPanel.swift @@ -0,0 +1,58 @@ +// +// DownloadPanel.swift +// HostsToolForMac +// +// Created by zm on 2020/11/17. +// Copyright © 2020 ZzzM. All rights reserved. +// + +import Cocoa + +class DownloadPanel: NSPanel { + + @IBOutlet weak var progressIndicator: NSProgressIndicator! + + var task: URLSessionTask! + + override func awakeFromNib() { + + progressIndicator.startAnimation(.none) + task = Network.request(url: HostsType.current.url) { [self] in + Helper.deliverNotification($0.hosts + .compared + .executed + .message) + + close(.none) + } failure: { [self] in + + if $0.code == -999 { + Helper.deliverNotification($0.localizedDescription) + } else { + close(.none) + } + + } + + } + + @IBAction func close(_ sender: Any?) { + + DispatchQueue.mainAsync { [self] in + progressIndicator.stopAnimation(.none) + close() + } + + task.cancel() + + } + + +} + +extension DownloadPanel: NSWindowDelegate { + override func close() { + super.close() + NSApp.abortModal() + } +} diff --git a/HostsToolForMac/HostsToolForMac/View/MainMenu.swift b/HostsToolForMac/HostsToolForMac/View/MainMenu.swift index 6f9bc4e..dd4c898 100644 --- a/HostsToolForMac/HostsToolForMac/View/MainMenu.swift +++ b/HostsToolForMac/HostsToolForMac/View/MainMenu.swift @@ -13,26 +13,6 @@ let updater = SUUpdater() class MainMenu: NSMenu { - @IBOutlet weak var importItem: NSMenuItem! - - @IBOutlet weak var downloadItem: NSMenuItem! - - @IBOutlet weak var exitItem: NSMenuItem! - - @IBOutlet weak var settingsItem: NSMenuItem! - @IBOutlet weak var checkItem: NSMenuItem! - @IBOutlet weak var helpItem: NSMenuItem! - - override func awakeFromNib() { - - importItem.title = "Menu.Title.Import".localized - downloadItem.title = "Menu.Title.Download".localized - settingsItem.title = "Menu.Title.Settings".localized - exitItem.title = "Menu.Title.Exit".localized - checkItem.title = "Menu.Title.Check".localized - helpItem.title = "Menu.Title.Help".localized - } - @IBAction func importAction(_ sender: Any) { var result = ExecutionResult.invalid if let url = Helper.openPanel() { @@ -42,25 +22,17 @@ class MainMenu: NSMenu { } @IBAction func downloadAction(_ sender: Any) { - Helper.deliverNotification(HostsType.current.url - .hosts - .compared - .executed - .message) + NSApp.open(DownloadPanel.self) } @IBAction func settingsAction(_ sender: Any) { - SettingsPanel.show() + NSApp.open(SettingsPanel.self) } @IBAction func checkAction(_ sender: Any) { updater.checkForUpdates(sender) } - @IBAction func helpAction(_ sender: Any) { - AppHomePageURL.open() - } - @IBAction func exitAction(_ sender: Any) { NSApp.terminate(.none) } @@ -76,12 +48,22 @@ extension String { } } +extension Data { + var hosts: ExecutionResult { + + guard let _hosts = String(data: self, encoding: .utf8) else { + return .invalid + } + + return _hosts.verifyResult + } +} extension URL{ var hosts: ExecutionResult { do { return try String(contentsOf: self).verifyResult - } catch{ + } catch { guard let underlyingError = error.userInfo["NSUnderlyingError"] as? Error else { return .error(error.localizedDescription) diff --git a/HostsToolForMac/HostsToolForMac/View/SettingsPanel.swift b/HostsToolForMac/HostsToolForMac/View/SettingsPanel.swift index 68e863c..d0e6674 100644 --- a/HostsToolForMac/HostsToolForMac/View/SettingsPanel.swift +++ b/HostsToolForMac/HostsToolForMac/View/SettingsPanel.swift @@ -10,48 +10,29 @@ import Cocoa class SettingsPanel: NSPanel { - @IBOutlet weak var optionsLabel: NSTextField! @IBOutlet weak var optionsButton: NSPopUpButton! - - @IBOutlet weak var lookButton: NSButton! - + - var hostsType: HostsType! { return optionsButton.selectedItem?.title.hostsType } - override func awakeFromNib() { - title = AppName - - standardWindowButton(.miniaturizeButton)?.isHidden = true - standardWindowButton(.zoomButton)?.isHidden = true - - optionsLabel.stringValue = "Settings.Title.Hosts".localized optionsButton.addItems(withTitles: HostsType.names) optionsButton.selectItem(withTitle: HostsType.current.name) optionsButton.menu?.delegate = self - lookButton.title = "Settings.Title.View".localized - } @IBAction func lookAction(_ sender: Any) { hostsType.url.open() } - static func show() { - - if !NSApp.isActive { - NSApp.activate(ignoringOtherApps: true) - } - - let panel = SettingsPanel.loadFromNib() - NSApp.runModal(for: panel) - + @IBAction func close(_ sender: Any) { + close() } + } diff --git a/HostsToolForMac/HostsToolForMac/View/SettingsPanel.xib b/HostsToolForMac/HostsToolForMac/View/SettingsPanel.xib deleted file mode 100644 index 2a24666..0000000 --- a/HostsToolForMac/HostsToolForMac/View/SettingsPanel.xib +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/HostsToolForMac/HostsToolForMac/View/en.lproj/DownloadPanel.xib b/HostsToolForMac/HostsToolForMac/View/en.lproj/DownloadPanel.xib new file mode 100644 index 0000000..0f35176 --- /dev/null +++ b/HostsToolForMac/HostsToolForMac/View/en.lproj/DownloadPanel.xib @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/HostsToolForMac/HostsToolForMac/View/en.lproj/MainMenu.strings b/HostsToolForMac/HostsToolForMac/View/en.lproj/MainMenu.strings deleted file mode 100644 index 19aabbf..0000000 --- a/HostsToolForMac/HostsToolForMac/View/en.lproj/MainMenu.strings +++ /dev/null @@ -1,21 +0,0 @@ - -/* Class = "NSMenuItem"; title = "镜像"; ObjectID = "0OD-yk-0ra"; */ -"0OD-yk-0ra.title" = "镜像"; - -/* Class = "NSMenuItem"; title = "本地导入"; ObjectID = "HVU-2S-bB1"; */ -"HVU-2S-bB1.title" = "本地导入"; - -/* Class = "NSMenu"; title = "网络更新"; ObjectID = "RuJ-F0-BuC"; */ -"RuJ-F0-BuC.title" = "网络更新"; - -/* Class = "NSMenuItem"; title = "检查更新"; ObjectID = "hZ7-5E-hRx"; */ -"hZ7-5E-hRx.title" = "检查更新"; - -/* Class = "NSMenuItem"; title = "退出"; ObjectID = "kux-y0-M3b"; */ -"kux-y0-M3b.title" = "退出"; - -/* Class = "NSMenuItem"; title = "网络更新"; ObjectID = "rJb-5x-wh6"; */ -"rJb-5x-wh6.title" = "网络更新"; - -/* Class = "NSMenuItem"; title = "默认"; ObjectID = "uQP-Zu-3g7"; */ -"uQP-Zu-3g7.title" = "默认"; diff --git a/HostsToolForMac/HostsToolForMac/View/Base.lproj/MainMenu.xib b/HostsToolForMac/HostsToolForMac/View/en.lproj/MainMenu.xib similarity index 74% rename from HostsToolForMac/HostsToolForMac/View/Base.lproj/MainMenu.xib rename to HostsToolForMac/HostsToolForMac/View/en.lproj/MainMenu.xib index 37959dd..e5e81cc 100644 --- a/HostsToolForMac/HostsToolForMac/View/Base.lproj/MainMenu.xib +++ b/HostsToolForMac/HostsToolForMac/View/en.lproj/MainMenu.xib @@ -1,8 +1,8 @@ - + - + @@ -45,12 +45,6 @@ - - - - - - @@ -58,15 +52,7 @@ - - - - - - - - - + diff --git a/HostsToolForMac/HostsToolForMac/View/en.lproj/SettingsPanel.xib b/HostsToolForMac/HostsToolForMac/View/en.lproj/SettingsPanel.xib new file mode 100644 index 0000000..8c9fcc3 --- /dev/null +++ b/HostsToolForMac/HostsToolForMac/View/en.lproj/SettingsPanel.xib @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/HostsToolForMac/HostsToolForMac/View/zh-Hans.lproj/DownloadPanel.xib b/HostsToolForMac/HostsToolForMac/View/zh-Hans.lproj/DownloadPanel.xib new file mode 100644 index 0000000..2fe4966 --- /dev/null +++ b/HostsToolForMac/HostsToolForMac/View/zh-Hans.lproj/DownloadPanel.xib @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/HostsToolForMac/HostsToolForMac/View/zh-Hans.lproj/MainMenu.strings b/HostsToolForMac/HostsToolForMac/View/zh-Hans.lproj/MainMenu.strings deleted file mode 100644 index 56560e7..0000000 --- a/HostsToolForMac/HostsToolForMac/View/zh-Hans.lproj/MainMenu.strings +++ /dev/null @@ -1,15 +0,0 @@ - -/* Class = "NSMenuItem"; title = "HostsToolForMac"; ObjectID = "1Xt-HY-uBw"; */ -"1Xt-HY-uBw.title" = "HostsToolForMac"; - -/* Class = "NSMenuItem"; title = "Quit HostsToolForMac"; ObjectID = "4sb-4s-VLi"; */ -"4sb-4s-VLi.title" = "Quit HostsToolForMac"; - -/* Class = "NSMenuItem"; title = "About HostsToolForMac"; ObjectID = "5kV-Vb-QxS"; */ -"5kV-Vb-QxS.title" = "About HostsToolForMac"; - -/* Class = "NSMenu"; title = "Main Menu"; ObjectID = "AYu-sK-qS6"; */ -"AYu-sK-qS6.title" = "Main Menu"; - -/* Class = "NSMenu"; title = "HostsToolForMac"; ObjectID = "uQy-DD-JDr"; */ -"uQy-DD-JDr.title" = "HostsToolForMac"; diff --git a/HostsToolForMac/HostsToolForMac/View/zh-Hans.lproj/MainMenu.xib b/HostsToolForMac/HostsToolForMac/View/zh-Hans.lproj/MainMenu.xib new file mode 100644 index 0000000..8551ad1 --- /dev/null +++ b/HostsToolForMac/HostsToolForMac/View/zh-Hans.lproj/MainMenu.xib @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/HostsToolForMac/HostsToolForMac/View/zh-Hans.lproj/SettingsPanel.xib b/HostsToolForMac/HostsToolForMac/View/zh-Hans.lproj/SettingsPanel.xib new file mode 100644 index 0000000..2c455f8 --- /dev/null +++ b/HostsToolForMac/HostsToolForMac/View/zh-Hans.lproj/SettingsPanel.xib @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/HostsToolForMac/HostsToolForMac/en.lproj/Localizable.strings b/HostsToolForMac/HostsToolForMac/en.lproj/Localizable.strings index fe2d651..0124d6f 100644 --- a/HostsToolForMac/HostsToolForMac/en.lproj/Localizable.strings +++ b/HostsToolForMac/HostsToolForMac/en.lproj/Localizable.strings @@ -5,15 +5,7 @@ Created by Zhang.M on 03/03/2017. Copyright © 2017 ZzzM. All rights reserved. */ -"Menu.Title.Import" = "Import"; -"Menu.Title.Download" = "Download"; -"Menu.Title.Settings" = "Settings"; -"Menu.Title.Check" = "Check for Updates"; -"Menu.Title.Help" = "Help"; -"Menu.Title.Exit" = "Exit"; -"Settings.Title.Hosts" = "Download Options"; -"Settings.Title.View" = "View"; "Error.Hosts.Invalid" = "Hosts is Invalid!"; diff --git a/HostsToolForMac/HostsToolForMac/zh-Hans.lproj/Localizable.strings b/HostsToolForMac/HostsToolForMac/zh-Hans.lproj/Localizable.strings index d5c0ec0..60b1036 100644 --- a/HostsToolForMac/HostsToolForMac/zh-Hans.lproj/Localizable.strings +++ b/HostsToolForMac/HostsToolForMac/zh-Hans.lproj/Localizable.strings @@ -5,15 +5,6 @@ Created by Zhang.M on 03/03/2017. Copyright © 2017 ZzzM. All rights reserved. */ -"Menu.Title.Import" = "导入"; -"Menu.Title.Download" = "下载"; -"Menu.Title.Settings" = "设置"; -"Menu.Title.Check" = "检查更新"; -"Menu.Title.Help" = "帮助"; -"Menu.Title.Exit" = "退出"; - -"Settings.Title.View" = "浏览"; -"Settings.Title.Hosts" = "下载配置"; "Error.Hosts.Invalid" = "无效的Hosts!"; "Error.Hosts.Creation" = "Hosts创建失败!"; diff --git a/HostsToolForMac/Podfile b/HostsToolForMac/Podfile index 4f425b6..cba58c9 100755 --- a/HostsToolForMac/Podfile +++ b/HostsToolForMac/Podfile @@ -2,6 +2,8 @@ platform :osx, ‘10.12’ inhibit_all_warnings! target 'HostsToolForMac' do + + use_frameworks! pod 'Sparkle' diff --git a/Previews/p1.png b/Previews/p1.png index ec4b937..9f484d1 100644 Binary files a/Previews/p1.png and b/Previews/p1.png differ diff --git a/Previews/p2.png b/Previews/p2.png index 567dc48..5a0df9b 100644 Binary files a/Previews/p2.png and b/Previews/p2.png differ diff --git a/Previews/p3.png b/Previews/p3.png new file mode 100644 index 0000000..9eb5d0f Binary files /dev/null and b/Previews/p3.png differ diff --git a/README.md b/README.md index 8bf695c..8db0536 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,38 @@ # HostsToolforMac 一款轻量级本地 hosts 更新工具。 -- 开发语言:Swift 5
-- 运行环境:macOS 10.12 或以上
+- 开发语言:Swift
+- 运行环境:macOS 10.12 或以上
- 在线更新:需要将解压好的App放至应用程序文件夹 -- [下载地址](https://github.com/ZzzM/HostsToolforMac/releases/download/2.6.0/HostsToolForMac.zip) +- [下载地址](https://github.com/ZzzM/HostsToolforMac/releases/download/2.7.0/HostsToolForMac.zip) -### Version 2.6.0: -- 更新菜单 -- 更新设置面板 -- 支持在线更新 -#### 菜单 +## 版本 + +| 版本 | 说明 | +| ---- | ---- | +| 2.6.0 | 更新菜单
更新设置面板
支持在线更新 | +| 2.6.1 | - | +| 2.7.0 | 更新菜单
更新设置面板
新增下载提示面板
适配 macOS Big Sur 11.0.1| + +## 预览 +- 主页 + +- 下载 + + +- 设置 + + -#### Hosts下载源-设置面板 - -#### Hosts下载源 -[coding](https://scaffrey.coding.net/p/hosts/d/hosts/git/raw/master/hosts-files/hosts)
-[gogs](https://git.qvq.network/googlehosts/hosts/raw/master/hosts-files/hosts)
+## Hosts下载源 +[coding](https://scaffrey.coding.net/p/hosts/d/hosts/git/raw/master/hosts-files/hosts)
+[gogs](https://git.qvq.network/googlehosts/hosts/raw/master/hosts-files/hosts)
[github](https://raw.githubusercontent.com/googlehosts/hosts/master/hosts-files/hosts) -### 注意 +## 注意 - 第一次更新会完全覆盖原hosts,然后生成“# My Hosts Start”、“# My Hosts End”标识,需要添加的话,只要在“# My Hosts Start”、“# My Hosts End”范围内编辑, - 防止覆盖自己添加的hosts,只要在“# My Hosts Start”、“# My Hosts End”范围内编辑即可