Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Sources/ClickLight/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
launchAtLogin: launchAtLogin,
onCheckForUpdates: { UpdateChecker.shared.checkForUpdates() },
updatesAreConfigured: { UpdateChecker.shared.isConfigured },
onOpenSettings: { [weak self] in self?.openSettings() },
onOpenSettings: { [weak self] pane in self?.openSettings(selecting: pane) },
onQuit: { NSApplication.shared.terminate(nil) },
onMenuWillOpen: { [weak self] in
self?.hotKeyManager.unregisterAll()
Expand Down Expand Up @@ -212,7 +212,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
NSApp.terminate(nil)
}

private func openSettings() {
private func openSettings(selecting pane: SettingsPane? = nil) {
let controller = settingsWindowController ?? SettingsWindowController(
settingsStore: settingsStore,
profileStore: profileStore,
Expand All @@ -224,6 +224,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
}
)
settingsWindowController = controller
controller.show()
controller.show(selecting: pane)
}
}
11 changes: 5 additions & 6 deletions Sources/ClickLight/ClickLightSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ struct ClickLightSettingsView: View {
@ObservedObject var viewModel: ClickLightSettingsViewModel
@ObservedObject var profileStore: ClickProfileStore
@ObservedObject var activityStore: ClickActivityStore
@State private var selectedPane: SettingsPane = .general
@State private var showResetConfirmation = false
@State private var showShortcutResetConfirmation = false
@State private var showActivityResetConfirmation = false
Expand All @@ -16,7 +15,7 @@ struct ClickLightSettingsView: View {
var body: some View {
NavigationSplitView {
VStack(spacing: 0) {
List(SettingsPane.allCases, id: \.self, selection: $selectedPane) { pane in
List(SettingsPane.allCases, id: \.self, selection: $viewModel.selectedPane) { pane in
Label {
Text(pane.title)
.font(.system(size: 13, weight: .medium))
Expand Down Expand Up @@ -60,7 +59,7 @@ struct ClickLightSettingsView: View {
paneHeader

Group {
switch selectedPane {
switch viewModel.selectedPane {
case .general:
generalPane
case .style:
Expand Down Expand Up @@ -138,10 +137,10 @@ struct ClickLightSettingsView: View {

private var paneHeader: some View {
VStack(alignment: .leading, spacing: 4) {
Text(selectedPane.title)
Text(viewModel.selectedPane.title)
.font(.system(size: 22, weight: .semibold))
.accessibilityAddTraits(.isHeader)
Text(selectedPane.subtitle)
Text(viewModel.selectedPane.subtitle)
.font(.subheadline)
.foregroundStyle(.secondary)
}
Expand Down Expand Up @@ -1262,7 +1261,7 @@ private final class InteractiveClickPreviewView: NSView {
}
}

private enum SettingsPane: String, CaseIterable, Hashable {
enum SettingsPane: String, CaseIterable, Hashable {
case general
case events
case style
Expand Down
6 changes: 5 additions & 1 deletion Sources/ClickLight/SettingsWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ final class SettingsWindowController: NSWindowController {
nil
}

func show() {
func show(selecting pane: SettingsPane? = nil) {
guard let window else { return }
NSApp.activate(ignoringOtherApps: true)
showWindow(nil)
window.makeKeyAndOrderFront(nil)
window.orderFrontRegardless()
if let pane {
viewModel.selectedPane = pane
}
Comment thread
aurorascharff marked this conversation as resolved.
viewModel.refreshSystemState()
}

Expand All @@ -70,6 +73,7 @@ final class ClickLightSettingsViewModel: NSObject, ObservableObject {
@Published private(set) var accessibilityTrusted: Bool = false
@Published private(set) var inputMonitoringTrusted: Bool = false
@Published var launchAtLoginErrorMessage: String?
@Published var selectedPane: SettingsPane = .general
@Published private(set) var shortcutErrors: [ClickShortcutAction: String] = [:]
@Published private(set) var hotKeyRegistrationIssues: [ClickShortcutAction: String] = [:]

Expand Down
18 changes: 13 additions & 5 deletions Sources/ClickLight/StatusController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class StatusController: NSObject {
private let launchAtLogin: LaunchAtLoginManaging
private let onCheckForUpdates: () -> Void
private let updatesAreConfigured: () -> Bool
private let onOpenSettings: () -> Void
private let onOpenSettings: (SettingsPane?) -> Void
private let onQuit: () -> Void
private let onMenuWillOpen: () -> Void
private let onMenuDidClose: () -> Void
Expand All @@ -25,7 +25,7 @@ final class StatusController: NSObject {
launchAtLogin: LaunchAtLoginManaging,
onCheckForUpdates: @escaping () -> Void,
updatesAreConfigured: @escaping () -> Bool,
onOpenSettings: @escaping () -> Void,
onOpenSettings: @escaping (SettingsPane?) -> Void,
onQuit: @escaping () -> Void,
onMenuWillOpen: @escaping () -> Void = {},
onMenuDidClose: @escaping () -> Void = {}
Expand Down Expand Up @@ -335,7 +335,7 @@ final class StatusController: NSObject {
menu.addItem(selectedCustom)
}

let configureCustom = NSMenuItem(title: "Configure Custom Colors...", action: #selector(openSettings), keyEquivalent: "")
let configureCustom = NSMenuItem(title: "Configure Custom Colors...", action: #selector(openVisualStyleSettings), keyEquivalent: "")
configureCustom.target = self
menu.addItem(configureCustom)

Expand Down Expand Up @@ -364,7 +364,7 @@ final class StatusController: NSObject {
}

menu.addItem(.separator())
let manageItem = NSMenuItem(title: "Manage Profiles...", action: #selector(openSettings), keyEquivalent: "")
let manageItem = NSMenuItem(title: "Manage Profiles...", action: #selector(openProfileSettings), keyEquivalent: "")
manageItem.target = self
menu.addItem(manageItem)

Expand All @@ -378,7 +378,15 @@ final class StatusController: NSObject {
}

@objc private func openSettings() {
onOpenSettings()
onOpenSettings(nil)
}

@objc private func openProfileSettings() {
onOpenSettings(.profiles)
}

@objc private func openVisualStyleSettings() {
onOpenSettings(.style)
}

@objc private func togglePress(_ sender: NSMenuItem) {
Expand Down