Skip to content

Commit d940120

Browse files
committed
refactor: split ShortcutSettings by domain into PanelSettings, StorageSettings
1 parent f4b7631 commit d940120

19 files changed

Lines changed: 758 additions & 716 deletions

‎EdgeMark/App/AppDelegate.swift‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
2626
let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "?"
2727
let build = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "?"
2828
Log.app.info("[AppDelegate] launched v\(version, privacy: .public) (build \(build, privacy: .public))")
29-
ShortcutSettings.shared.applyAppearance()
29+
AppSettings.shared.applyAppearance()
3030
setupMenuBar()
3131
panelController = SidePanelController()
3232
SidecarMigration.runIfNeeded()
@@ -38,7 +38,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
3838
// non-blocking storage-root picker as the panel's empty state instead of the
3939
// note list. The persistent active root's notes are loaded already; picking a
4040
// root in the picker switches to it for the session (temporary override).
41-
if ShortcutSettings.shared.askOnLaunch, ShortcutSettings.shared.storageRoots.count >= 2 {
41+
if StorageSettings.shared.askOnLaunch, StorageSettings.shared.storageRoots.count >= 2 {
4242
panelController?.noteStore.awaitingRootChoice = true
4343
}
4444

@@ -52,7 +52,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
5252
}
5353

