working on getting watch app to actually work

This commit is contained in:
breadone
2024-07-10 11:44:58 +12:00
parent f2de4ae7cc
commit a174b096fd
14 changed files with 130 additions and 54 deletions

View File

@@ -1,6 +1,7 @@
{
"images" : [
{
"filename" : "oncue_icon.png",
"idiom" : "universal",
"platform" : "watchos",
"size" : "1024x1024"

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 KiB

View File

@@ -7,6 +7,7 @@
import SwiftUI
import SwiftData
import CoreData
@main
struct OnCuePresenter_Watch_AppApp: App {
@@ -14,11 +15,37 @@ struct OnCuePresenter_Watch_AppApp: App {
let schema = Schema([
OCProject.self,
OCCard.self,
// Item.self,
])
let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
do {
#if DEBUG
// Use an autorelease pool to make sure Swift deallocates the persistent
// container before setting up the SwiftData stack.
try autoreleasepool {
let desc = NSPersistentStoreDescription(url: modelConfiguration.url)
let opts = NSPersistentCloudKitContainerOptions(containerIdentifier: "iCloud.xyz.breadone.oncue")
desc.cloudKitContainerOptions = opts
// Load the store synchronously so it completes before initializing the
// CloudKit schema.
desc.shouldAddStoreAsynchronously = false
if let mom = NSManagedObjectModel.makeManagedObjectModel(for: [OCProject.self, OCCard.self]) {
let container = NSPersistentCloudKitContainer(name: "OnCue", managedObjectModel: mom)
container.persistentStoreDescriptions = [desc]
container.loadPersistentStores {_, err in
if let err {
fatalError(err.localizedDescription)
}
}
// Initialize the CloudKit schema after the store finishes loading.
try container.initializeCloudKitSchema()
// Remove and unload the store from the persistent container.
if let store = container.persistentStoreCoordinator.persistentStores.first {
try container.persistentStoreCoordinator.remove(store)
}
}
}
#endif
return try ModelContainer(for: schema, configurations: [modelConfiguration])
} catch {
fatalError("Could not create ModelContainer: \(error)")

View File

@@ -12,6 +12,7 @@ struct MainViewPresenter: View {
@Environment(\.modelContext) private var modelContext
@Query private var items: [OCProject]
@AppStorage(Preferences.themeColour) var themeColor = Color.blue.toHex()!
@State private var newProjectName = ""
@State private var addNewProject = false
@@ -23,13 +24,19 @@ struct MainViewPresenter: View {
CueCardViewPresenter(project: project)
} label: {
VStack(alignment: .leading) {
Text("\(project.name)")
.bold()
.font(.title2)
.foregroundStyle(Color(hex: project.color) ?? .white)
if (project.color == Color.clear.toHex()!) {
Text("\(project.name)")
.bold()
.font(.title2)
.foregroundStyle(Color(hex: themeColor) ?? .blue)
} else {
Text("\(project.name)")
.bold()
.font(.title2)
.foregroundStyle(Color(hex: project.color) ?? .white)
}
Text("\(project.cards?.count ?? 0) \(project.cards?.count ?? 0 == 1 ? "Card" : "Cards")")
}
}
} }
.padding(.vertical, 3)
}