Launch at login toggle and some design improvements.
This commit is contained in:
@@ -17,11 +17,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
|
|||||||
|
|
||||||
window.makeKeyAndOrderFront(nil)
|
window.makeKeyAndOrderFront(nil)
|
||||||
|
|
||||||
HotKeyManager.shared.handler =
|
HotKeyManager.shared.handler = { (inHandlerCallRef, inEvent, inUserData) -> OSStatus in
|
||||||
{ (inHandlerCallRef, inEvent, inUserData) -> OSStatus in
|
if let delegate = NSApplication.shared.delegate as? AppDelegate {
|
||||||
if let delegate =
|
|
||||||
NSApplication.shared.delegate as? AppDelegate
|
|
||||||
{
|
|
||||||
let window = delegate.window
|
let window = delegate.window
|
||||||
if window.isKeyWindow {
|
if window.isKeyWindow {
|
||||||
window.resignKey()
|
window.resignKey()
|
||||||
@@ -59,12 +56,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
public func toggleLaunchAtLogin() {
|
public func toggleLaunchAtLogin(isOn status: Bool) {
|
||||||
let service = SMAppService.mainApp
|
let service = SMAppService.mainApp
|
||||||
if service.status == .enabled {
|
if status, service.status != .enabled {
|
||||||
try? service.unregister()
|
|
||||||
} else {
|
|
||||||
try? service.register()
|
try? service.register()
|
||||||
|
} else if service.status == .enabled {
|
||||||
|
try? service.unregister()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ class SearchViewController: NSViewController, NSTextFieldDelegate, NSPopoverDele
|
|||||||
|
|
||||||
private var settingsButton: NSButton = {
|
private var settingsButton: NSButton = {
|
||||||
let button = NSButton()
|
let button = NSButton()
|
||||||
button.image = systemImage("gear.circle.fill", .title1, .large, .init(paletteColors: [.labelColor, .systemGray]))
|
button.image = systemImage("gear.circle.fill", .title1, .large, .init(paletteColors: [.white, .systemGray]))
|
||||||
button.isBordered = false
|
button.isBordered = false
|
||||||
button.action = #selector(openSettings)
|
button.action = #selector(openSettings)
|
||||||
button.sizeToFit()
|
button.sizeToFit()
|
||||||
|
|||||||
@@ -15,10 +15,8 @@ class SettingsViewController: NSViewController,
|
|||||||
|
|
||||||
private var paths: [String] = []
|
private var paths: [String] = []
|
||||||
|
|
||||||
// NOTE: PERF: This is very slow to initialize because it creates a
|
// PERF: This is very slow to initialize because it creates a new process. This also cannot be done on a separate
|
||||||
// a new process. This also cannot be done on a separate
|
// thread. This sucks because the program now takes considerably longer to launch.
|
||||||
// thread. This sucks because the program now takes
|
|
||||||
// considerably longer to launch.
|
|
||||||
private let dirPicker: NSOpenPanel = {
|
private let dirPicker: NSOpenPanel = {
|
||||||
let panel = NSOpenPanel()
|
let panel = NSOpenPanel()
|
||||||
panel.message = "Select a directory to search applications in . . ."
|
panel.message = "Select a directory to search applications in . . ."
|
||||||
@@ -139,8 +137,6 @@ class SettingsViewController: NSViewController,
|
|||||||
table.allowsColumnSelection = false
|
table.allowsColumnSelection = false
|
||||||
table.addTableColumn(NSTableColumn(identifier: NSUserInterfaceItemIdentifier("Paths")))
|
table.addTableColumn(NSTableColumn(identifier: NSUserInterfaceItemIdentifier("Paths")))
|
||||||
|
|
||||||
//rowHeight cgfloat must see doc
|
|
||||||
|
|
||||||
table.translatesAutoresizingMaskIntoConstraints = false
|
table.translatesAutoresizingMaskIntoConstraints = false
|
||||||
return table
|
return table
|
||||||
}()
|
}()
|
||||||
@@ -161,18 +157,28 @@ class SettingsViewController: NSViewController,
|
|||||||
return control
|
return control
|
||||||
}()
|
}()
|
||||||
|
|
||||||
private var launchAtLoginButton: NSButton = {
|
private var launchAtLoginLabel: NSTextField = {
|
||||||
let button = NSButton()
|
let textField = NSTextField(labelWithString: "Launch at login")
|
||||||
button.title = "Launch at login - OFF"
|
textField.translatesAutoresizingMaskIntoConstraints = false
|
||||||
button.action = #selector(launchAtLogin)
|
return textField
|
||||||
button.setButtonType(.toggle)
|
|
||||||
button.sizeToFit()
|
|
||||||
button.bezelStyle = .rounded
|
|
||||||
button.isBordered = false
|
|
||||||
button.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
return button
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
private var launchAtLoginToggle: NSSegmentedControl = {
|
||||||
|
let control = NSSegmentedControl()
|
||||||
|
control.segmentCount = 2
|
||||||
|
control.segmentStyle = .roundRect
|
||||||
|
|
||||||
|
control.setLabel("Off", forSegment: 0)
|
||||||
|
control.setLabel("On", forSegment: 1)
|
||||||
|
|
||||||
|
control.setToolTip("Off", forSegment: 0)
|
||||||
|
control.setToolTip("On", forSegment: 1)
|
||||||
|
|
||||||
|
control.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
return control
|
||||||
|
}()
|
||||||
|
|
||||||
|
|
||||||
private var resetAllButton: NSButton = {
|
private var resetAllButton: NSButton = {
|
||||||
let button = NSButton()
|
let button = NSButton()
|
||||||
button.title = "Reset"
|
button.title = "Reset"
|
||||||
@@ -199,7 +205,8 @@ class SettingsViewController: NSViewController,
|
|||||||
view.addSubview(tableScrollView)
|
view.addSubview(tableScrollView)
|
||||||
view.addSubview(pathsControl)
|
view.addSubview(pathsControl)
|
||||||
|
|
||||||
view.addSubview(launchAtLoginButton)
|
view.addSubview(launchAtLoginLabel)
|
||||||
|
view.addSubview(launchAtLoginToggle)
|
||||||
view.addSubview(resetAllButton)
|
view.addSubview(resetAllButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,10 +249,13 @@ class SettingsViewController: NSViewController,
|
|||||||
pathsControl.topAnchor.constraint(equalTo: tableScrollView.bottomAnchor, constant: ViewConstants.spacing10),
|
pathsControl.topAnchor.constraint(equalTo: tableScrollView.bottomAnchor, constant: ViewConstants.spacing10),
|
||||||
pathsControl.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: ViewConstants.spacing10),
|
pathsControl.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: ViewConstants.spacing10),
|
||||||
|
|
||||||
launchAtLoginButton.topAnchor.constraint(equalTo: pathsControl.bottomAnchor, constant: ViewConstants.spacing10),
|
launchAtLoginLabel.topAnchor.constraint(equalTo: pathsControl.bottomAnchor, constant: ViewConstants.spacing10),
|
||||||
launchAtLoginButton.trailingAnchor.constraint(equalTo: resetAllButton.leadingAnchor, constant: -ViewConstants.spacing10),
|
launchAtLoginLabel.trailingAnchor.constraint(equalTo: launchAtLoginToggle.leadingAnchor, constant: -ViewConstants.spacing10),
|
||||||
|
|
||||||
resetAllButton.centerYAnchor.constraint(equalTo: launchAtLoginButton.centerYAnchor),
|
launchAtLoginToggle.firstBaselineAnchor.constraint(equalTo: launchAtLoginLabel.firstBaselineAnchor),
|
||||||
|
launchAtLoginToggle.trailingAnchor.constraint(equalTo: resetAllButton.leadingAnchor, constant: -ViewConstants.spacing15),
|
||||||
|
|
||||||
|
resetAllButton.firstBaselineAnchor.constraint(equalTo: launchAtLoginLabel.firstBaselineAnchor),
|
||||||
resetAllButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -ViewConstants.spacing10),
|
resetAllButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -ViewConstants.spacing10),
|
||||||
resetAllButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -ViewConstants.spacing10),
|
resetAllButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -ViewConstants.spacing10),
|
||||||
])
|
])
|
||||||
@@ -261,7 +271,7 @@ class SettingsViewController: NSViewController,
|
|||||||
ctrlButton.target = self
|
ctrlButton.target = self
|
||||||
shiftButton.target = self
|
shiftButton.target = self
|
||||||
recordButton.delegate = self
|
recordButton.delegate = self
|
||||||
launchAtLoginButton.target = self
|
launchAtLoginLabel.target = self
|
||||||
resetAllButton.target = self
|
resetAllButton.target = self
|
||||||
|
|
||||||
recordButton.defaultKey = kVK_Space
|
recordButton.defaultKey = kVK_Space
|
||||||
@@ -274,6 +284,12 @@ class SettingsViewController: NSViewController,
|
|||||||
pathsControl.target = self
|
pathsControl.target = self
|
||||||
pathsControl.action = #selector(affectPaths(_:))
|
pathsControl.action = #selector(affectPaths(_:))
|
||||||
|
|
||||||
|
pathsControl.target = self
|
||||||
|
pathsControl.action = #selector(affectPaths(_:))
|
||||||
|
|
||||||
|
launchAtLoginToggle.target = self
|
||||||
|
launchAtLoginToggle.action = #selector(affectLaunchAtLogin(_:))
|
||||||
|
|
||||||
addSubviews()
|
addSubviews()
|
||||||
setConstraints()
|
setConstraints()
|
||||||
}
|
}
|
||||||
@@ -345,18 +361,16 @@ class SettingsViewController: NSViewController,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
private func launchAtLogin() {
|
private func launchAtLogin(isOn status: Bool) {
|
||||||
delegate.toggleLaunchAtLogin()
|
delegate.toggleLaunchAtLogin(isOn: status)
|
||||||
launchAtLoginStatus()
|
launchAtLoginStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func launchAtLoginStatus() {
|
private func launchAtLoginStatus() {
|
||||||
if delegate.willLaunchAtLogin() {
|
if delegate.willLaunchAtLogin() {
|
||||||
launchAtLoginButton.title = "Launch at login - ON"
|
launchAtLoginToggle.setSelected(true, forSegment: 1)
|
||||||
launchAtLoginButton.state = .on
|
|
||||||
} else {
|
} else {
|
||||||
launchAtLoginButton.title = "Launch at login - OFF"
|
launchAtLoginToggle.setSelected(true, forSegment: 0)
|
||||||
launchAtLoginButton.state = .off
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,6 +467,21 @@ class SettingsViewController: NSViewController,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc
|
||||||
|
private func affectLaunchAtLogin(_ sender: NSSegmentedControl) {
|
||||||
|
let selectedSegment = sender.selectedSegment
|
||||||
|
switch selectedSegment {
|
||||||
|
case 0:
|
||||||
|
launchAtLogin(isOn: false)
|
||||||
|
break
|
||||||
|
case 1:
|
||||||
|
launchAtLogin(isOn: true)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
private func editItem(_ sender: NSTableView) {
|
private func editItem(_ sender: NSTableView) {
|
||||||
pathsTableView.deselectAll(nil)
|
pathsTableView.deselectAll(nil)
|
||||||
|
|||||||
Reference in New Issue
Block a user