5454
// Auto-check for updates on launch (24h throttle, respects user setting)
55-
if ShortcutSettings.shared.autoCheckUpdates {
55+
if AppSettings.shared.autoCheckUpdates {
5656
Task {
5757
await checkForUpdatesOnLaunch()
5858
}
@@ -147,8 +147,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
147147
// While the ask-on-launch picker is up, no root has been chosen for the session
148148
// yet (sessionRootOverride is nil) — show no checkmark until one is picked.
149149
let awaiting = panelController?.noteStore.awaitingRootChoice ?? false
150-
let activeID = awaiting ? nil : ShortcutSettings.shared.activeStorageRoot?.id
151-
for root in ShortcutSettings.shared.storageRoots {
150+
let activeID = awaiting ? nil : StorageSettings.shared.activeStorageRoot?.id
151+
for root in StorageSettings.shared.storageRoots {
152152
let item = NSMenuItem(
153153
title: root.displayName,
154154
action: #selector(switchToStorageRoot(sender:)),
@@ -159,18 +159,18 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
159159
item.state = (root.id == activeID) ? .on : .off
160160
submenu.addItem(item)
161161
}
162-
if !ShortcutSettings.shared.storageRoots.isEmpty {
162+
if !StorageSettings.shared.storageRoots.isEmpty {
163163
submenu.addItem(.separator())
164164
let hint = NSMenuItem(title: L10n.shared["menu.storageTemporary"], action: nil, keyEquivalent: "")
165165
hint.isEnabled = false
166166
submenu.addItem(hint)
167167
}
168-
storageMenuItem?.isHidden = ShortcutSettings.shared.storageRoots.count < 2
168+
storageMenuItem?.isHidden = StorageSettings.shared.storageRoots.count < 2
169169
}
170170

171171
@objc private func switchToStorageRoot(sender: NSMenuItem) {
172172
guard let id = sender.representedObject as? String,
173-
let root = ShortcutSettings.shared.storageRoots.first(where: { $0.id == id })
173+
let root = StorageSettings.shared.storageRoots.first(where: { $0.id == id })
174174
else { return }
175175
switchRoot(to: root, temporary: true)
176176
}
@@ -185,11 +185,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
185185
panel.prompt = L10n.shared["common.select"]
186186

187187
// Pre-select current storage directory
188-
panel.directoryURL = ShortcutSettings.shared.resolvedStorageDirectory
188+
panel.directoryURL = StorageSettings.shared.resolvedStorageDirectory
189189

190190
panel.begin { [weak self] response in
191191
guard response == .OK, let newURL = panel.url else { return }
192-
let oldURL = ShortcutSettings.shared.resolvedStorageDirectory
192+
let oldURL = StorageSettings.shared.resolvedStorageDirectory
193193
guard newURL != oldURL else { return }
194194

195195
// Save dirty notes to old location first
@@ -200,7 +200,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
200200
Self.migrateStorageContents(from: oldURL, to: newURL)
201201

202202
// Update the roots model: the migrated-to dir becomes the active root.
203-
var roots = ShortcutSettings.shared.storageRoots
203+
var roots = StorageSettings.shared.storageRoots
204204
let activeID: String
205205
if let existing = roots.first(where: { $0.url == newURL }) {
206206
activeID = existing.id
@@ -209,9 +209,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
209209
roots.append(root)
210210
activeID = root.id
211211
}
212-
ShortcutSettings.shared.storageRoots = roots
213-
ShortcutSettings.shared.activeRootID = activeID
214-
ShortcutSettings.shared.sessionRootOverride = nil
212+
StorageSettings.shared.storageRoots = roots
213+
StorageSettings.shared.activeRootID = activeID
214+
StorageSettings.shared.sessionRootOverride = nil
215215
// Reload notes AND sidecar from the new location (the old changeNotesFolder
216216
// path reloaded notes but not the sidecar — a latent bug fixed here).
217217
try? SidecarStore.shared.load()
@@ -241,18 +241,18 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
241241
panelController?.noteStore.awaitingRootChoice = false
242242
}
243243
// Don't no-op-switch to the already-active root.
244-
if ShortcutSettings.shared.activeStorageRoot?.id == root.id {
244+
if StorageSettings.shared.activeStorageRoot?.id == root.id {
245245
return
246246
}
247247

248248
// Flush unsaved edits in the outgoing root before switching.
249249
panelController?.noteStore.saveDirtyNotes()
250250

251251
if temporary {
252-
ShortcutSettings.shared.sessionRootOverride = root
252+
StorageSettings.shared.sessionRootOverride = root
253253
} else {
254-
ShortcutSettings.shared.sessionRootOverride = nil
255-
ShortcutSettings.shared.activeRootID = root.id
254+
StorageSettings.shared.sessionRootOverride = nil
255+
StorageSettings.shared.activeRootID = root.id
256256
}
257257

258258
// Reload sidecar (per-root meta.json) and notes for the new root, inside
@@ -318,7 +318,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
318318
}
319319

320320
private func fireBackgroundCheck() {
321-
guard ShortcutSettings.shared.autoCheckUpdates else { return }
321+
guard AppSettings.shared.autoCheckUpdates else { return }
322322
Task {
323323
await updateState.check(source: .launch)
324324
if case let .available(release) = updateState.status {

‎EdgeMark/App/ContentView.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct ContentView: View {
1919
/// Horizontal page transition based on navigation direction.
2020
/// Falls back to opacity when the user has chosen Fade animation style.
2121
private var pageTransition: AnyTransition {
22-
guard ShortcutSettings.shared.animationStyle == .slide else { return .opacity }
22+
guard PanelSettings.shared.animationStyle == .slide else { return .opacity }
2323
switch noteStore.navigationDirection {
2424
case .forward:
2525
return .asymmetric(
@@ -38,7 +38,7 @@ struct ContentView: View {
3838

3939
/// Trash uses vertical slide (from bottom), or opacity in Fade mode.
4040
private var trashTransition: AnyTransition {
41-
guard ShortcutSettings.shared.animationStyle == .slide else { return .opacity }
41+
guard PanelSettings.shared.animationStyle == .slide else { return .opacity }
4242
return .asymmetric(
4343
insertion: .move(edge: .bottom),
4444
removal: .move(edge: .bottom),

‎EdgeMark/Core/Settings/AppSettings.swift‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import AppKit
22
import Foundation
3+
import OSLog
4+
import ServiceManagement
35

46
@Observable
57
final class AppSettings {
@@ -119,6 +121,59 @@ final class AppSettings {
119121
didSet { UserDefaults.standard.set(taskCheckboxPreset.rawValue, forKey: "taskCheckboxPreset") }
120122
}
121123

124+
// MARK: - Appearance, updates, launch
125+
126+
enum AppearanceMode: String {
127+
case system
128+
case light
129+
case dark
130+
}
131+
132+
/// Appearance mode: system, light, or dark.
133+
var appearanceMode: AppearanceMode = .system {
134+
didSet {
135+
UserDefaults.standard.set(appearanceMode.rawValue, forKey: "appearanceMode")
136+
applyAppearance()
137+
}
138+
}
139+
140+
/// Whether to automatically check for updates on launch (24h throttle).
141+
var autoCheckUpdates: Bool = true {
142+
didSet { UserDefaults.standard.set(autoCheckUpdates, forKey: "autoCheckUpdates") }
143+
}
144+
145+
/// Whether the app launches at login.
146+
var launchAtLogin: Bool = false {
147+
didSet {
148+
UserDefaults.standard.set(launchAtLogin, forKey: "launchAtLogin")
149+
updateLoginItem()
150+
}
151+
}
152+
153+
func applyAppearance() {
154+
switch appearanceMode {
155+
case .system:
156+
NSApp.appearance = nil
157+
case .light:
158+
NSApp.appearance = NSAppearance(named: .aqua)
159+
case .dark:
160+
NSApp.appearance = NSAppearance(named: .darkAqua)
161+
}
162+
}
163+
164+
private func updateLoginItem() {
165+
do {
166+
if launchAtLogin {
167+
try SMAppService.mainApp.register()
168+
} else {
169+
try SMAppService.mainApp.unregister()
170+
}
171+
} catch {
172+
let msg = error.localizedDescription
173+
Log.app.error("Failed to update login item: \(msg)")
174+
}
175+
}
176+
122177
// MARK: - Panel opacity
123178

124179
enum PanelStyle: String, CaseIterable {
@@ -264,6 +319,14 @@ final class AppSettings {
264319
{
265320
taskCheckboxPreset = value
266321
}
322+
// Appearance, updates, launch (moved from ShortcutSettings)
323+
if let raw = UserDefaults.standard.string(forKey: "appearanceMode"),
324+
let mode = AppearanceMode(rawValue: raw)
325+
{
326+
appearanceMode = mode
327+
}
328+
autoCheckUpdates = UserDefaults.standard.object(forKey: "autoCheckUpdates") as? Bool ?? true
329+
launchAtLogin = UserDefaults.standard.object(forKey: "launchAtLogin") as? Bool ?? false
267330
if let raw = UserDefaults.standard.object(forKey: "spellCheckingEnabled") as? Bool {
268331
spellCheckingEnabled = raw
269332
}

0 commit comments

Comments
 (0)