Some improvements to the settings.

This commit is contained in:
2025-05-31 14:53:10 -07:00
parent b3fb6dfc7f
commit 727c1ceb09
5 changed files with 48 additions and 34 deletions

View File

@@ -16,7 +16,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
window.delegate = self window.delegate = self
// NOTE: Here we check wether the program was launched by the // NOTE: Here we check wether the program was launched by the
// system. If it was not, then display the window. // system (e.g. launch-at-login). If it was not, then display
// the window.
if let event = NSAppleEventManager.shared().currentAppleEvent, if let event = NSAppleEventManager.shared().currentAppleEvent,
!(event.eventID == kAEOpenApplication && !(event.eventID == kAEOpenApplication &&
event.paramDescriptor(forKeyword: keyAEPropData)? event.paramDescriptor(forKeyword: keyAEPropData)?

View File

@@ -12,8 +12,8 @@ SRCMODULES = Helpers.swift EditableNSTextField.swift EventMonitor.swift \
SettingsViewController.swift HotKeyManager.swift \ SettingsViewController.swift HotKeyManager.swift \
KeyDetectorButton.swift PathManager.swift \ KeyDetectorButton.swift PathManager.swift \
PathsTableCellView.swift ProgramsTable.swift ShadowView.swift \ PathsTableCellView.swift ProgramsTable.swift ShadowView.swift \
DirMonitor.swift MenulessWindow.swift AboutViewController.swift \ DirMonitor.swift MenulessWindow.swift \
AppDelegate.swift main.swift AboutViewController.swift AppDelegate.swift main.swift
ARMOBJMODULES = $(addprefix ./arm64/,$(SRCMODULES:.swift=.o)) ARMOBJMODULES = $(addprefix ./arm64/,$(SRCMODULES:.swift=.o))
X86OBJMODULES = $(addprefix ./x86_64/,$(SRCMODULES:.swift=.o)) X86OBJMODULES = $(addprefix ./x86_64/,$(SRCMODULES:.swift=.o))
@@ -71,6 +71,7 @@ ifdef UNIVERSAL
./x86_64/main.o $(filter-out ./x86_64/main.o, $(X86OBJMODULES)) -o $@ ./x86_64/main.o $(filter-out ./x86_64/main.o, $(X86OBJMODULES)) -o $@
endif endif
# TODO: The universal build doesn't seem to compile x86_64.
ifdef UNIVERSAL ifdef UNIVERSAL
$(EXEC): ./arm64/$(EXEC) ./x86_64/$(EXEC) $(EXEC): ./arm64/$(EXEC) ./x86_64/$(EXEC)
@lipo -create -output $(EXEC) $^ @lipo -create -output $(EXEC) $^

View File

@@ -1,9 +1,11 @@
import AppKit import AppKit
import Carbon import Carbon
// NOTE: This is the corner radius of the backgrounView view that acts as a window frame and an NSViewController's view that clips all elements inside of it. // NOTE: This is the corner radius of the backgrounView view that acts as
// a window frame.
fileprivate let windowCornerRadius = 15.0 fileprivate let windowCornerRadius = 15.0
// NOTE: This is the maximum number of elements shown when searching.
fileprivate let maxItems = 20 fileprivate let maxItems = 20
class SearchViewController: NSViewController, NSTextFieldDelegate, class SearchViewController: NSViewController, NSTextFieldDelegate,
@@ -205,10 +207,10 @@ class SearchViewController: NSViewController, NSTextFieldDelegate,
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
// NOTE: This needs removeObserver on deinit? Well, technically we // NOTE: This needs removeObserver on deinit. However, technically
// don't care because this view controller will exist // it doesn't matter because if this view controller doesn't
// throughout the whole life of the program. When the // exists, then the whole program is pointless. So, let the OS
// program gets killed, the OS will clear this. // clean it up when the program is killed.
DistributedNotificationCenter.default DistributedNotificationCenter.default
.addObserver(self, selector: #selector(osThemeChanged(sender:)), .addObserver(self, selector: #selector(osThemeChanged(sender:)),
name: NSNotification name: NSNotification
@@ -318,7 +320,7 @@ class SearchViewController: NSViewController, NSTextFieldDelegate,
centerWindow() centerWindow()
view.window?.makeFirstResponder(searchInput) view.window?.makeFirstResponder(searchInput)
// searchInput should select all text whenever window appears. // searchInput select all text whenever window appears.
NSApp.sendAction(#selector(NSResponder.selectAll(_:)), to: nil, NSApp.sendAction(#selector(NSResponder.selectAll(_:)), to: nil,
from: self) from: self)
} }
@@ -402,12 +404,10 @@ class SearchViewController: NSViewController, NSTextFieldDelegate,
programsList[listIndex].path = prog.path programsList[listIndex].path = prog.path
programsList[listIndex].name = prog.name programsList[listIndex].name = prog.name
programsList[listIndex].ext = prog.ext programsList[listIndex].ext = prog.ext
programsList[listIndex].img = programsList[listIndex].img = NSWorkspace.shared
NSWorkspace.shared
.icon(forFile: URL( .icon(forFile: URL(
fileURLWithPath: prog.path fileURLWithPath: prog.path
) ).appendingPathComponent(
.appendingPathComponent(
prog.name+prog.ext).path prog.name+prog.ext).path
) )
listIndex += 1 listIndex += 1

