Skip to content

Commit

Permalink
misc: swift lint
Browse files Browse the repository at this point in the history
# Conflicts:
#	ClashX.xcodeproj/project.pbxproj
#	ClashX/General/ApiRequest.swift
#	ClashX/General/Managers/ProManager.swift
#	ClashX/General/Managers/Settings.swift
#	ClashX/General/Managers/TunManager.swift
#	ClashX/General/Utils/NetworkChangeNotifier.swift
#	ClashX/ViewControllers/ClashWebViewContoller.swift
  • Loading branch information
yichengchen committed Jun 20, 2022
1 parent 6df282d commit c6c74dd
Show file tree
Hide file tree
Showing 32 changed files with 153 additions and 126 deletions.
19 changes: 19 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# By default, SwiftLint uses a set of sensible default rules you can adjust:
disabled_rules: # rule identifiers turned on by default to exclude from running
- colon
- identifier_name
- force_cast
- closure_parameter_position
- file_length
- large_tuple
- type_body_length
included: # paths to include during linting. `--path` is ignored if present.
- ClashX
excluded: # paths to ignore during linting. Takes precedence over `included`.
- ClashX/Vendor
- Pods
analyzer_rules: # Rules run by `swiftlint analyze`
- explicit_self
# implicitly
line_length: 300
# reporter: "xcode"
8 changes: 4 additions & 4 deletions ClashX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
49B445162457CDF000B27E3E /* ClashStatusTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49B445152457CDF000B27E3E /* ClashStatusTool.swift */; };
49B4575D244F4A2A00463C39 /* PrivilegedHelperManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49B4575C244F4A2A00463C39 /* PrivilegedHelperManager.swift */; };
49B4575F244FD4D100463C39 /* PrivilegedHelperManager+Legacy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49B4575E244FD4D100463C39 /* PrivilegedHelperManager+Legacy.swift */; };
49BB31E7246853EA008A4CB0 /* iCloudManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49BB31E6246853EA008A4CB0 /* iCloudManager.swift */; };
49BB31E7246853EA008A4CB0 /* ICloudManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49BB31E6246853EA008A4CB0 /* ICloudManager.swift */; };
49BC061C212931F4005A0FE7 /* AboutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49BC061B212931F4005A0FE7 /* AboutViewController.swift */; };
49C9EF64223E78F5005D8B6A /* ClashProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49C9EF63223E78F5005D8B6A /* ClashProxy.swift */; };
49CF3B2120CD7463001EBF94 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49CF3B2020CD7463001EBF94 /* AppDelegate.swift */; };
Expand Down Expand Up @@ -176,7 +176,7 @@
49B445152457CDF000B27E3E /* ClashStatusTool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClashStatusTool.swift; sourceTree = "<group>"; };
49B4575C244F4A2A00463C39 /* PrivilegedHelperManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivilegedHelperManager.swift; sourceTree = "<group>"; };
49B4575E244FD4D100463C39 /* PrivilegedHelperManager+Legacy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PrivilegedHelperManager+Legacy.swift"; sourceTree = "<group>"; };
49BB31E6246853EA008A4CB0 /* iCloudManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iCloudManager.swift; sourceTree = "<group>"; };
49BB31E6246853EA008A4CB0 /* ICloudManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ICloudManager.swift; sourceTree = "<group>"; };
49BC061B212931F4005A0FE7 /* AboutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutViewController.swift; sourceTree = "<group>"; };
49C9EF63223E78F5005D8B6A /* ClashProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClashProxy.swift; sourceTree = "<group>"; };
49CF3B1D20CD7463001EBF94 /* ClashX.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ClashX.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -299,7 +299,7 @@
F9E754CF239CC21F00CEE7CC /* WebPortalManager.swift */,
49B4575C244F4A2A00463C39 /* PrivilegedHelperManager.swift */,
49B4575E244FD4D100463C39 /* PrivilegedHelperManager+Legacy.swift */,
49BB31E6246853EA008A4CB0 /* iCloudManager.swift */,
49BB31E6246853EA008A4CB0 /* ICloudManager.swift */,
499ADAFC2498CC5900C488FE /* RemoteControlManager.swift */,
4929F67E258CE04700A435F6 /* Settings.swift */,
);
Expand Down Expand Up @@ -751,7 +751,7 @@
F976275C23634DF8000EDEFE /* LoginServiceKit.swift in Sources */,
4966E9E6211824F300A391FB /* NSImage+extension.swift in Sources */,
F92D0B2E236D35C000575E15 /* ProxyItemView.swift in Sources */,
49BB31E7246853EA008A4CB0 /* iCloudManager.swift in Sources */,
49BB31E7246853EA008A4CB0 /* ICloudManager.swift in Sources */,
49B1086A216A356D0064FFCE /* String+Extension.swift in Sources */,
F92D0B2C236C7C3600575E15 /* MenuItemBaseView.swift in Sources */,
499ADAFD2498CC5900C488FE /* RemoteControlManager.swift in Sources */,
Expand Down
20 changes: 19 additions & 1 deletion ClashX.xcodeproj/xcshareddata/xcschemes/ClashX.xcscheme
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
version = "1.3">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<PreActions>
<ExecutionAction
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Run Script"
scriptText = "export PATH=&quot;$PATH:/opt/homebrew/bin&quot;&#10;if which swiftlint &gt; /dev/null; then&#10; cd $PROJECT_DIR &amp;&amp; swiftlint --fix &amp;&amp; swiftlint&#10;else&#10; echo &quot;warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint&quot;&#10;fi&#10;">
<EnvironmentBuildable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "49CF3B1C20CD7463001EBF94"
BuildableName = "ClashX Pro.app"
BlueprintName = "ClashX Pro"
ReferencedContainer = "container:ClashX.xcodeproj">
</BuildableReference>
</EnvironmentBuildable>
</ActionContent>
</ExecutionAction>
</PreActions>
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
Expand Down
47 changes: 23 additions & 24 deletions ClashX/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import RxSwift
import AppCenter
import AppCenterAnalytics


