TodosApp.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. var sharedModelContainer: ModelContainer = {
  18. let schema = Schema([
  19. Project.self,
  20. Task.self,
  21. SubTask.self,
  22. Tag.self
  23. ])
  24. let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
  25. do {
  26. return try ModelContainer(for: schema, configurations: [modelConfiguration])
  27. } catch {
  28. fatalError("Could not create ModelContainer: \(error)")
  29. }
  30. }()
  31. @State private var rotate = RotateTracking()
  32. var body: some Scene {
  33. WindowGroup {
  34. ContentView(rotate: $rotate).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. RotateContentMenu(rotate: $rotate)
  55. .modelContainer(sharedModelContainer)
  56. }
  57. }
  58. #if os(macOS)
  59. Settings {
  60. SettingsView()
  61. }
  62. #endif
  63. }
  64. }