View File

@@ -16,18 +16,7 @@ class SettingsViewController: NSViewController,
private var paths: [String] = [] private var paths: [String] = []
// PERF: This is very slow to initialize because it creates a new private var dirPicker: NSOpenPanel?
// process. This also cannot be done on a separate thread. This
// sucks because the program now takes considerably longer to
// launch.
private let dirPicker: NSOpenPanel = {
let panel = NSOpenPanel()
panel.message = "Select a directory to search applications in . . ."
panel.canChooseDirectories = true
panel.canChooseFiles = false
panel.allowsMultipleSelection = false
return panel
}()
private var shortcutsLabel: NSTextField = { private var shortcutsLabel: NSTextField = {
let textField = NSTextField(labelWithString: "Shortcut") let textField = NSTextField(labelWithString: "Shortcut")
@@ -528,8 +517,7 @@ class SettingsViewController: NSViewController,
pathsTableView.scrollRowToVisible(row) pathsTableView.scrollRowToVisible(row)
pathsTableView.selectRowIndexes(IndexSet(integer: row), pathsTableView.selectRowIndexes(IndexSet(integer: row),
byExtendingSelection: false) byExtendingSelection: false)
( (pathsTableView
pathsTableView
.view(atColumn: 0, row: row, makeIfNecessary: false .view(atColumn: 0, row: row, makeIfNecessary: false
) as? PathsTableCellView)?.startEditing() ) as? PathsTableCellView)?.startEditing()
break break
@@ -586,6 +574,15 @@ class SettingsViewController: NSViewController,
} }
func titleFieldTextChanged(tag: Int, text: String) { func titleFieldTextChanged(tag: Int, text: String) {
if let cell = pathsTableView.view(atColumn: 0, row: tag,
makeIfNecessary: false) as? PathsTableCellView
{
if isDirectory(text) {
cell.titleField.textColor = NSColor.green
} else {
cell.titleField.textColor = NSColor.red
}
}
} }
func keyWasSet(to keyCode: Int) { func keyWasSet(to keyCode: Int) {
@@ -593,12 +590,27 @@ class SettingsViewController: NSViewController,
} }
func selectionButtonClicked(tag: Int) { func selectionButtonClicked(tag: Int) {
if dirPicker == nil {
dirPicker = NSOpenPanel()
dirPicker!.message = "Select a directory to search applications in..."
dirPicker!.canChooseDirectories = true
dirPicker!.canChooseFiles = false
dirPicker!.allowsMultipleSelection = false
}
// WARN:
// FIX: THere is a bug where the program crashes when adding a new
// path. This happens because the settings popup is closed before
// displaying the selection modal, as a result the new path item
// is cleared (well, b/c it's empty) and the path gets set into
// non-existent memory which results in segmentation fault.
NSRunningApplication.current.activate(options: .activateAllWindows) NSRunningApplication.current.activate(options: .activateAllWindows)
delegate.window.level = .normal delegate.window.level = .normal
delegate.aboutWindow.performClose(nil) delegate.aboutWindow.performClose(nil)
if dirPicker.runModal() == .OK { if dirPicker!.runModal() == .OK {
if let url = dirPicker.url { if let url = dirPicker!.url {
paths[tag] = url.path paths[tag] = url.path
pathsTableView.reloadData() pathsTableView.reloadData()
} }

Binary file not shown.