private let statusItemLengthWithSpeed: CGFloat = 72

@NSApplicationMain
Expand Down Expand Up @@ -90,7 +89,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
setupStatusMenuItemData()
AppVersionUtil.showUpgradeAlert()
iCloudManager.shared.setup()
ICloudManager.shared.setup()
setupExperimentalMenuItem()

// install proxy helper
Expand Down Expand Up @@ -121,7 +120,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {

RemoteConfigManager.shared.autoUpdateCheck()


setupNetworkNotifier()
}

Expand Down Expand Up @@ -181,7 +179,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
Logger.log("ClashX will terminate")
if NetworkChangeNotifier.isCurrentSystemSetToClash(looser: true) ||
NetworkChangeNotifier.hasInterfaceProxySetToClash() {
Logger.log("Need Reset Proxy Setting again",level: .error)
Logger.log("Need Reset Proxy Setting again", level: .error)
SystemProxyManager.shared.disableProxy()
}
}
Expand Down Expand Up @@ -271,21 +269,21 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

}.disposed(by: disposeBag)

if !PrivilegedHelperManager.shared.isHelperCheckFinished.value &&
ConfigManager.shared.proxyPortAutoSet {
PrivilegedHelperManager.shared.isHelperCheckFinished
.filter({$0})
.take(1)
.take(while:{_ in ConfigManager.shared.proxyPortAutoSet})
.take(while: {_ in ConfigManager.shared.proxyPortAutoSet})
.observe(on: MainScheduler.instance)
.bind(onNext: { _ in
SystemProxyManager.shared.enableProxy()
}).disposed(by: disposeBag)
} else if ConfigManager.shared.proxyPortAutoSet {
SystemProxyManager.shared.enableProxy()
}

