misc: swiftlint auto fix
This commit is contained in:
parent
209c1db1fa
commit
f266dbf8b7
|
@ -48,7 +48,7 @@ class Logger {
|
||||||
func logFilePath() -> String {
|
func logFilePath() -> String {
|
||||||
return fileLogger.logFileManager.sortedLogFilePaths.first ?? ""
|
return fileLogger.logFileManager.sortedLogFilePaths.first ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func logFolder() -> String {
|
func logFolder() -> String {
|
||||||
return fileLogger.logFileManager.logsDirectory
|
return fileLogger.logFileManager.logsDirectory
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ extension NSView {
|
||||||
$0.leftAnchor.constraint(equalTo: $0.superview!.leftAnchor, constant: inset.left),
|
$0.leftAnchor.constraint(equalTo: $0.superview!.leftAnchor, constant: inset.left),
|
||||||
$0.rightAnchor.constraint(equalTo: $0.superview!.rightAnchor, constant: -inset.right),
|
$0.rightAnchor.constraint(equalTo: $0.superview!.rightAnchor, constant: -inset.right),
|
||||||
$0.topAnchor.constraint(equalTo: $0.superview!.topAnchor, constant: inset.top),
|
$0.topAnchor.constraint(equalTo: $0.superview!.topAnchor, constant: inset.top),
|
||||||
$0.bottomAnchor.constraint(equalTo: $0.superview!.bottomAnchor, constant: -inset.bottom),
|
$0.bottomAnchor.constraint(equalTo: $0.superview!.bottomAnchor, constant: -inset.bottom)
|
||||||
] }
|
] }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ extension NSView {
|
||||||
func makeConstraintsBindToCenterOfSuperview() -> Self {
|
func makeConstraintsBindToCenterOfSuperview() -> Self {
|
||||||
return makeConstraints { [
|
return makeConstraints { [
|
||||||
$0.centerXAnchor.constraint(equalTo: $0.superview!.centerXAnchor),
|
$0.centerXAnchor.constraint(equalTo: $0.superview!.centerXAnchor),
|
||||||
$0.centerYAnchor.constraint(equalTo: $0.superview!.centerYAnchor),
|
$0.centerYAnchor.constraint(equalTo: $0.superview!.centerYAnchor)
|
||||||
] }
|
] }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,19 +46,19 @@ enum Settings {
|
||||||
|
|
||||||
@UserDefault("apiPortAllowLan", defaultValue: false)
|
@UserDefault("apiPortAllowLan", defaultValue: false)
|
||||||
static var apiPortAllowLan: Bool
|
static var apiPortAllowLan: Bool
|
||||||
|
|
||||||
@UserDefault("disableSSIDList", defaultValue: [])
|
@UserDefault("disableSSIDList", defaultValue: [])
|
||||||
static var disableSSIDList:[String]
|
static var disableSSIDList: [String]
|
||||||
|
|
||||||
@UserDefault("useSwiftUiMenuBar", defaultValue: true)
|
@UserDefault("useSwiftUiMenuBar", defaultValue: true)
|
||||||
static var useSwiftUiMenuBar: Bool
|
static var useSwiftUiMenuBar: Bool
|
||||||
|
|
||||||
static let apiSecretKey = "api-secret"
|
static let apiSecretKey = "api-secret"
|
||||||
|
|
||||||
static var isApiSecretSet:Bool {
|
static var isApiSecretSet: Bool {
|
||||||
return UserDefaults.standard.object(forKey: apiSecretKey) != nil
|
return UserDefaults.standard.object(forKey: apiSecretKey) != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@UserDefault(apiSecretKey, defaultValue: "")
|
@UserDefault(apiSecretKey, defaultValue: "")
|
||||||
static var apiSecret: String
|
static var apiSecret: String
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ class NetworkChangeNotifier {
|
||||||
}
|
}
|
||||||
return allowIPV6 ? ipv6 : nil
|
return allowIPV6 ? ipv6 : nil
|
||||||
}
|
}
|
||||||
|
|
||||||
static func getCurrentSSID() -> String? {
|
static func getCurrentSSID() -> String? {
|
||||||
return CWWiFiClient.shared().interface()?.ssid()
|
return CWWiFiClient.shared().interface()?.ssid()
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,7 @@ class SSIDSuspendTool {
|
||||||
.bind { [weak self] _ in
|
.bind { [weak self] _ in
|
||||||
self?.update()
|
self?.update()
|
||||||
}.disposed(by: disposeBag)
|
}.disposed(by: disposeBag)
|
||||||
|
|
||||||
|
|
||||||
ConfigManager.shared
|
ConfigManager.shared
|
||||||
.proxyShouldPaused
|
.proxyShouldPaused
|
||||||
.asObservable()
|
.asObservable()
|
||||||
|
@ -37,10 +36,10 @@ class SSIDSuspendTool {
|
||||||
SystemProxyManager.shared.enableProxy()
|
SystemProxyManager.shared.enableProxy()
|
||||||
}
|
}
|
||||||
}.disposed(by: disposeBag)
|
}.disposed(by: disposeBag)
|
||||||
|
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
func update() {
|
func update() {
|
||||||
if shouldSuspend() {
|
if shouldSuspend() {
|
||||||
ConfigManager.shared.proxyShouldPaused.accept(true)
|
ConfigManager.shared.proxyShouldPaused.accept(true)
|
||||||
|
@ -48,7 +47,7 @@ class SSIDSuspendTool {
|
||||||
ConfigManager.shared.proxyShouldPaused.accept(false)
|
ConfigManager.shared.proxyShouldPaused.accept(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldSuspend() -> Bool {
|
func shouldSuspend() -> Bool {
|
||||||
if let currentSSID = NetworkChangeNotifier.getCurrentSSID() {
|
if let currentSSID = NetworkChangeNotifier.getCurrentSSID() {
|
||||||
return Settings.disableSSIDList.contains(currentSSID)
|
return Settings.disableSSIDList.contains(currentSSID)
|
||||||
|
|
|
@ -28,7 +28,6 @@ class DebugSettingViewController: NSViewController {
|
||||||
@IBAction func actionOpenLocalConfig(_ sender: Any) {
|
@IBAction func actionOpenLocalConfig(_ sender: Any) {
|
||||||
NSWorkspace.shared.openFile(kConfigFolderPath)
|
NSWorkspace.shared.openFile(kConfigFolderPath)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@IBAction func actionOpenIcloudConfig(_ sender: Any) {
|
@IBAction func actionOpenIcloudConfig(_ sender: Any) {
|
||||||
if ICloudManager.shared.icloudAvailable {
|
if ICloudManager.shared.icloudAvailable {
|
||||||
|
|
|
@ -20,12 +20,11 @@ class GeneralSettingViewController: NSViewController {
|
||||||
@IBOutlet weak var proxyPortTextField: NSTextField!
|
@IBOutlet weak var proxyPortTextField: NSTextField!
|
||||||
@IBOutlet weak var apiPortTextField: NSTextField!
|
@IBOutlet weak var apiPortTextField: NSTextField!
|
||||||
@IBOutlet var ssidSuspendTextField: NSTextView!
|
@IBOutlet var ssidSuspendTextField: NSTextView!
|
||||||
|
|
||||||
@IBOutlet weak var apiSecretTextField: NSTextField!
|
@IBOutlet weak var apiSecretTextField: NSTextField!
|
||||||
|
|
||||||
@IBOutlet weak var apiSecretOverrideButton: NSButton!
|
@IBOutlet weak var apiSecretOverrideButton: NSButton!
|
||||||
|
|
||||||
|
|
||||||
var disposeBag = DisposeBag()
|
var disposeBag = DisposeBag()
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
@ -37,7 +36,6 @@ class GeneralSettingViewController: NSViewController {
|
||||||
Settings.proxyIgnoreList = arr
|
Settings.proxyIgnoreList = arr
|
||||||
}.disposed(by: disposeBag)
|
}.disposed(by: disposeBag)
|
||||||
|
|
||||||
|
|
||||||
ssidSuspendTextField.string = Settings.disableSSIDList.joined(separator: ",")
|
ssidSuspendTextField.string = Settings.disableSSIDList.joined(separator: ",")
|
||||||
ssidSuspendTextField.rx
|
ssidSuspendTextField.rx
|
||||||
.string.debounce(.milliseconds(500), scheduler: MainScheduler.instance)
|
.string.debounce(.milliseconds(500), scheduler: MainScheduler.instance)
|
||||||
|
@ -46,7 +44,7 @@ class GeneralSettingViewController: NSViewController {
|
||||||
Settings.disableSSIDList = arr
|
Settings.disableSSIDList = arr
|
||||||
SSIDSuspendTool.shared.update()
|
SSIDSuspendTool.shared.update()
|
||||||
}.disposed(by: disposeBag)
|
}.disposed(by: disposeBag)
|
||||||
|
|
||||||
LaunchAtLogin.shared.isEnableVirable
|
LaunchAtLogin.shared.isEnableVirable
|
||||||
.map { $0 ? .on : .off }
|
.map { $0 ? .on : .off }
|
||||||
.bind(to: launchAtLoginButton.rx.state)
|
.bind(to: launchAtLoginButton.rx.state)
|
||||||
|
@ -78,12 +76,12 @@ class GeneralSettingViewController: NSViewController {
|
||||||
} else {
|
} else {
|
||||||
apiPortTextField.stringValue = ConfigManager.shared.apiPort
|
apiPortTextField.stringValue = ConfigManager.shared.apiPort
|
||||||
}
|
}
|
||||||
|
|
||||||
apiSecretTextField.stringValue = Settings.apiSecret
|
apiSecretTextField.stringValue = Settings.apiSecret
|
||||||
apiSecretTextField.rx.text.compactMap {$0}.bind {
|
apiSecretTextField.rx.text.compactMap {$0}.bind {
|
||||||
Settings.apiSecret = $0
|
Settings.apiSecret = $0
|
||||||
}.disposed(by: disposeBag)
|
}.disposed(by: disposeBag)
|
||||||
|
|
||||||
apiSecretOverrideButton.state = Settings.overrideConfigSecret ? .on : .off
|
apiSecretOverrideButton.state = Settings.overrideConfigSecret ? .on : .off
|
||||||
apiSecretOverrideButton.rx.state.bind { state in
|
apiSecretOverrideButton.rx.state.bind { state in
|
||||||
Settings.overrideConfigSecret = state == .on
|
Settings.overrideConfigSecret = state == .on
|
||||||
|
|
|
@ -24,41 +24,40 @@ extension KeyboardShortcuts.Name {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enum KeyboardShortCutManager {
|
enum KeyboardShortCutManager {
|
||||||
static func setup() {
|
static func setup() {
|
||||||
KeyboardShortcuts.onKeyUp(for: .toggleSystemProxyMode) {
|
KeyboardShortcuts.onKeyUp(for: .toggleSystemProxyMode) {
|
||||||
AppDelegate.shared.actionSetSystemProxy(nil)
|
AppDelegate.shared.actionSetSystemProxy(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardShortcuts.onKeyUp(for: .copyShellCommand) {
|
KeyboardShortcuts.onKeyUp(for: .copyShellCommand) {
|
||||||
AppDelegate.shared.actionCopyExportCommand(AppDelegate.shared.copyExportCommandMenuItem)
|
AppDelegate.shared.actionCopyExportCommand(AppDelegate.shared.copyExportCommandMenuItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardShortcuts.onKeyUp(for: .copyExternalShellCommand) {
|
KeyboardShortcuts.onKeyUp(for: .copyExternalShellCommand) {
|
||||||
AppDelegate.shared.actionCopyExportCommand(AppDelegate.shared.copyExportCommandExternalMenuItem)
|
AppDelegate.shared.actionCopyExportCommand(AppDelegate.shared.copyExportCommandExternalMenuItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardShortcuts.onKeyUp(for: .modeDirect) {
|
KeyboardShortcuts.onKeyUp(for: .modeDirect) {
|
||||||
AppDelegate.shared.switchProxyMode(mode: .direct)
|
AppDelegate.shared.switchProxyMode(mode: .direct)
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardShortcuts.onKeyUp(for: .modeRule) {
|
KeyboardShortcuts.onKeyUp(for: .modeRule) {
|
||||||
AppDelegate.shared.switchProxyMode(mode: .rule)
|
AppDelegate.shared.switchProxyMode(mode: .rule)
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardShortcuts.onKeyUp(for: .modeGlobal) {
|
KeyboardShortcuts.onKeyUp(for: .modeGlobal) {
|
||||||
AppDelegate.shared.switchProxyMode(mode: .global)
|
AppDelegate.shared.switchProxyMode(mode: .global)
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardShortcuts.onKeyUp(for: .log) {
|
KeyboardShortcuts.onKeyUp(for: .log) {
|
||||||
AppDelegate.shared.actionShowLog(nil)
|
AppDelegate.shared.actionShowLog(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardShortcuts.onKeyUp(for: .dashboard) {
|
KeyboardShortcuts.onKeyUp(for: .dashboard) {
|
||||||
AppDelegate.shared.actionDashboard(nil)
|
AppDelegate.shared.actionDashboard(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardShortcuts.onKeyUp(for: .openMenu) {
|
KeyboardShortcuts.onKeyUp(for: .openMenu) {
|
||||||
AppDelegate.shared.statusItem.button?.performClick(nil)
|
AppDelegate.shared.statusItem.button?.performClick(nil)
|
||||||
}
|
}
|
||||||
|
@ -66,39 +65,37 @@ enum KeyboardShortCutManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
class GlobalShortCutViewController: NSViewController {
|
class GlobalShortCutViewController: NSViewController {
|
||||||
|
|
||||||
@IBOutlet weak var proxyBox: NSBox!
|
@IBOutlet weak var proxyBox: NSBox!
|
||||||
@IBOutlet weak var modeBoxView: NSView!
|
@IBOutlet weak var modeBoxView: NSView!
|
||||||
@IBOutlet weak var otherBoxView: NSView!
|
@IBOutlet weak var otherBoxView: NSView!
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
let systemProxy = KeyboardShortcuts.RecorderCocoa(for: .toggleSystemProxyMode)
|
let systemProxy = KeyboardShortcuts.RecorderCocoa(for: .toggleSystemProxyMode)
|
||||||
let copyShellCommand = KeyboardShortcuts.RecorderCocoa(for: .copyShellCommand)
|
let copyShellCommand = KeyboardShortcuts.RecorderCocoa(for: .copyShellCommand)
|
||||||
let copyShellCommandExternal = KeyboardShortcuts.RecorderCocoa(for: .copyExternalShellCommand)
|
let copyShellCommandExternal = KeyboardShortcuts.RecorderCocoa(for: .copyExternalShellCommand)
|
||||||
addGridView(in: proxyBox.contentView!, with: [
|
addGridView(in: proxyBox.contentView!, with: [
|
||||||
[NSTextField(labelWithString: NSLocalizedString("System Proxy", comment: "")),systemProxy],
|
[NSTextField(labelWithString: NSLocalizedString("System Proxy", comment: "")), systemProxy],
|
||||||
[NSTextField(labelWithString: NSLocalizedString("Copy Shell Command", comment: "")),copyShellCommand],
|
[NSTextField(labelWithString: NSLocalizedString("Copy Shell Command", comment: "")), copyShellCommand],
|
||||||
[NSTextField(labelWithString: NSLocalizedString("Copy Shell Command (External)", comment: "")),copyShellCommandExternal],
|
[NSTextField(labelWithString: NSLocalizedString("Copy Shell Command (External)", comment: "")), copyShellCommandExternal]
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
addGridView(in: modeBoxView, with: [
|
addGridView(in: modeBoxView, with: [
|
||||||
[NSTextField(labelWithString: NSLocalizedString("Direct Mode", comment: "")),KeyboardShortcuts.RecorderCocoa(for: .modeDirect)],
|
[NSTextField(labelWithString: NSLocalizedString("Direct Mode", comment: "")), KeyboardShortcuts.RecorderCocoa(for: .modeDirect)],
|
||||||
[NSTextField(labelWithString: NSLocalizedString("Rule Mode", comment: "")),KeyboardShortcuts.RecorderCocoa(for: .modeRule)],
|
[NSTextField(labelWithString: NSLocalizedString("Rule Mode", comment: "")), KeyboardShortcuts.RecorderCocoa(for: .modeRule)],
|
||||||
[NSTextField(labelWithString: NSLocalizedString("Global Mode", comment: "")),KeyboardShortcuts.RecorderCocoa(for: .modeGlobal)],
|
[NSTextField(labelWithString: NSLocalizedString("Global Mode", comment: "")), KeyboardShortcuts.RecorderCocoa(for: .modeGlobal)]
|
||||||
])
|
])
|
||||||
|
|
||||||
addGridView(in: otherBoxView, with: [
|
addGridView(in: otherBoxView, with: [
|
||||||
[NSTextField(labelWithString: NSLocalizedString("Open Menu", comment: "")),KeyboardShortcuts.RecorderCocoa(for: .openMenu)],
|
[NSTextField(labelWithString: NSLocalizedString("Open Menu", comment: "")), KeyboardShortcuts.RecorderCocoa(for: .openMenu)],
|
||||||
[NSTextField(labelWithString: NSLocalizedString("Open Log", comment: "")),KeyboardShortcuts.RecorderCocoa(for: .log)],
|
[NSTextField(labelWithString: NSLocalizedString("Open Log", comment: "")), KeyboardShortcuts.RecorderCocoa(for: .log)],
|
||||||
[NSTextField(labelWithString: NSLocalizedString("Open Dashboard", comment: "")),KeyboardShortcuts.RecorderCocoa(for: .dashboard)],
|
[NSTextField(labelWithString: NSLocalizedString("Open Dashboard", comment: "")), KeyboardShortcuts.RecorderCocoa(for: .dashboard)]
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addGridView(in superView: NSView, with views: [[NSView]]) {
|
||||||
func addGridView(in superView:NSView, with views: [[NSView]]) {
|
|
||||||
let gridView = NSGridView(views: views)
|
let gridView = NSGridView(views: views)
|
||||||
gridView.rowSpacing = 10
|
gridView.rowSpacing = 10
|
||||||
gridView.rowAlignment = .firstBaseline
|
gridView.rowAlignment = .firstBaseline
|
||||||
|
|
|
@ -56,10 +56,10 @@ class StatusMenuViewModel: ObservableObject {
|
||||||
struct SwiftUIView: View {
|
struct SwiftUIView: View {
|
||||||
@ObservedObject var viewModel: StatusMenuViewModel
|
@ObservedObject var viewModel: StatusMenuViewModel
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack(alignment:.center) {
|
HStack(alignment: .center) {
|
||||||
Image(nsImage: $viewModel.image.wrappedValue).renderingMode(.template)
|
Image(nsImage: $viewModel.image.wrappedValue).renderingMode(.template)
|
||||||
.resizable().aspectRatio(contentMode: .fit).frame(width: 16,height: 16)
|
.resizable().aspectRatio(contentMode: .fit).frame(width: 16, height: 16)
|
||||||
|
|
||||||
if $viewModel.showSpeed.wrappedValue {
|
if $viewModel.showSpeed.wrappedValue {
|
||||||
Spacer(minLength: 0)
|
Spacer(minLength: 0)
|
||||||
VStack(alignment: .trailing) {
|
VStack(alignment: .trailing) {
|
||||||
|
|
Loading…
Reference in New Issue