fix: reload tint colors while running
This commit is contained in:
@@ -4,6 +4,7 @@ import ConjureKit
|
||||
@MainActor
|
||||
final class ApplicationActionsController: NSViewController, NSSearchFieldDelegate, NSTableViewDataSource, NSTableViewDelegate {
|
||||
private var search: ActionsSearchField!
|
||||
private var themeObservation: ThemeObservation?
|
||||
private var background: LauncherBackground!
|
||||
private var entries: [ActionEntry] = []
|
||||
private var visibleEntries: [Int] = []
|
||||
@@ -74,23 +75,23 @@ final class ApplicationActionsController: NSViewController, NSSearchFieldDelegat
|
||||
selectionScroll = nil
|
||||
selectionViewportHeight = nil
|
||||
entries = [
|
||||
ActionEntry(title: "Open", symbol: "arrow.up.forward.app", color: ThemePalette.text),
|
||||
ActionEntry(title: "Favorite", symbol: "star", color: ThemePalette.text),
|
||||
ActionEntry(title: "Show in Finder", symbol: "finder", color: ThemePalette.text),
|
||||
ActionEntry(title: "Reset ranking", symbol: "arrow.counterclockwise", color: ThemePalette.text),
|
||||
ActionEntry(title: "Quit application", symbol: "stop.circle", color: ThemePalette.text),
|
||||
ActionEntry(title: "Uninstall application", symbol: "trash", color: ThemePalette.error),
|
||||
ActionEntry(title: "Copy Emoji", symbol: "doc.on.doc", color: ThemePalette.text),
|
||||
ActionEntry(title: "Change source language…", symbol: "character.bubble", color: ThemePalette.text),
|
||||
ActionEntry(title: "Change target language…", symbol: "character.bubble", color: ThemePalette.text),
|
||||
ActionEntry(title: "Swap languages", symbol: "arrow.left.arrow.right", color: ThemePalette.text),
|
||||
ActionEntry(title: "MyMemory (no key)", symbol: "checkmark", color: ThemePalette.text),
|
||||
ActionEntry(title: "OpenAI · gpt-6-luna", symbol: "checkmark", color: ThemePalette.text),
|
||||
ActionEntry(title: "Browse Notes", symbol: "list.bullet", color: ThemePalette.text, commandKey: "P"),
|
||||
ActionEntry(title: "New Note", symbol: "square.and.pencil", color: ThemePalette.text, commandKey: "N"),
|
||||
ActionEntry(title: "Delete Note", symbol: "trash", color: ThemePalette.error),
|
||||
ActionEntry(title: "Copy as Markdown", symbol: "doc.on.doc", color: ThemePalette.text),
|
||||
ActionEntry(title: "Export as Markdown…", symbol: "square.and.arrow.up", color: ThemePalette.text)
|
||||
ActionEntry(title: "Open", symbol: "arrow.up.forward.app"),
|
||||
ActionEntry(title: "Favorite", symbol: "star"),
|
||||
ActionEntry(title: "Show in Finder", symbol: "finder"),
|
||||
ActionEntry(title: "Reset ranking", symbol: "arrow.counterclockwise"),
|
||||
ActionEntry(title: "Quit application", symbol: "stop.circle"),
|
||||
ActionEntry(title: "Uninstall application", symbol: "trash", destructive: true),
|
||||
ActionEntry(title: "Copy Emoji", symbol: "doc.on.doc"),
|
||||
ActionEntry(title: "Change source language…", symbol: "character.bubble"),
|
||||
ActionEntry(title: "Change target language…", symbol: "character.bubble"),
|
||||
ActionEntry(title: "Swap languages", symbol: "arrow.left.arrow.right"),
|
||||
ActionEntry(title: "MyMemory (no key)", symbol: "checkmark"),
|
||||
ActionEntry(title: "OpenAI · gpt-6-luna", symbol: "checkmark"),
|
||||
ActionEntry(title: "Browse Notes", symbol: "list.bullet", commandKey: "P"),
|
||||
ActionEntry(title: "New Note", symbol: "square.and.pencil", commandKey: "N"),
|
||||
ActionEntry(title: "Delete Note", symbol: "trash", destructive: true),
|
||||
ActionEntry(title: "Copy as Markdown", symbol: "doc.on.doc"),
|
||||
ActionEntry(title: "Export as Markdown…", symbol: "square.and.arrow.up")
|
||||
]
|
||||
view = ActionsPanelView()
|
||||
view.wantsLayer = true
|
||||
@@ -212,6 +213,13 @@ final class ApplicationActionsController: NSViewController, NSSearchFieldDelegat
|
||||
selectionViewportHeight = viewportHeight
|
||||
}
|
||||
updateSelection()
|
||||
themeObservation = ThemeObservation { [weak self, weak content] in
|
||||
guard let self else { return }
|
||||
self.search.applyTheme()
|
||||
self.applicationLabel.textColor = ThemePalette.secondaryText
|
||||
self.empty.textColor = ThemePalette.secondaryText
|
||||
content?.layer?.borderColor = ThemePalette.secondaryText.withAlphaComponent(0.22).cgColor
|
||||
}
|
||||
}
|
||||
|
||||
func show(for application: Application, relativeTo anchor: NSView) {
|
||||
@@ -558,8 +566,10 @@ private struct ActionEntry {
|
||||
let icon: IconView
|
||||
let returnKey: ShortcutIndicator
|
||||
let hasCommandKey: Bool
|
||||
private var themeObservation: ThemeObservation?
|
||||
|
||||
init(title: String, symbol: String, color: NSColor, commandKey: String? = nil) {
|
||||
init(title: String, symbol: String, destructive: Bool = false, commandKey: String? = nil) {
|
||||
let color = destructive ? ThemePalette.error : ThemePalette.text
|
||||
hasCommandKey = commandKey != nil
|
||||
returnKey = commandKey.map { ShortcutIndicator("⌘", $0) } ?? ShortcutIndicator("↵")
|
||||
let font = NSFont.systemFont(ofSize: LauncherRowView.textSize, weight: .medium)
|
||||
@@ -590,12 +600,22 @@ private struct ActionEntry {
|
||||
returnKey.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -12),
|
||||
returnKey.centerYAnchor.constraint(equalTo: view.centerYAnchor)
|
||||
])
|
||||
themeObservation = ThemeObservation { [weak button, weak icon] in
|
||||
let color = destructive ? ThemePalette.error : ThemePalette.text
|
||||
button?.contentTintColor = color
|
||||
if let button {
|
||||
let title = NSMutableAttributedString(attributedString: button.attributedTitle)
|
||||
title.addAttribute(.foregroundColor, value: color, range: NSRange(location: 0, length: title.length))
|
||||
button.attributedTitle = title
|
||||
}
|
||||
icon?.contentTintColor = color
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private final class SelectionCell: NSView {
|
||||
let entry = ActionEntry(title: "", symbol: "checkmark", color: ThemePalette.text)
|
||||
let entry = ActionEntry(title: "", symbol: "checkmark")
|
||||
|
||||
init() {
|
||||
super.init(frame: .zero)
|
||||
|
||||
Reference in New Issue
Block a user