if !PrivilegedHelperManager.shared.isHelperCheckFinished.value {
proxySettingMenuItem.target = nil
PrivilegedHelperManager.shared.isHelperCheckFinished
Expand Down Expand Up @@ -424,7 +422,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
} else {
ConfigManager.shared.isRunning = false
proxyModeMenuItem.isEnabled = false
Logger.log(string,level: .error)
Logger.log(string, level: .error)
NSUserNotificationCenter.default.postConfigErrorNotice(msg: string)
}
Logger.log("Start proxy done")
Expand Down Expand Up @@ -492,7 +490,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
if WebPortalManager.hasWebProtal {
WebPortalManager.shared.addWebProtalMenuItem(&statusMenu)
}
iCloudManager.shared.addEnableMenuItem(&experimentalMenu)
ICloudManager.shared.addEnableMenuItem(&experimentalMenu)
AutoUpgardeManager.shared.setup()
AutoUpgardeManager.shared.addChanelMenuItem(&experimentalMenu)
updateExperimentalFeatureStatus()
Expand Down Expand Up @@ -524,23 +522,23 @@ class AppDelegate: NSObject, NSApplicationDelegate {
ApiRequest.getMergedProxyData {
proxyResp in
guard let proxyResp = proxyResp else {return}

var providers = Set<ClashProxyName>()

let groups = proxyResp.proxyGroups.filter({$0.type.isAutoGroup})
for group in groups {
group.all?.compactMap{
group.all?.compactMap {
proxyResp.proxiesMap[$0]?.enclosingProvider?.name
}.forEach{
}.forEach {
providers.insert($0)
}
}

for group in groups {
Logger.log("Start auto health check for group \(group.name)")
ApiRequest.healthCheck(proxy: group.name)
}

for provider in providers {
Logger.log("Start auto health check for provider \(provider)")
ApiRequest.healthCheck(proxy: provider)
Expand Down Expand Up @@ -590,7 +588,7 @@ extension AppDelegate {
}
let config = ConfigManager.shared.currentConfig?.copy()
config?.mode = mode
ApiRequest.updateOutBoundMode(mode: mode) { success in
ApiRequest.updateOutBoundMode(mode: mode) { _ in
ConfigManager.shared.currentConfig = config
ConfigManager.selectOutBoundMode = mode
MenuItemFactory.recreateProxyMenuItems()
Expand Down Expand Up @@ -697,8 +695,8 @@ extension AppDelegate {

extension AppDelegate {
@IBAction func openConfigFolder(_ sender: Any) {
if iCloudManager.shared.isICloudEnable() {
iCloudManager.shared.getUrl() {
if ICloudManager.shared.isICloudEnable() {
ICloudManager.shared.getUrl {
url in
if let url = url {
NSWorkspace.shared.open(url)
Expand Down Expand Up @@ -728,7 +726,7 @@ extension AppDelegate {
@IBAction func actionUpdateRemoteConfig(_ sender: Any) {
RemoteConfigManager.shared.updateCheck(ignoreTimeLimit: true, showNotification: true)
}

@IBAction func actionSetUpdateInterval(_ sender: Any) {
RemoteConfigManager.showAdd()
}
Expand All @@ -747,6 +745,7 @@ extension AppDelegate {
@IBAction func actionUpdateProxyGroupMenu(_ sender: Any) {
ConfigManager.shared.disableShowCurrentProxyInMenu = !ConfigManager.shared.disableShowCurrentProxyInMenu
updateExperimentalFeatureStatus()
print("211")
MenuItemFactory.recreateProxyMenuItems()
}

Expand Down Expand Up @@ -780,10 +779,10 @@ extension AppDelegate {
#else
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
AppCenter.start(withAppSecret: "dce6e9a3-b6e3-4fd2-9f2d-35c767a99663", services: [
Analytics.self,
Analytics.self
])
}

#endif
}

Expand All @@ -805,7 +804,7 @@ extension AppDelegate {
UserDefaults.standard.removePersistentDomain(forName: domain)
UserDefaults.standard.synchronize()
}
NSUserNotificationCenter.default.post(title: "Fail on launch protect", info: "You origin Config has been renamed",notiOnly: false)
NSUserNotificationCenter.default.post(title: "Fail on launch protect", info: "You origin Config has been renamed", notiOnly: false)
}
DispatchQueue.global().asyncAfter(deadline: DispatchTime.now() + Double(Int64(5 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: {
x.set(0, forKey: "launch_fail_times")
Expand Down Expand Up @@ -842,8 +841,8 @@ extension AppDelegate {
}
}

if iCloudManager.shared.isICloudEnable() {
iCloudManager.shared.getConfigFilesList { list in
if ICloudManager.shared.isICloudEnable() {
ICloudManager.shared.getConfigFilesList { list in
action(list)
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion ClashX/Basic/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Logger {
#if DEBUG
DDLog.add(DDOSLogger.sharedInstance)
#endif
//default time zone is "UTC"
// default time zone is "UTC"
let dataFormatter = DateFormatter()
dataFormatter.setLocalizedDateFormatFromTemplate("YYYY/MM/dd HH:mm:ss:SSS")
fileLogger.logFormatter = DDLogFileFormatterDefault.init(dateFormatter: dataFormatter)
Expand Down
2 changes: 1 addition & 1 deletion ClashX/Basic/NSImage+extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension NSImage {

color.set()

let imageRect = NSRect(origin: NSZeroPoint, size: image.size)
let imageRect = NSRect(origin: NSPoint.zero, size: image.size)
imageRect.fill(using: .sourceIn)

image.unlockFocus()
Expand Down
Loading

0 comments on commit c6c74dd

Please sign in to comment.