SPB Git

Repository Public

SPNotesWidgets.swift 3.5 KB 90 lines swift

1// SP Notes iOS2// File: Widgets/SPNotesWidgets.swift3// Description: Widget bundle: recent notes, pinned notes, new note, one chosen note, and « Capture et tâches » (interactive).4//              The views live in WidgetShared/.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import SwiftUI9import WidgetKit1011@main12struct SPNotesWidgetBundle: WidgetBundle {13    var body: some Widget {14        RecentNotesWidget()15        PinnedNotesWidget()16        NewNoteWidget()17        SingleNoteWidget()18        TasksWidget()19    }20}2122/// Reads the family from the environment (the shared views take it as a parameter) and sets the widget background.23private struct FamilyReader<Content: View>: View {24    @Environment(\.widgetFamily) private var family25    @ViewBuilder let content: (WidgetFamily) -> Content26    var body: some View {27        content(family).containerBackground(for: .widget) { WidgetTone.background }28    }29}3031struct RecentNotesWidget: Widget {32    static let kind = WidgetKinds.recent33    var body: some WidgetConfiguration {34        StaticConfiguration(kind: Self.kind, provider: NotesListProvider(kind: .recent)) { entry in35            FamilyReader { NotesListWidgetView(kind: .recent, content: entry.content, family: $0) }36        }37        .configurationDisplayName("Notes récentes")38        .description("Tes dernières notes, à portée de main.")39        .supportedFamilies([.systemSmall, .systemMedium, .systemLarge, .accessoryRectangular])40    }41}4243struct PinnedNotesWidget: Widget {44    static let kind = WidgetKinds.pinned45    var body: some WidgetConfiguration {46        StaticConfiguration(kind: Self.kind, provider: NotesListProvider(kind: .pinned)) { entry in47            FamilyReader { NotesListWidgetView(kind: .pinned, content: entry.content, family: $0) }48        }49        .configurationDisplayName("Notes épinglées")50        .description("Les notes que tu as épinglées.")51        .supportedFamilies([.systemMedium, .systemLarge])52    }53}5455struct NewNoteWidget: Widget {56    static let kind = WidgetKinds.new57    var body: some WidgetConfiguration {58        StaticConfiguration(kind: Self.kind, provider: StaticProvider()) { _ in59            FamilyReader { NewNoteWidgetView(family: $0) }60        }61        .configurationDisplayName("Nouvelle note")62        .description("Commence une note ou une liste de tâches d’un seul geste.")63        .supportedFamilies([.systemSmall, .systemMedium, .accessoryCircular])64    }65}6667struct SingleNoteWidget: Widget {68    static let kind = WidgetKinds.note69    var body: some WidgetConfiguration {70        AppIntentConfiguration(kind: Self.kind, intent: SelectNoteIntent.self, provider: SingleNoteProvider()) { entry in71            FamilyReader { SingleNoteWidgetView(state: entry.state, family: $0) }72        }73        .configurationDisplayName("Note")74        .description("Garde une note sous les yeux.")75        .supportedFamilies([.systemSmall, .systemMedium, .systemLarge])76    }77}7879struct TasksWidget: Widget {80    static let kind = WidgetKinds.tasks81    var body: some WidgetConfiguration {82        StaticConfiguration(kind: Self.kind, provider: TasksProvider()) { entry in83            FamilyReader { TasksWidgetView(content: entry.content, family: $0, now: entry.date) }84        }85        .configurationDisplayName("Capture et tâches")86        .description("Capture une note, une tâche ou une dictée, et coche les tâches du jour sans ouvrir l’app.")87        .supportedFamilies([.systemSmall, .systemMedium, .systemLarge, .accessoryCircular])88    }89}90
Files main
Menu

Theme