TodosApp.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // TodosApp.swift
  3. // Todos
  4. //
  5. // Created by Sam Jaffe on 2/28/26.
  6. //
  7. import SwiftUI
  8. import SwiftData
  9. struct UserDefaultsKeys {
  10. private static let root = "leumasjaffe.Todos"
  11. static let UrlHints = root + ".URLHints"
  12. static let WeekStart = root + ".WeekStart"
  13. static let Category = root + ".Category"
  14. }
  15. @main
  16. struct TodosApp: App {
  17. @State private var isMoveMode = false
  18. var sharedModelContainer: ModelContainer = {
  19. let schema = Schema([
  20. Project.self,
  21. Task.self,
  22. SubTask.self,
  23. Tag.self,
  24. ])
  25. let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
  26. do {
  27. return try ModelContainer(for: schema, configurations: [modelConfiguration])
  28. } catch {
  29. fatalError("Could not create ModelContainer: \(error)")
  30. }
  31. }()
  32. var body: some Scene {
  33. WindowGroup {
  34. ContentView(isMoveMode: $isMoveMode).onAppear {
  35. // Disable the tab bar options
  36. NSWindow.allowsAutomaticWindowTabbing = false
  37. }
  38. }
  39. .modelContainer(sharedModelContainer)
  40. .commands {
  41. CommandGroup(replacing: .newItem) {
  42. NewProjectMenu()
  43. .modelContainer(sharedModelContainer)
  44. }
  45. CommandGroup(replacing: .saveItem) {
  46. SaveSnapshotMenu()
  47. .modelContainer(sharedModelContainer)
  48. SaveAsMenu()
  49. .modelContainer(sharedModelContainer)
  50. ExportMenu()
  51. .modelContainer(sharedModelContainer)
  52. ImportMenu()
  53. .modelContainer(sharedModelContainer)
  54. }
  55. CommandGroup(replacing: .toolbar) {
  56. Toggle(isOn: $isMoveMode) {
  57. Label("Move/Delete Tasks", systemImage: "pencil")
  58. }
  59. }
  60. }
  61. #if os(macOS)
  62. Settings {
  63. SettingsView()
  64. }
  65. #endif
  66. }
  67. }