diff --git a/README.md b/README.md index 6d0e16a..0eb778f 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,8 @@ The launcher opens without a window animation; Settings is constructed only when | Open a result or copy a calculated answer | Return or double-click | | Open actions for the selected entry | Command-K | | Open one of the first nine results | Hold Command until numbers appear, then press 1–9 | -| Go back or dismiss the launcher | Escape | -| Dismiss the launcher | Command-W | +| Dismiss the launcher, including the current Command and Actions | Escape or Command-W | +| Go back without dismissing | Back chevron | | Open Settings | Command-comma | | Quit | Command-Q | @@ -104,19 +104,19 @@ Rates are shared across queries and refreshed on the next currency query after t Search for **Conjure Emoji**, identified by its centered 🤔 icon, and open it. Browse the grid or search by name, keyword, `:shortcode:`, or emoji. Use the category menu to filter results or show **Recently Used**. Your last 30 selections are saved locally. Favorites appear first, followed by recent selections when browsing All Emoji. -Use the arrow keys or Control-H/J/K/L to navigate left/down/up/right; the grid scrolls to keep the selected emoji visible. Return, clicking an emoji, or **Copy and Paste** copies it, dismisses Conjure, and tries to paste into the app that was focused when the launcher opened. Automatic pasting requires **System Settings → Privacy & Security → Accessibility → Conjure**; macOS prompts if permission is missing. After granting it, select an emoji again. If permission is denied, the previous app is unavailable, or focus cannot be restored promptly, the emoji stays copied for manual Command-V. Escape or the Back chevron returns to the launcher and restores your search. +Use the arrow keys or Control-H/J/K/L to navigate left/down/up/right; the grid scrolls to keep the selected emoji visible. Return, clicking an emoji, or **Copy and Paste** copies it, dismisses Conjure, and tries to paste into the app that was focused when the launcher opened. Automatic pasting requires **System Settings → Privacy & Security → Accessibility → Conjure**; macOS prompts if permission is missing. After granting it, select an emoji again. If permission is denied, the previous app is unavailable, or focus cannot be restored promptly, the emoji stays copied for manual Command-V. The Back chevron returns to the launcher and restores your search. If macOS keeps prompting despite an enabled Accessibility entry, quit Conjure, remove its stale entry with the minus button, add the exact app you launch (normally `/Applications/Conjure.app`), enable it, then reopen Conjure and retry. Avoid switching between installed and `.build` copies. For permission that survives rebuilds, configure certificate signing as described above. **Copy Emoji** followed by manual Command-V works without this permission. Open **Actions** with Command-K for **Copy and Paste** (default), **Copy Emoji** (copy only, no Accessibility permission needed), **Favorite**, or **Remove Favorite**. Favorites are saved locally and grouped ahead of other emoji, with a small extra spacing break when browsing without a search. There are no star badges. -With Actions open, Escape or the Back chevron closes Actions first; another Back returns to Applications and restores your search. Command-W dismisses the entire launcher, including the current Command and its Actions. Switching destinations also removes the previous Command's Actions completely. Copy and Copy and Paste dismiss the launcher without an intermediate Back step. +With Actions open, the Back chevron closes Actions first; another Back returns to Applications and restores your search. Escape or Command-W dismisses the entire launcher, including the current Command and its Actions. Switching destinations also removes the previous Command's Actions completely. Copy and Copy and Paste dismiss the launcher without an intermediate Back step. The picker works offline with 1,870 emoji from [gemoji v4.1.0](https://github.com/github/gemoji/tree/v4.1.0). Its [MIT license](Sources/ConjureKit/Resources/LICENSE-gemoji.txt) is included in the application. ## Translation -Search for **Conjure Translate** and open it. Enter English in the search bar, choose a provider, then press Return or click **Translate**. Typing alone never sends text. Copy selected Japanese output with Command-C; the copy hint appears beside the Translate action at the bottom. The Back chevron beside the input or Escape returns to the launcher and restores your search. +Search for **Conjure Translate** and open it. Enter English in the search bar, choose a provider, then press Return or click **Translate**. Typing alone never sends text. Copy selected Japanese output with Command-C; the copy hint appears beside the Translate action at the bottom. The Back chevron beside the input returns to the launcher and restores your search; Escape dismisses Conjure. Editing the input, switching providers, forgetting the key, or leaving Translate cancels the active request; cancelled results are not shown. After a request fails, submit again to retry. @@ -127,7 +127,7 @@ Editing the input, switching providers, forgetting the key, or leaving Translate ## Uninstalling applications -Select an application, open **Actions → Uninstall application**, and review the discovered files. Return toggles the highlighted file's inclusion; **Command-Return opens confirmation**. Back or Escape cancels review. +Select an application, open **Actions → Uninstall application**, and review the discovered files. Return toggles the highlighted file's inclusion; **Command-Return opens confirmation**. Back cancels review and returns to the launcher; Escape dismisses the entire launcher. Closing remains disabled while an uninstall is running, and confirmation sheets retain their own cancellation behavior. Discovery looks for the application and associated files identified by its bundle IDs. Shared app-group data starts unchecked because other applications may use it. Review selections carefully: discovery is conservative, not a guarantee that every associated file is found. Protected applications and unsafe or inaccessible files cannot be removed. Running applications are asked to quit normally; Conjure does not force-quit them or request administrator privileges. diff --git a/Sources/Conjure/ApplicationActionsController.swift b/Sources/Conjure/ApplicationActionsController.swift index 2ef997c..0bde349 100644 --- a/Sources/Conjure/ApplicationActionsController.swift +++ b/Sources/Conjure/ApplicationActionsController.swift @@ -267,7 +267,6 @@ final class ApplicationActionsController: NSViewController, NSSearchFieldDelegat switch selector { case #selector(NSResponder.insertNewline(_:)): if let selectedEntry { chooseAction(at: selectedEntry) } - case #selector(NSResponder.cancelOperation(_:)): close() case #selector(NSResponder.moveUp(_:)): moveSelection(by: -1) case #selector(NSResponder.moveDown(_:)): moveSelection(by: 1) default: return false diff --git a/Sources/Conjure/EmojiPickerController.swift b/Sources/Conjure/EmojiPickerController.swift index 883f4b6..fb3ecb5 100644 --- a/Sources/Conjure/EmojiPickerController.swift +++ b/Sources/Conjure/EmojiPickerController.swift @@ -116,7 +116,6 @@ final class EmojiPickerController: NSViewController, NSCollectionViewDataSource, actions.close(animated: false) closed?() } - override func cancelOperation(_ sender: Any?) { goBack() } func inputChanged(preservingSelection: Bool = false) { let previous = preservingSelection && results.indices.contains(selected) ? results[selected].value : nil @@ -223,7 +222,6 @@ final class EmojiPickerController: NSViewController, NSCollectionViewDataSource, case #selector(NSResponder.moveUp(_:)): moveVertically(-1) case #selector(NSResponder.moveDown(_:)): moveVertically(1) case #selector(NSResponder.insertNewline(_:)): copyAndPasteSelection() - case #selector(NSResponder.cancelOperation(_:)): goBack() default: return false } return true diff --git a/Sources/Conjure/LauncherWindowController.swift b/Sources/Conjure/LauncherWindowController.swift index 7ac6c98..1de6c18 100644 --- a/Sources/Conjure/LauncherWindowController.swift +++ b/Sources/Conjure/LauncherWindowController.swift @@ -158,9 +158,13 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe func dismiss(restoringFocus: Bool = true) { guard !restoringFocus || (!isLaunching && window?.attachedSheet == nil) else { return } - if let review = uninstallReview { review.goBack(); return } + if launcherFrameBeforeReview != nil { + guard uninstallReview?.canClose != false else { return } + pendingPresentation = { [weak self] in self?.dismiss(restoringFocus: restoringFocus) } + uninstallReview?.goBack() + return + } closeCommand() - guard launcherFrameBeforeReview == nil else { return } actions.close(animated: false) alignmentGuides?.end() let previous = previousApplication @@ -257,7 +261,7 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe commandBack.isBordered = false commandBack.contentTintColor = SunsetPalette.secondaryText commandBack.setAccessibilityLabel("Back to applications") - commandBack.toolTip = "Back to applications (Escape)" + commandBack.toolTip = "Back to applications" commandBack.isHidden = true NSLayoutConstraint.activate([ commandBack.widthAnchor.constraint(equalToConstant: IconStyle.applicationSize(for: searchFont)), @@ -478,10 +482,13 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe } func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool { + if commandSelector == #selector(NSResponder.cancelOperation(_:)) { + dismiss() + return true + } if let emojiPicker { return emojiPicker.handle(commandSelector) } if let translation { if commandSelector == #selector(NSResponder.insertNewline(_:)) { translation.translate(); return true } - if commandSelector == #selector(NSResponder.cancelOperation(_:)) { translation.goBack(); return true } return false } switch commandSelector { @@ -491,8 +498,6 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe moveSelection(by: -1) case #selector(NSResponder.insertNewline(_:)): openSelection() - case #selector(NSResponder.cancelOperation(_:)): - dismiss() default: return false } @@ -1201,6 +1206,11 @@ final class LauncherPanel: NSPanel { } override func sendEvent(_ event: NSEvent) { + if event.type == .keyDown, event.keyCode == 53, attachedSheet == nil, + event.modifierFlags.intersection([.command, .control, .option, .shift]).isEmpty { + cancelOperation(nil) + return + } let eligible = numberShortcutsEligible if event.type == .flagsChanged || (event.type == .keyUp && event.keyCode == 49) { reevaluateNumberHints(modifierFlags: event.modifierFlags, eligible: eligible, at: event.timestamp) @@ -1233,6 +1243,10 @@ final class LauncherPanel: NSPanel { } } + override func cancelOperation(_ sender: Any?) { + dismiss?() + } + override func performClose(_ sender: Any?) { dismiss?() } diff --git a/Sources/Conjure/TranslationController.swift b/Sources/Conjure/TranslationController.swift index dfeb534..8fcf603 100644 --- a/Sources/Conjure/TranslationController.swift +++ b/Sources/Conjure/TranslationController.swift @@ -3,7 +3,7 @@ import ConjureKit import Security @MainActor -final class TranslationController: NSViewController, NSTextFieldDelegate, NSTextViewDelegate { +final class TranslationController: NSViewController, NSTextFieldDelegate { private let keyField = NSSecureTextField() private let provider = NSPopUpButton() private let credentials = NSStackView() @@ -59,7 +59,7 @@ final class TranslationController: NSViewController, NSTextFieldDelegate, NSText translateButton.isBordered = false translateButton.font = .systemFont(ofSize: 12, weight: .medium) translateButton.contentTintColor = SunsetPalette.text - translateButton.toolTip = "Translate the English input (Return). Escape returns to the launcher." + translateButton.toolTip = "Translate the English input (Return). Escape dismisses Conjure." let returnKey = ShortcutIndicator("↵") let actionPill = NSView() actionPill.wantsLayer = true @@ -91,7 +91,6 @@ final class TranslationController: NSViewController, NSTextFieldDelegate, NSText output.textColor = SunsetPalette.text output.font = .systemFont(ofSize: 20) output.setAccessibilityLabel("Japanese translation") - output.delegate = self let scroll = NSScrollView() scroll.documentView = output scroll.hasVerticalScroller = true @@ -129,20 +128,6 @@ final class TranslationController: NSViewController, NSTextFieldDelegate, NSText updateProvider() } - override func cancelOperation(_ sender: Any?) { goBack() } - - func control(_ control: NSControl, textView: NSTextView, doCommandBy selector: Selector) -> Bool { - guard selector == #selector(NSResponder.cancelOperation(_:)) else { return false } - goBack() - return true - } - - func textView(_ textView: NSTextView, doCommandBy selector: Selector) -> Bool { - guard selector == #selector(NSResponder.cancelOperation(_:)) else { return false } - goBack() - return true - } - func controlTextDidChange(_ notification: Notification) { inputChanged() } @objc func goBack() { diff --git a/Sources/Conjure/UninstallReviewController.swift b/Sources/Conjure/UninstallReviewController.swift index bb89b2a..f4845e2 100644 --- a/Sources/Conjure/UninstallReviewController.swift +++ b/Sources/Conjure/UninstallReviewController.swift @@ -25,6 +25,7 @@ final class UninstallReviewController: NSViewController, NSSearchFieldDelegate, private var window: NSWindow? { view.window } var closed: (() -> Void)? var changed: (() -> Void)? + var canClose: Bool { !busy } init(application: Application, uninstaller: ApplicationUninstaller) { self.application = application @@ -117,7 +118,6 @@ final class UninstallReviewController: NSViewController, NSSearchFieldDelegate, table.allowsEmptySelection = false table.setAccessibilityLabel("Files to uninstall for \(application.name)") table.toggle = { [weak self] in self?.toggleHighlighted() } - table.dismiss = { [weak self] in self?.goBack() } let scroll = NSScrollView() scroll.documentView = table scroll.hasVerticalScroller = true @@ -229,7 +229,6 @@ final class UninstallReviewController: NSViewController, NSSearchFieldDelegate, case #selector(NSResponder.moveDown(_:)): moveSelection(1) case #selector(NSResponder.moveUp(_:)): moveSelection(-1) case #selector(NSResponder.insertNewline(_:)): toggleHighlighted() - case #selector(NSResponder.cancelOperation(_:)): goBack() default: return false } return true @@ -391,10 +390,8 @@ final class UninstallReviewController: NSViewController, NSSearchFieldDelegate, } } - override func cancelOperation(_ sender: Any?) { goBack() } - @objc func goBack() { - guard !busy else { return } + guard canClose else { return } scanTask?.cancel() (view as! UninstallReviewContent).acceptsInteraction = false view.setAccessibilityHidden(true) @@ -467,10 +464,8 @@ private final class UninstallFileCell: NSTableCellView { @MainActor private final class UninstallFilesTable: NSTableView { var toggle: (() -> Void)? - var dismiss: (() -> Void)? override func keyDown(with event: NSEvent) { if [36, 76, 49].contains(event.keyCode), event.modifierFlags.intersection([.command, .option, .control]).isEmpty { toggle?() } - else if event.keyCode == 53 { dismiss?() } else { super.keyDown(with: event) } } } diff --git a/TODO.md b/TODO.md index fd4f957..524ea20 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,6 @@ - [x] bugfix: the emoji picker currently doesn't scroll with the selection (arrows or ctrl+hjkl), only with mouse scroll. - the window should scroll with the current selection -- [ ] make escape close the window that was opened, be it the application launcher, the emoji picker, or something else. +- [x] make escape close the window that was opened, be it the application launcher, the emoji picker, or something else. - clicking the "back" chevron should still take you back to the application launcher view though (as it does today). - [ ] add a notes app inspired by raycast notes - [ ] improve on the conjure translation command \ No newline at end of file diff --git a/Tests/ConjureKitTests/EmojiPickerTests.swift b/Tests/ConjureKitTests/EmojiPickerTests.swift index cf17035..258471d 100644 --- a/Tests/ConjureKitTests/EmojiPickerTests.swift +++ b/Tests/ConjureKitTests/EmojiPickerTests.swift @@ -202,7 +202,7 @@ import Testing } } -@Test @MainActor func emojiCommandRestoresLauncherSearchOnEscape() throws { +@Test @MainActor func emojiCommandBackNavigationRestoresLauncherSearch() throws { _ = NSApplication.shared let suite = "ConjureEmojiCommand.\(UUID().uuidString)" let defaults = UserDefaults(suiteName: suite)! @@ -215,6 +215,9 @@ import Testing search.stringValue = "emoji" launcher.controlTextDidChange(Notification(name: NSControl.textDidChangeNotification, object: search)) _ = launcher.control(search, textView: NSTextView(), doCommandBy: #selector(NSResponder.insertNewline(_:))) + let back = try #require(descendants(content).compactMap { $0 as? NSButton }.first { + !$0.isHidden && $0.accessibilityLabel() == "Back to applications" + }) let grid = try #require(descendants(content).compactMap { $0 as? NSCollectionView }.first) search.stringValue = ":woman_technologist:" launcher.controlTextDidChange(Notification(name: NSControl.textDidChangeNotification, object: search)) @@ -224,12 +227,12 @@ import Testing $0.title == "Actions" && $0.target is EmojiPickerController }) (actionsButton.target as? EmojiPickerController)?.showActions() - _ = launcher.control(search, textView: NSTextView(), doCommandBy: #selector(NSResponder.cancelOperation(_:))) + back.performClick(nil) #expect(descendants(content).contains { $0 === grid }) #expect(search.stringValue == ":woman_technologist:") let copyButton = try #require(descendants(content).compactMap { $0 as? NSButton }.first { $0.title == "Copy and Paste" }) #expect(copyButton.keyEquivalent == "\r") - _ = launcher.control(search, textView: NSTextView(), doCommandBy: #selector(NSResponder.cancelOperation(_:))) + back.performClick(nil) #expect(!descendants(content).contains { $0 === grid }) #expect(search.stringValue == "emoji") let table = try #require(descendants(content).compactMap { $0 as? NSTableView }.first) diff --git a/Tests/ConjureKitTests/EscapeDismissalTests.swift b/Tests/ConjureKitTests/EscapeDismissalTests.swift new file mode 100644 index 0000000..51b160e --- /dev/null +++ b/Tests/ConjureKitTests/EscapeDismissalTests.swift @@ -0,0 +1,60 @@ +import AppKit +import ConjureKit +import Testing +@testable import Conjure + +@Test(arguments: ["launcher", "launcher-actions", "emoji", "emoji-actions", "translate-input", "translate-output", "translate-key"]) +@MainActor func escapeDismissesEntireLauncher(_ destination: String) throws { + _ = NSApplication.shared + let suite = "ConjureEscape.\(UUID().uuidString)" + let defaults = UserDefaults(suiteName: suite)! + defer { defaults.removePersistentDomain(forName: suite) } + let launcher = LauncherWindowController( + history: LaunchHistory(defaults: defaults, now: { Date(timeIntervalSinceReferenceDate: 12_000) }), + defaults: defaults) + let window = try #require(launcher.window) + defer { window.orderOut(nil) } + let content = try #require(window.contentView) + func descendants(_ view: NSView) -> [NSView] { [view] + view.subviews.flatMap(descendants) } + let search = try #require(descendants(content).compactMap { $0 as? NSSearchField }.first) + if !destination.hasPrefix("launcher") { + search.stringValue = destination.hasPrefix("emoji") ? "emoji" : "translate" + launcher.controlTextDidChange(Notification(name: NSControl.textDidChangeNotification, object: search)) + _ = launcher.control(search, textView: NSTextView(), doCommandBy: #selector(NSResponder.insertNewline(_:))) + } + window.makeKeyAndOrderFront(nil) + window.makeFirstResponder(search) + if destination == "launcher-actions" { + search.stringValue = "emoji" + launcher.controlTextDidChange(Notification(name: NSControl.textDidChangeNotification, object: search)) + let button = try #require(descendants(content).compactMap { $0 as? NSButton }.first { + $0.title == "Actions" && $0.target === launcher + }) + button.performClick(nil) + } + if destination == "emoji-actions" { + let button = try #require(descendants(content).compactMap { $0 as? NSButton }.first { + $0.title == "Actions" && $0.target is EmojiPickerController + }) + (button.target as? EmojiPickerController)?.showActions() + } else if destination == "translate-output" { + let output = try #require(descendants(content).compactMap { $0 as? NSTextView }.first { + $0.accessibilityLabel() == "Japanese translation" + }) + window.makeFirstResponder(output) + } else if destination == "translate-key" { + let provider = try #require(descendants(content).compactMap { $0 as? NSPopUpButton }.first) + provider.selectItem(at: 1) + _ = provider.target?.perform(provider.action, with: provider) + let key = try #require(descendants(content).compactMap { $0 as? NSSecureTextField }.first) + window.makeFirstResponder(key) + } + #expect(window.isVisible) + let escape = try #require(NSEvent.keyEvent( + with: .keyDown, location: .zero, modifierFlags: [], timestamp: 1, + windowNumber: window.windowNumber, context: nil, characters: "\u{1b}", + charactersIgnoringModifiers: "\u{1b}", isARepeat: false, keyCode: 53)) + window.sendEvent(escape) + #expect(!window.isVisible) + #expect(!descendants(content).contains { $0 is NSCollectionView }) +} diff --git a/Tests/ConjureKitTests/TranslationTests.swift b/Tests/ConjureKitTests/TranslationTests.swift index f3a4007..79e9ec7 100644 --- a/Tests/ConjureKitTests/TranslationTests.swift +++ b/Tests/ConjureKitTests/TranslationTests.swift @@ -26,7 +26,7 @@ import Testing } } -@Test @MainActor func translationCommandOpensToolAndEscapeRestoresSearch() throws { +@Test @MainActor func translationCommandBackNavigationRestoresSearch() throws { _ = NSApplication.shared let launcher = LauncherWindowController() let content = try #require(launcher.window?.contentView) @@ -42,12 +42,6 @@ import Testing _ = launcher.control(search, textView: NSTextView(), doCommandBy: #selector(NSResponder.insertNewline(_:))) #expect(search.stringValue.isEmpty) #expect(search.accessibilityLabel() == "English text to translate into Japanese") - search.stringValue = "Good morning" - launcher.controlTextDidChange(Notification(name: NSControl.textDidChangeNotification, object: search)) - _ = launcher.control(search, textView: NSTextView(), doCommandBy: #selector(NSResponder.cancelOperation(_:))) - #expect(search.stringValue == "translate") - #expect(table.numberOfRows == 1) - _ = launcher.control(search, textView: NSTextView(), doCommandBy: #selector(NSResponder.insertNewline(_:))) let back = try #require(descendants(content).compactMap { $0 as? NSButton }.first { !$0.isHidden && $0.accessibilityLabel() == "Back to applications" })