SPB Git

Repository Public

FeatureCommands.swift 4.5 KB 93 lines swift

1// SP Notes Core2// File: Sources/SPNotesFeatures/Command/FeatureCommands.swift3// Description: The commands the Features library can provide by itself: one « Aller à » command per feature screen4//              (the host says how a destination is shown), « Synchroniser maintenant », and one command per database5//              of the device. Everything else (new page, export, settings, windows…) is registered by the app.6//7// Author: Simon-Pierre Boucher8// Contact: contact@spboucher.ai9import Foundation10import SPNotesSync1112/// The feature screens an app can navigate to.13public enum FeatureDestination: String, Sendable, Hashable, CaseIterable, Identifiable {14    case brief, tasks, inbox, search, ask, graph, constellation, timeline, health, research15    public var id: String { rawValue }1617    public var title: String {18        switch self {19        case .brief: return L("Brief du jour")20        case .tasks: return L("Tâches")21        case .inbox: return L("Boîte de réception")22        case .search: return L("Recherche")23        case .ask: return L("Demander à mes notes")24        case .graph: return L("Graphe de connaissances")25        case .constellation: return L("Constellation")26        case .timeline: return L("Chronologie")27        case .health: return L("Santé des connaissances")28        case .research: return L("Recherche documentaire")29        }30    }3132    /// Search terms beyond the title (English names included: many users type them).33    public var keywords: String {34        switch self {35        case .brief: return "daily brief aujourd'hui matin résumé"36        case .tasks: return "tasks todo à faire échéances"37        case .inbox: return "inbox capture tri triage"38        case .search: return "search find chercher trouver"39        case .ask: return "ask ai ia assistant question chat"40        case .graph: return "graph liens relations réseau"41        case .constellation: return "constellation carte map clusters"42        case .timeline: return "timeline journal historique time machine remonter le temps"43        case .health: return "health orphelines liens cassés doublons"44        case .research: return "research références bibliographie doi bibtex citations"45        }46    }4748    public var systemImage: String {49        switch self {50        case .brief: return "sun.max"51        case .tasks: return "checklist"52        case .inbox: return "tray"53        case .search: return "magnifyingglass"54        case .ask: return "sparkles"55        case .graph: return "point.3.connected.trianglepath.dotted"56        case .constellation: return "sparkle"57        case .timeline: return "clock.arrow.circlepath"58        case .health: return "stethoscope"59        case .research: return "books.vertical"60        }61    }62}6364public enum FeatureCommands {65    public static let ownerDestinations = "features.destinations"66    public static let ownerStandard = "features.standard"6768    /// One « Aller à » command per destination; `open` is the host's navigation.69    @MainActor70    public static func destinations(_ destinations: [FeatureDestination] = FeatureDestination.allCases, open: @escaping @MainActor (FeatureDestination) -> Void) -> [FeatureCommand] {71        destinations.map { destination in72            FeatureCommand(id: "nav." + destination.rawValue, title: destination.title, keywords: destination.keywords, systemImage: destination.systemImage,73                           section: L("Aller à")) { open(destination) }74        }75    }7677    /// What Features can do alone: ask for a sync, open each database of the device.78    @MainActor79    public static func standard(repositories: NotesRepositories, router: any FeatureRouter) async -> [FeatureCommand] {80        var commands = [81            FeatureCommand(id: "sync.now", title: L("Synchroniser maintenant"), keywords: "sync refresh actualiser envoyer", systemImage: "arrow.triangle.2.circlepath",82                           section: L("Général")) { await repositories.context.scheduleSync() },83        ]84        let databases = (try? await repositories.databases.list()) ?? []85        for database in databases {86            let name = database.name.isEmpty ? L("Sans titre") : database.name87            commands.append(FeatureCommand(id: "database." + database.id, title: LF("Ouvrir la base « %@ »", name), keywords: "database base table " + name,88                                           systemImage: "tablecells", section: L("Bases de données")) { [weak router] in router?.openDatabase(id: database.id) })89        }90        return commands91    }92}93
Files main
Menu

Theme