iOS widgets and clock Live Activity !185
15 files changed, +1162 −1
Layout: unified · split
Sources/OrgApp/AgendaSnapshot.swift added +272
| @@ -0,0 +1,272 @@ | |||
| 1 | import Foundation | ||
| 2 | import OrgCore | ||
| 3 | import OrgPresentation | ||
| 4 | |||
| 5 | /// The next days of the agenda for widgets, which can't read the folders: the app writes it | ||
| 6 | /// as JSON into the app group's container, the widgets read it. | ||
| 7 | public struct AgendaSnapshot: Codable, Equatable, Sendable { | ||
| 8 | /// Days from today the snapshot holds. | ||
| 9 | public static let dayCount = 7 | ||
| 10 | |||
| 11 | /// A color in light and dark appearance, `#rrggbb` or `#rrggbbaa`. | ||
| 12 | public struct Hex: Codable, Equatable, Sendable { | ||
| 13 | public var light: String | ||
| 14 | public var dark: String | ||
| 15 | |||
| 16 | public init(light: String, dark: String) { | ||
| 17 | self.light = light | ||
| 18 | self.dark = dark | ||
| 19 | } | ||
| 20 | |||
| 21 | init?(_ color: (Bool) -> RGBA?) { | ||
| 22 | guard let light = color(false) ?? color(true), let dark = color(true) ?? color(false) else { return nil } | ||
| 23 | self.init(light: light.hex, dark: dark.hex) | ||
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 27 | public struct Row: Codable, Equatable, Sendable, Identifiable { | ||
| 28 | public var id: String | ||
| 29 | /// `AgendaRow.gutter`: the time or a short status. | ||
| 30 | public var gutter: String | ||
| 31 | /// `AgendaRow.Status`'s raw value. | ||
| 32 | public var status: String | ||
| 33 | public var title: String | ||
| 34 | public var category: String | ||
| 35 | public var todo: String? | ||
| 36 | public var priority: String? | ||
| 37 | public var isDone: Bool | ||
| 38 | public var isEvent: Bool | ||
| 39 | /// When a timed row starts and ends. | ||
| 40 | public var start: Date? | ||
| 41 | public var end: Date? | ||
| 42 | /// The Org entry, for a link to it. | ||
| 43 | public var path: String? | ||
| 44 | public var offset: Int? | ||
| 45 | public var statusColor: Hex? | ||
| 46 | public var todoColor: Hex? | ||
| 47 | public var priorityColor: Hex? | ||
| 48 | public var categoryColor: Hex? | ||
| 49 | |||
| 50 | public init( | ||
| 51 | id: String, gutter: String, status: String, title: String, category: String, todo: String?, priority: String?, isDone: Bool, | ||
| 52 | isEvent: Bool, start: Date?, end: Date?, path: String?, offset: Int?, statusColor: Hex?, todoColor: Hex?, priorityColor: Hex?, | ||
| 53 | categoryColor: Hex? | ||
| 54 | ) { | ||
| 55 | self.id = id | ||
| 56 | self.gutter = gutter | ||
| 57 | self.status = status | ||
| 58 | self.title = title | ||
| 59 | self.category = category | ||
| 60 | self.todo = todo | ||
| 61 | self.priority = priority | ||
| 62 | self.isDone = isDone | ||
| 63 | self.isEvent = isEvent | ||
| 64 | self.start = start | ||
| 65 | self.end = end | ||
| 66 | self.path = path | ||
| 67 | self.offset = offset | ||
| 68 | self.statusColor = statusColor | ||
| 69 | self.todoColor = todoColor | ||
| 70 | self.priorityColor = priorityColor | ||
| 71 | self.categoryColor = categoryColor | ||
| 72 | } | ||
| 73 | |||
| 74 | public var link: AppLink? { | ||
| 75 | guard let path, let offset else { return nil } | ||
| 76 | return .entry(path: path, offset: offset) | ||
| 77 | } | ||
| 78 | |||
| 79 | /// Not done and not a calendar event. | ||
| 80 | public var isOpen: Bool { !isDone && !isEvent } | ||
| 81 | } | ||
| 82 | |||
| 83 | public struct Day: Codable, Equatable, Sendable, Identifiable { | ||
| 84 | /// As `Days` numbers it. | ||
| 85 | public var day: Int | ||
| 86 | /// Midnight starting the day. | ||
| 87 | public var date: Date | ||
| 88 | public var header: String | ||
| 89 | /// Today only: deadlines and scheduled entries from before today. | ||
| 90 | public var overdue: [Row] | ||
| 91 | public var rows: [Row] | ||
| 92 | |||
| 93 | public var id: Int { day } | ||
| 94 | |||
| 95 | public init(day: Int, date: Date, header: String, overdue: [Row], rows: [Row]) { | ||
| 96 | self.day = day | ||
| 97 | self.date = date | ||
| 98 | self.header = header | ||
| 99 | self.overdue = overdue | ||
| 100 | self.rows = rows | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | public var generated: Date | ||
| 105 | public var days: [Day] | ||
| 106 | /// The agenda's colors the widgets use: `agenda-today`, `agenda-time`, `agenda-date`, | ||
| 107 | /// `foreground`, and `agenda-background` when the theme sets one. | ||
| 108 | public var colors: [String: Hex] | ||
| 109 | |||
| 110 | public init(generated: Date, days: [Day], colors: [String: Hex]) { | ||
| 111 | self.generated = generated | ||
| 112 | self.days = days | ||
| 113 | self.colors = colors | ||
| 114 | } | ||
| 115 | |||
| 116 | /// The groups from `today` through `dayCount - 1` days later, colored by `theme`. | ||
| 117 | public init( | ||
| 118 | groups: [AgendaDayGroup], today: Int, dayCount: Int = AgendaSnapshot.dayCount, theme: ThemeSpec, generated: Date, | ||
| 119 | calendar: Calendar = .current | ||
| 120 | ) { | ||
| 121 | func row(_ row: AgendaRow, midnight: Date) -> Row { | ||
| 122 | func at(_ hhmm: Int?) -> Date? { | ||
| 123 | hhmm.flatMap { calendar.date(byAdding: .minute, value: ($0 / 100) * 60 + $0 % 100, to: midnight) } | ||
| 124 | } | ||
| 125 | let item = row.item | ||
| 126 | return Row( | ||
| 127 | id: row.id, gutter: row.gutter, status: row.status.rawValue, title: row.title, category: row.category, todo: row.todo, | ||
| 128 | priority: row.priority, isDone: row.isDone, isEvent: row.isEvent, start: at(row.start), end: at(row.end), | ||
| 129 | path: item?.path, offset: item.flatMap { $0.headingOffset ?? $0.markerOffset }, | ||
| 130 | statusColor: Hex { theme.statusColor(row.status, dark: $0) }, | ||
| 131 | todoColor: row.todo.flatMap { todo in Hex { theme.todoColor(todo, isDone: row.isDone, dark: $0) } }, | ||
| 132 | priorityColor: row.priority.flatMap { priority in Hex { theme.priorityColor(priority, dark: $0) } }, | ||
| 133 | categoryColor: Hex { dark -> RGBA? in | ||
| 134 | if let event = row.event { return theme.eventColor(event, dark: dark) } | ||
| 135 | return theme.categoryColor(row.category, dark: dark) | ||
| 136 | } | ||
| 137 | ) | ||
| 138 | } | ||
| 139 | days = groups.filter { $0.day >= today && $0.day < today + dayCount }.map { group in | ||
| 140 | let midnight = group.date(calendar: calendar) | ||
| 141 | return Day( | ||
| 142 | day: group.day, date: midnight, header: group.header, | ||
| 143 | overdue: group.overdue.map { row($0, midnight: midnight) }, rows: group.rows.map { row($0, midnight: midnight) } | ||
| 144 | ) | ||
| 145 | } | ||
| 146 | var colors: [String: Hex] = [:] | ||
| 147 | for key in ["agenda-today", "agenda-time", "agenda-date", "foreground", "agenda-background"] { | ||
| 148 | colors[key] = Hex { theme.color(key, dark: $0) } | ||
| 149 | } | ||
| 150 | self.colors = colors | ||
| 151 | self.generated = generated | ||
| 152 | } | ||
| 153 | |||
| 154 | // MARK: - What the widgets show | ||
| 155 | |||
| 156 | /// The snapshot's day that `now` falls on. | ||
| 157 | public func day(at now: Date, calendar: Calendar = .current) -> Day? { | ||
| 158 | days.first { calendar.isDate($0.date, inSameDayAs: now) } | ||
| 159 | } | ||
| 160 | |||
| 161 | /// The day after `now`'s. | ||
| 162 | public func day(after now: Date, calendar: Calendar = .current) -> Day? { | ||
| 163 | guard let next = calendar.date(byAdding: .day, value: 1, to: calendar.startOfDay(for: now)) else { return nil } | ||
| 164 | return day(at: next, calendar: calendar) | ||
| 165 | } | ||
| 166 | |||
| 167 | /// What's left of `now`'s day: its rows not done, without timed rows that have ended | ||
| 168 | /// (or, with no end, started) before `now`, then the overdue entries. | ||
| 169 | public func upcoming(at now: Date, calendar: Calendar = .current) -> [Row] { | ||
| 170 | guard let day = day(at: now, calendar: calendar) else { return [] } | ||
| 171 | return (day.rows + day.overdue).filter { row in | ||
| 172 | guard !row.isDone else { return false } | ||
| 173 | guard let time = row.end ?? row.start else { return true } | ||
| 174 | return time >= now | ||
| 175 | } | ||
| 176 | } | ||
| 177 | |||
| 178 | /// Entries of `now`'s day not done, overdue ones included; calendar events don't count. | ||
| 179 | public func openCount(at now: Date, calendar: Calendar = .current) -> Int { | ||
| 180 | guard let day = day(at: now, calendar: calendar) else { return 0 } | ||
| 181 | return (day.rows + day.overdue).filter(\.isOpen).count | ||
| 182 | } | ||
| 183 | |||
| 184 | public func overdueCount(at now: Date, calendar: Calendar = .current) -> Int { | ||
| 185 | day(at: now, calendar: calendar)?.overdue.filter(\.isOpen).count ?? 0 | ||
| 186 | } | ||
| 187 | |||
| 188 | /// When what `upcoming` shows changes after `now`: a minute after each timed row of the | ||
| 189 | /// day ends (or starts), and the next midnight. | ||
| 190 | public func changes(after now: Date, calendar: Calendar = .current) -> [Date] { | ||
| 191 | var dates = Set<Date>() | ||
| 192 | for row in day(at: now, calendar: calendar).map({ $0.rows + $0.overdue }) ?? [] { | ||
| 193 | if let time = row.end ?? row.start, time.addingTimeInterval(60) > now { dates.insert(time.addingTimeInterval(60)) } | ||
| 194 | } | ||
| 195 | if let midnight = calendar.date(byAdding: .day, value: 1, to: calendar.startOfDay(for: now)) { dates.insert(midnight) } | ||
| 196 | return dates.sorted() | ||
| 197 | } | ||
| 198 | |||
| 199 | // MARK: - The file | ||
| 200 | |||
| 201 | /// `Widgets/agenda.json` in the app group's container; nil without the group. | ||
| 202 | public static func file(group: String = CaptureInbox.group) -> URL? { | ||
| 203 | FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: group)? | ||
| 204 | .appendingPathComponent("Widgets").appendingPathComponent("agenda.json") | ||
| 205 | } | ||
| 206 | |||
| 207 | public static func read(from file: URL) -> AgendaSnapshot? { | ||
| 208 | guard let data = try? Data(contentsOf: file) else { return nil } | ||
| 209 | return try? decoder.decode(AgendaSnapshot.self, from: data) | ||
| 210 | } | ||
| 211 | |||
| 212 | /// Writes the snapshot unless the file holds the same days and colors; true when it wrote. | ||
| 213 | @discardableResult | ||
| 214 | public func write(to file: URL) throws -> Bool { | ||
| 215 | if let old = Self.read(from: file), old.days == days, old.colors == colors { return false } | ||
| 216 | try FileManager.default.createDirectory(at: file.deletingLastPathComponent(), withIntermediateDirectories: true) | ||
| 217 | try Self.encoder.encode(self).write(to: file, options: .atomic) | ||
| 218 | return true | ||
| 219 | } | ||
| 220 | |||
| 221 | static var encoder: JSONEncoder { | ||
| 222 | let encoder = JSONEncoder() | ||
| 223 | encoder.dateEncodingStrategy = .iso8601 | ||
| 224 | encoder.outputFormatting = [.sortedKeys] | ||
| 225 | return encoder | ||
| 226 | } | ||
| 227 | |||
| 228 | static var decoder: JSONDecoder { | ||
| 229 | let decoder = JSONDecoder() | ||
| 230 | decoder.dateDecodingStrategy = .iso8601 | ||
| 231 | return decoder | ||
| 232 | } | ||
| 233 | } | ||
| 234 | |||
| 235 | /// The app's own links, `orgstar://`, which widgets and the Live Activity open. | ||
| 236 | public enum AppLink: Equatable, Sendable { | ||
| 237 | case agenda | ||
| 238 | /// An Org entry: its file and an offset in it. | ||
| 239 | case entry(path: String, offset: Int) | ||
| 240 | /// The entry of the running clock. | ||
| 241 | case clock | ||
| 242 | |||
| 243 | public static let scheme = "orgstar" | ||
| 244 | |||
| 245 | public var url: URL { | ||
| 246 | var components = URLComponents() | ||
| 247 | components.scheme = Self.scheme | ||
| 248 | switch self { | ||
| 249 | case .agenda: | ||
| 250 | components.host = "agenda" | ||
| 251 | case .clock: | ||
| 252 | components.host = "clock" | ||
| 253 | case .entry(let path, let offset): | ||
| 254 | components.host = "entry" | ||
| 255 | components.queryItems = [URLQueryItem(name: "path", value: path), URLQueryItem(name: "offset", value: String(offset))] | ||
| 256 | } | ||
| 257 | return components.url! | ||
| 258 | } | ||
| 259 | |||
| 260 | public init?(url: URL) { | ||
| 261 | guard url.scheme == Self.scheme, let components = URLComponents(url: url, resolvingAgainstBaseURL: false) else { return nil } | ||
| 262 | func query(_ name: String) -> String? { components.queryItems?.first { $0.name == name }?.value } | ||
| 263 | switch components.host { | ||
| 264 | case "agenda": self = .agenda | ||
| 265 | case "clock": self = .clock | ||
| 266 | case "entry": | ||
| 267 | guard let path = query("path"), let offset = query("offset").flatMap(Int.init) else { return nil } | ||
| 268 | self = .entry(path: path, offset: offset) | ||
| 269 | default: return nil | ||
| 270 | } | ||
| 271 | } | ||
| 272 | } | ||
Sources/OrgApp/ClockActivity.swift added +48
| @@ -0,0 +1,48 @@ | |||
| 1 | #if os(iOS) | ||
| 2 | import ActivityKit | ||
| 3 | import AppIntents | ||
| 4 | import Foundation | ||
| 5 | |||
| 6 | /// The running clock's Live Activity, which the app starts and the widget extension draws. | ||
| 7 | public struct ClockActivityAttributes: ActivityAttributes { | ||
| 8 | public struct ContentState: Codable, Hashable, Sendable { | ||
| 9 | public var heading: String | ||
| 10 | public var startedAt: Date | ||
| 11 | |||
| 12 | public init(heading: String, startedAt: Date) { | ||
| 13 | self.heading = heading | ||
| 14 | self.startedAt = startedAt | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | /// The clock's file and the stamp in its `CLOCK: [start]` line, which name the clock. | ||
| 19 | public var path: String | ||
| 20 | public var start: String | ||
| 21 | |||
| 22 | public init(path: String, start: String) { | ||
| 23 | self.path = path | ||
| 24 | self.start = start | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | /// The Live Activity's Clock Out button. It runs in the app's process, which sets `handler`. | ||
| 29 | public struct ClockOutIntent: LiveActivityIntent { | ||
| 30 | public static let title: LocalizedStringResource = "Clock Out" | ||
| 31 | public static let description = IntentDescription("Stops the running clock.") | ||
| 32 | public static let isDiscoverable = false | ||
| 33 | |||
| 34 | /// Clocks out; set by the app at launch. | ||
| 35 | @MainActor public static var handler: (@MainActor @Sendable () async -> Void)? | ||
| 36 | |||
| 37 | public init() {} | ||
| 38 | |||
| 39 | public func perform() async throws -> some IntentResult { | ||
| 40 | let handler = await MainActor.run { Self.handler } | ||
| 41 | await handler?() | ||
| 42 | return .result() | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | /// OrgApp's App Intents, for the app and the widget extension to include. | ||
| 47 | public struct OrgAppIntents: AppIntentsPackage {} | ||
| 48 | #endif | ||
Sources/OrgstarMobile/LiveClock.swift added +47
| @@ -0,0 +1,47 @@ | |||
| 1 | #if os(iOS) | ||
| 2 | import ActivityKit | ||
| 3 | import AppIntents | ||
| 4 | import OrgApp | ||
| 5 | |||
| 6 | /// The running clock's Live Activity: one while a clock runs, started when it starts and | ||
| 7 | /// ended when it stops, however that happens. | ||
| 8 | @MainActor | ||
| 9 | enum LiveClock { | ||
| 10 | nonisolated private static func isLive(_ activity: Activity<ClockActivityAttributes>) -> Bool { | ||
| 11 | activity.activityState == .active || activity.activityState == .stale | ||
| 12 | } | ||
| 13 | |||
| 14 | nonisolated private static func shows(_ activity: Activity<ClockActivityAttributes>, _ running: ClockModel.Running) -> Bool { | ||
| 15 | activity.attributes.path == running.path && activity.attributes.start == running.start | ||
| 16 | } | ||
| 17 | |||
| 18 | /// Ends activities of other clocks; starts one for `running` unless it has one. | ||
| 19 | nonisolated static func sync(_ running: ClockModel.Running?) async { | ||
| 20 | let activities = Activity<ClockActivityAttributes>.activities.filter(isLive) | ||
| 21 | for activity in activities where running.map({ !shows(activity, $0) }) ?? true { | ||
| 22 | await activity.end(nil, dismissalPolicy: .immediate) | ||
| 23 | } | ||
| 24 | guard let running, !activities.contains(where: { shows($0, running) }), ActivityAuthorizationInfo().areActivitiesEnabled else { return } | ||
| 25 | let state = ClockActivityAttributes.ContentState(heading: running.heading, startedAt: running.startedAt) | ||
| 26 | _ = try? Activity.request( | ||
| 27 | attributes: ClockActivityAttributes(path: running.path, start: running.start), content: ActivityContent(state: state, staleDate: nil) | ||
| 28 | ) | ||
| 29 | } | ||
| 30 | |||
| 31 | /// The Clock Out button's work, in the app's process. | ||
| 32 | static func install() { | ||
| 33 | ClockOutIntent.handler = { | ||
| 34 | let model = MobileModel.shared | ||
| 35 | let path = model.clock.running?.path | ||
| 36 | _ = model.clock.clockOut(model.session) | ||
| 37 | if let path, model.session.dirtyPaths.contains(path) { _ = model.session.save(path) } | ||
| 38 | await sync(model.clock.running) | ||
| 39 | } | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | /// The App Intents OrgApp declares. | ||
| 44 | struct OrgstarIntents: AppIntentsPackage { | ||
| 45 | static var includedPackages: [any AppIntentsPackage.Type] { [OrgAppIntents.self] } | ||
| 46 | } | ||
| 47 | #endif | ||
Sources/OrgstarMobile/MobileModel.swift +18
| @@ -7,6 +7,7 @@ import OrgIndex | |||
| 7 | import OrgPresentation | 7 | import OrgPresentation |
| 8 | import OrgWorkspace | 8 | import OrgWorkspace |
| 9 | import UIKit | 9 | import UIKit |
| 10 | import WidgetKit | ||
| 10 | 11 | ||
| 11 | /// The app's models, and the settings from the configuration folder: a folder you choose | 12 | /// The app's models, and the settings from the configuration folder: a folder you choose |
| 12 | /// (a synced copy of the Mac's `~/.config/orgstar`) with `config.toml` and `capture.toml`. | 13 | /// (a synced copy of the Mac's `~/.config/orgstar`) with `config.toml` and `capture.toml`. |
| @@ -209,5 +210,22 @@ final class MobileModel { | |||
| 209 | let reminders = await agenda.reminders(open: session.openTexts, lead: OrgPreferences.reminderLead()) | 210 | let reminders = await agenda.reminders(open: session.openTexts, lead: OrgPreferences.reminderLead()) |
| 210 | await scheduler.reconcile(reminders) | 211 | await scheduler.reconcile(reminders) |
| 211 | } | 212 | } |
| 213 | |||
| 214 | /// The widgets' agenda: today and the next days in the app group's container, with the | ||
| 215 | /// widgets reloaded when it changed. | ||
| 216 | func updateWidgets() async { | ||
| 217 | guard let workspace, let file = AgendaSnapshot.file() else { return } | ||
| 218 | let days = AgendaModel(workspace: workspace) | ||
| 219 | days.mode = .agenda(span: AgendaSnapshot.dayCount, startOffset: 0) | ||
| 220 | if let agenda { | ||
| 221 | days.includeSubfolders = agenda.includeSubfolders | ||
| 222 | days.options = agenda.options | ||
| 223 | days.calendarEvents = agenda.calendarEvents | ||
| 224 | days.calendarNames = agenda.calendarNames | ||
| 225 | } | ||
| 226 | await days.refresh(open: session.openTexts) | ||
| 227 | let snapshot = AgendaSnapshot(groups: days.groups(), today: days.today, theme: theme, generated: Date()) | ||
| 228 | if (try? snapshot.write(to: file)) == true { WidgetCenter.shared.reloadAllTimelines() } | ||
| 229 | } | ||
| 212 | } | 230 | } |
| 213 | #endif | 231 | #endif |
Sources/OrgstarMobile/OrgstarMobileApp.swift +28 −1
| @@ -11,6 +11,10 @@ struct OrgstarMobileApp: App { | |||
| 11 | @UIApplicationDelegateAdaptor private var delegate: AppDelegate | 11 | @UIApplicationDelegateAdaptor private var delegate: AppDelegate |
| 12 | @State private var model = MobileModel.shared | 12 | @State private var model = MobileModel.shared |
| 13 | 13 | ||
| 14 | init() { | ||
| 15 | LiveClock.install() | ||
| 16 | } | ||
| 17 | |||
| 14 | var body: some Scene { | 18 | var body: some Scene { |
| 15 | WindowGroup { | 19 | WindowGroup { |
| 16 | if let workspace = model.workspace, let agenda = model.agenda { | 20 | if let workspace = model.workspace, let agenda = model.agenda { |
| @@ -197,6 +201,7 @@ struct RootView: View { | |||
| 197 | try? await Task.sleep(for: .seconds(1)) | 201 | try? await Task.sleep(for: .seconds(1)) |
| 198 | guard !Task.isCancelled else { return } | 202 | guard !Task.isCancelled else { return } |
| 199 | await model.updateReminders() | 203 | await model.updateReminders() |
| 204 | await model.updateWidgets() | ||
| 200 | } | 205 | } |
| 201 | // Spotlight follows the files and saved edits. | 206 | // Spotlight follows the files and saved edits. |
| 202 | .task(id: SpotlightKey(files: workspace.files.count, changed: workspace.changedFile?.version, saved: session.dirtyPaths.count)) { | 207 | .task(id: SpotlightKey(files: workspace.files.count, changed: workspace.changedFile?.version, saved: session.dirtyPaths.count)) { |
| @@ -217,7 +222,16 @@ struct RootView: View { | |||
| 217 | Task { await workspace.refresh() } | 222 | Task { await workspace.refresh() } |
| 218 | } | 223 | } |
| 219 | .onOpenURL { url in | 224 | .onOpenURL { url in |
| 220 | if let request = CaptureRequest(link: url.absoluteString) { capture = request } | 225 | if let link = AppLink(url: url) { |
| 226 | open(link) | ||
| 227 | } else if let request = CaptureRequest(link: url.absoluteString) { | ||
| 228 | capture = request | ||
| 229 | } | ||
| 230 | } | ||
| 231 | // The Live Activity follows the clock, wherever it starts or stops. | ||
| 232 | .task { await LiveClock.sync(model.clock.running) } | ||
| 233 | .onChange(of: model.clock.running) { | ||
| 234 | Task { await LiveClock.sync(model.clock.running) } | ||
| 221 | } | 235 | } |
| 222 | } | 236 | } |
| 223 | 237 | ||
| @@ -231,6 +245,19 @@ struct RootView: View { | |||
| 231 | if !waiting.isEmpty { capture = waiting.removeFirst() } | 245 | if !waiting.isEmpty { capture = waiting.removeFirst() } |
| 232 | } | 246 | } |
| 233 | 247 | ||
| 248 | /// A widget's or the Live Activity's link. | ||
| 249 | private func open(_ link: AppLink) { | ||
| 250 | switch link { | ||
| 251 | case .agenda: | ||
| 252 | tab = .agenda | ||
| 253 | agendaPath = NavigationPath() | ||
| 254 | case .entry(let path, let offset): | ||
| 255 | model.openRequest = .offset(path, offset) | ||
| 256 | case .clock: | ||
| 257 | clock("app.clock.goto") | ||
| 258 | } | ||
| 259 | } | ||
| 260 | |||
| 234 | private func clock(_ id: String) { | 261 | private func clock(_ id: String) { |
| 235 | if id == "app.clock.report" { | 262 | if id == "app.clock.report" { |
| 236 | showingClockReport = true | 263 | showingClockReport = true |
Sources/OrgstarWidgets/AgendaTimeline.swift added +96
| @@ -0,0 +1,96 @@ | |||
| 1 | import OrgApp | ||
| 2 | import SwiftUI | ||
| 3 | import WidgetKit | ||
| 4 | |||
| 5 | struct AgendaEntry: TimelineEntry { | ||
| 6 | let date: Date | ||
| 7 | /// Nil until the app has written one. | ||
| 8 | let snapshot: AgendaSnapshot? | ||
| 9 | } | ||
| 10 | |||
| 11 | /// The app's agenda snapshot, with an entry for each time what's left of the day changes. | ||
| 12 | struct AgendaProvider: TimelineProvider { | ||
| 13 | func placeholder(in context: Context) -> AgendaEntry { | ||
| 14 | AgendaEntry(date: .now, snapshot: .sample(.now)) | ||
| 15 | } | ||
| 16 | |||
| 17 | func getSnapshot(in context: Context, completion: @escaping (AgendaEntry) -> Void) { | ||
| 18 | let snapshot = Self.load() | ||
| 19 | completion(AgendaEntry(date: .now, snapshot: snapshot ?? (context.isPreview ? .sample(.now) : nil))) | ||
| 20 | } | ||
| 21 | |||
| 22 | func getTimeline(in context: Context, completion: @escaping (Timeline<AgendaEntry>) -> Void) { | ||
| 23 | completion(Self.timeline(Self.load(), now: .now)) | ||
| 24 | } | ||
| 25 | |||
| 26 | static func load() -> AgendaSnapshot? { | ||
| 27 | AgendaSnapshot.file().flatMap(AgendaSnapshot.read) | ||
| 28 | } | ||
| 29 | |||
| 30 | static func timeline(_ snapshot: AgendaSnapshot?, now: Date, calendar: Calendar = .current) -> Timeline<AgendaEntry> { | ||
| 31 | let changes = snapshot?.changes(after: now, calendar: calendar) | ||
| 32 | ?? [calendar.date(byAdding: .day, value: 1, to: calendar.startOfDay(for: now))!] | ||
| 33 | let entries = ([now] + changes).map { AgendaEntry(date: $0, snapshot: snapshot) } | ||
| 34 | return Timeline(entries: entries, policy: .atEnd) | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | extension AgendaSnapshot.Hex { | ||
| 39 | func color(_ scheme: ColorScheme) -> Color { | ||
| 40 | Self.parse(scheme == .dark ? dark : light) ?? .primary | ||
| 41 | } | ||
| 42 | |||
| 43 | /// `#rrggbb` or `#rrggbbaa`. | ||
| 44 | static func parse(_ hex: String) -> Color? { | ||
| 45 | let digits = hex.dropFirst() | ||
| 46 | guard hex.first == "#", digits.count == 6 || digits.count == 8, let value = UInt64(digits, radix: 16) else { return nil } | ||
| 47 | let full = digits.count == 6 ? value << 8 | 0xFF : value | ||
| 48 | func part(_ shift: UInt64) -> Double { Double(full >> shift & 0xFF) / 255 } | ||
| 49 | return Color(.sRGB, red: part(24), green: part(16), blue: part(8), opacity: part(0)) | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | extension AgendaSnapshot { | ||
| 54 | func color(_ key: String, _ scheme: ColorScheme) -> Color? { | ||
| 55 | colors[key]?.color(scheme) | ||
| 56 | } | ||
| 57 | |||
| 58 | /// A day for the gallery and previews. | ||
| 59 | static func sample(_ now: Date, calendar: Calendar = .current) -> AgendaSnapshot { | ||
| 60 | let midnight = calendar.startOfDay(for: now) | ||
| 61 | func at(_ hour: Int, _ minute: Int = 0) -> Date { midnight.addingTimeInterval(Double(hour * 3600 + minute * 60)) } | ||
| 62 | let red = Hex(light: "#d70015", dark: "#ff6961") | ||
| 63 | let orange = Hex(light: "#c93400", dark: "#ff9f0a") | ||
| 64 | let gray = Hex(light: "#6c6c70", dark: "#98989d") | ||
| 65 | let blue = Hex(light: "#0a66d8", dark: "#409cff") | ||
| 66 | func row( | ||
| 67 | _ title: String, _ gutter: String, status: String = "normal", todo: String? = nil, todoColor: Hex? = nil, | ||
| 68 | priority: String? = nil, category: String = "work", start: Date? = nil, end: Date? = nil | ||
| 69 | ) -> Row { | ||
| 70 | Row( | ||
| 71 | id: title, gutter: gutter, status: status, title: title, category: category, todo: todo, priority: priority, isDone: false, | ||
| 72 | isEvent: false, start: start, end: end, path: nil, offset: nil, | ||
| 73 | statusColor: status == "overdue" ? red : status == "due-soon" ? orange : gray, todoColor: todoColor, | ||
| 74 | priorityColor: priority == nil ? nil : red, categoryColor: Hex(light: "#2e6b8f", dark: "#7fb8d9") | ||
| 75 | ) | ||
| 76 | } | ||
| 77 | let today = Day( | ||
| 78 | day: 0, date: midnight, header: "Today", | ||
| 79 | overdue: [row("Send the forms", "3d late", status: "overdue", todo: "TODO", todoColor: red, category: "home")], | ||
| 80 | rows: [ | ||
| 81 | row("Standup", "09:30", start: at(9, 30)), | ||
| 82 | row("Review the draft", "11:00–12:00", todo: "NEXT", todoColor: blue, priority: "A", start: at(11), end: at(12)), | ||
| 83 | row("Dentist", "14:00", category: "home", start: at(14)), | ||
| 84 | row("File expenses", "Due today", status: "due-soon", todo: "TODO", todoColor: red), | ||
| 85 | ] | ||
| 86 | ) | ||
| 87 | let tomorrow = Day( | ||
| 88 | day: 1, date: calendar.date(byAdding: .day, value: 1, to: midnight)!, header: "Tomorrow", overdue: [], | ||
| 89 | rows: [row("Plan the week", "Scheduled", todo: "TODO", todoColor: red)] | ||
| 90 | ) | ||
| 91 | return AgendaSnapshot( | ||
| 92 | generated: now, days: [today, tomorrow], | ||
| 93 | colors: ["agenda-today": Hex(light: "#007aff", dark: "#0a84ff"), "agenda-time": gray, "foreground": Hex(light: "#1f2328", dark: "#e6edf3")] | ||
| 94 | ) | ||
| 95 | } | ||
| 96 | } | ||
Sources/OrgstarWidgets/ClockActivityWidget.swift added +84
| @@ -0,0 +1,84 @@ | |||
| 1 | import ActivityKit | ||
| 2 | import AppIntents | ||
| 3 | import OrgApp | ||
| 4 | import SwiftUI | ||
| 5 | import WidgetKit | ||
| 6 | |||
| 7 | /// The running clock on the Lock Screen and in the Dynamic Island: the heading and the time | ||
| 8 | /// so far, which ticks by itself. | ||
| 9 | struct ClockActivityWidget: Widget { | ||
| 10 | var body: some WidgetConfiguration { | ||
| 11 | ActivityConfiguration(for: ClockActivityAttributes.self) { context in | ||
| 12 | HStack(spacing: 12) { | ||
| 13 | Image(systemName: "stopwatch").font(.title2).foregroundStyle(.orange) | ||
| 14 | VStack(alignment: .leading, spacing: 2) { | ||
| 15 | Text("Clocked in").font(.caption).foregroundStyle(.secondary) | ||
| 16 | Text(context.state.heading).font(.headline).lineLimit(2) | ||
| 17 | } | ||
| 18 | Spacer(minLength: 0) | ||
| 19 | VStack(alignment: .trailing, spacing: 6) { | ||
| 20 | ElapsedText(state: context.state).font(.title3.weight(.semibold)) | ||
| 21 | ClockOutButton() | ||
| 22 | } | ||
| 23 | } | ||
| 24 | .padding() | ||
| 25 | .widgetURL(AppLink.clock.url) | ||
| 26 | } dynamicIsland: { context in | ||
| 27 | DynamicIsland { | ||
| 28 | DynamicIslandExpandedRegion(.leading) { | ||
| 29 | Image(systemName: "stopwatch").font(.title2).foregroundStyle(.orange) | ||
| 30 | } | ||
| 31 | DynamicIslandExpandedRegion(.trailing) { | ||
| 32 | ElapsedText(state: context.state).font(.title3.weight(.semibold)).frame(width: 84, alignment: .trailing) | ||
| 33 | } | ||
| 34 | DynamicIslandExpandedRegion(.center) { | ||
| 35 | Text(context.state.heading).font(.headline).lineLimit(1) | ||
| 36 | } | ||
| 37 | DynamicIslandExpandedRegion(.bottom) { | ||
| 38 | ClockOutButton() | ||
| 39 | } | ||
| 40 | } compactLeading: { | ||
| 41 | Image(systemName: "stopwatch").foregroundStyle(.orange) | ||
| 42 | } compactTrailing: { | ||
| 43 | ElapsedText(state: context.state).frame(maxWidth: 56) | ||
| 44 | } minimal: { | ||
| 45 | Image(systemName: "stopwatch").foregroundStyle(.orange) | ||
| 46 | } | ||
| 47 | .widgetURL(AppLink.clock.url) | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | /// Time since the clock started, `1:05:09`. | ||
| 53 | struct ElapsedText: View { | ||
| 54 | let state: ClockActivityAttributes.ContentState | ||
| 55 | |||
| 56 | var body: some View { | ||
| 57 | Text(timerInterval: state.startedAt...Date.distantFuture, countsDown: false) | ||
| 58 | .monospacedDigit() | ||
| 59 | .lineLimit(1) | ||
| 60 | .minimumScaleFactor(0.7) | ||
| 61 | .multilineTextAlignment(.trailing) | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | struct ClockOutButton: View { | ||
| 66 | var body: some View { | ||
| 67 | Button(intent: ClockOutIntent()) { | ||
| 68 | Label("Clock Out", systemImage: "stop.fill").font(.caption.weight(.semibold)) | ||
| 69 | } | ||
| 70 | .tint(.orange) | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | #Preview("Lock Screen", as: .content, using: ClockActivityAttributes(path: "/notes/work.org", start: "2026-10-09 Fri 09:00")) { | ||
| 75 | ClockActivityWidget() | ||
| 76 | } contentStates: { | ||
| 77 | ClockActivityAttributes.ContentState(heading: "Review the draft", startedAt: .now.addingTimeInterval(-3725)) | ||
| 78 | } | ||
| 79 | |||
| 80 | #Preview("Expanded", as: .dynamicIsland(.expanded), using: ClockActivityAttributes(path: "/notes/work.org", start: "2026-10-09 Fri 09:00")) { | ||
| 81 | ClockActivityWidget() | ||
| 82 | } contentStates: { | ||
| 83 | ClockActivityAttributes.ContentState(heading: "Review the draft", startedAt: .now.addingTimeInterval(-3725)) | ||
| 84 | } | ||
Sources/OrgstarWidgets/OrgstarWidgets.swift added +19
| @@ -0,0 +1,19 @@ | |||
| 1 | import AppIntents | ||
| 2 | import OrgApp | ||
| 3 | import SwiftUI | ||
| 4 | import WidgetKit | ||
| 5 | |||
| 6 | /// The agenda on the Home Screen and the Lock Screen, and the running clock's Live Activity. | ||
| 7 | @main | ||
| 8 | struct OrgstarWidgets: WidgetBundle { | ||
| 9 | var body: some Widget { | ||
| 10 | TodayWidget() | ||
| 11 | UpNextWidget() | ||
| 12 | ClockActivityWidget() | ||
| 13 | } | ||
| 14 | } | ||
| 15 | |||
| 16 | /// The App Intents OrgApp declares: the Live Activity's Clock Out button. | ||
| 17 | struct OrgstarWidgetIntents: AppIntentsPackage { | ||
| 18 | static var includedPackages: [any AppIntentsPackage.Type] { [OrgAppIntents.self] } | ||
| 19 | } | ||
Sources/OrgstarWidgets/TodayWidget.swift added +168
| @@ -0,0 +1,168 @@ | |||
| 1 | import OrgApp | ||
| 2 | import SwiftUI | ||
| 3 | import WidgetKit | ||
| 4 | |||
| 5 | /// Today's agenda on the Home Screen: what's next (small), today's list (medium), today and | ||
| 6 | /// tomorrow (large). | ||
| 7 | struct TodayWidget: Widget { | ||
| 8 | var body: some WidgetConfiguration { | ||
| 9 | StaticConfiguration(kind: "sh.krz.orgstar.today", provider: AgendaProvider()) { entry in | ||
| 10 | TodayView(entry: entry) | ||
| 11 | } | ||
| 12 | .configurationDisplayName("Today") | ||
| 13 | .description("What's left of today's agenda.") | ||
| 14 | .supportedFamilies([.systemSmall, .systemMedium, .systemLarge]) | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | struct TodayView: View { | ||
| 19 | let entry: AgendaEntry | ||
| 20 | @Environment(\.widgetFamily) private var family | ||
| 21 | @Environment(\.colorScheme) private var scheme | ||
| 22 | |||
| 23 | var body: some View { | ||
| 24 | Group { | ||
| 25 | if let snapshot = entry.snapshot { | ||
| 26 | content(snapshot) | ||
| 27 | } else { | ||
| 28 | Text("Open Orgstar to show your agenda here.") | ||
| 29 | .font(.caption) | ||
| 30 | .foregroundStyle(.secondary) | ||
| 31 | .frame(maxWidth: .infinity, maxHeight: .infinity) | ||
| 32 | } | ||
| 33 | } | ||
| 34 | .widgetURL(AppLink.agenda.url) | ||
| 35 | .containerBackground(for: .widget) { | ||
| 36 | entry.snapshot?.color("agenda-background", scheme) ?? Color(uiColor: .systemBackground) | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | @ViewBuilder | ||
| 41 | private func content(_ snapshot: AgendaSnapshot) -> some View { | ||
| 42 | let upcoming = snapshot.upcoming(at: entry.date) | ||
| 43 | VStack(alignment: .leading, spacing: family == .systemSmall ? 4 : 6) { | ||
| 44 | header(snapshot) | ||
| 45 | switch family { | ||
| 46 | case .systemSmall: | ||
| 47 | rows(Array(upcoming.prefix(3)), snapshot, compact: true, empty: "Nothing left today") | ||
| 48 | case .systemLarge: | ||
| 49 | rows(Array(upcoming.prefix(6)), snapshot, compact: false, empty: "Nothing left today") | ||
| 50 | if let tomorrow = snapshot.day(after: entry.date) { | ||
| 51 | let next = (tomorrow.rows + tomorrow.overdue).filter { !$0.isDone } | ||
| 52 | Divider() | ||
| 53 | Text("Tomorrow").font(.caption.weight(.semibold)).foregroundStyle(.secondary) | ||
| 54 | rows(Array(next.prefix(max(2, 9 - min(upcoming.count, 6)))), snapshot, compact: false, empty: "Nothing scheduled") | ||
| 55 | } | ||
| 56 | default: | ||
| 57 | rows(Array(upcoming.prefix(4)), snapshot, compact: false, empty: "Nothing left today") | ||
| 58 | } | ||
| 59 | Spacer(minLength: 0) | ||
| 60 | } | ||
| 61 | .frame(maxWidth: .infinity, alignment: .leading) | ||
| 62 | } | ||
| 63 | |||
| 64 | private func header(_ snapshot: AgendaSnapshot) -> some View { | ||
| 65 | let open = snapshot.openCount(at: entry.date) | ||
| 66 | let overdue = snapshot.overdueCount(at: entry.date) | ||
| 67 | return HStack(alignment: .firstTextBaseline, spacing: 6) { | ||
| 68 | Text(entry.date, format: family == .systemSmall ? .dateTime.weekday(.abbreviated).day() : .dateTime.weekday(.wide).day().month()) | ||
| 69 | .font(.subheadline.weight(.semibold)) | ||
| 70 | .foregroundStyle(snapshot.color("agenda-today", scheme) ?? .accentColor) | ||
| 71 | Spacer(minLength: 0) | ||
| 72 | if overdue > 0, family != .systemSmall { | ||
| 73 | Text("\(overdue) overdue") | ||
| 74 | .font(.caption2.weight(.semibold)) | ||
| 75 | .foregroundStyle(snapshot.day(at: entry.date)?.overdue.first?.statusColor?.color(scheme) ?? .red) | ||
| 76 | } | ||
| 77 | Text(family == .systemSmall ? "\(open)" : "\(open) open") | ||
| 78 | .font(.caption2.weight(.semibold)) | ||
| 79 | .foregroundStyle(.secondary) | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | @ViewBuilder | ||
| 84 | private func rows(_ rows: [AgendaSnapshot.Row], _ snapshot: AgendaSnapshot, compact: Bool, empty: String) -> some View { | ||
| 85 | if rows.isEmpty { | ||
| 86 | Text(empty).font(.caption).foregroundStyle(.secondary) | ||
| 87 | } | ||
| 88 | ForEach(rows) { row in | ||
| 89 | if compact { | ||
| 90 | SmallRow(row: row) | ||
| 91 | } else if let link = row.link { | ||
| 92 | Link(destination: link.url) { WideRow(row: row) } | ||
| 93 | } else { | ||
| 94 | WideRow(row: row) | ||
| 95 | } | ||
| 96 | } | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | /// The gutter over the title. | ||
| 101 | struct SmallRow: View { | ||
| 102 | let row: AgendaSnapshot.Row | ||
| 103 | @Environment(\.colorScheme) private var scheme | ||
| 104 | |||
| 105 | var body: some View { | ||
| 106 | VStack(alignment: .leading, spacing: 0) { | ||
| 107 | Text(row.gutter) | ||
| 108 | .font(.caption2.weight(.medium).monospacedDigit()) | ||
| 109 | .foregroundStyle(row.statusColor?.color(scheme) ?? .secondary) | ||
| 110 | Text(row.title).font(.caption).lineLimit(1) | ||
| 111 | } | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | /// The gutter, keyword and priority badges, the title and the category's dot. | ||
| 116 | struct WideRow: View { | ||
| 117 | let row: AgendaSnapshot.Row | ||
| 118 | @Environment(\.colorScheme) private var scheme | ||
| 119 | |||
| 120 | var body: some View { | ||
| 121 | HStack(spacing: 6) { | ||
| 122 | Text(row.gutter) | ||
| 123 | .font(.caption2.weight(.medium).monospacedDigit()) | ||
| 124 | .foregroundStyle(row.statusColor?.color(scheme) ?? .secondary) | ||
| 125 | .lineLimit(1) | ||
| 126 | .frame(width: 72, alignment: .leading) | ||
| 127 | if let todo = row.todo { | ||
| 128 | let color = row.todoColor?.color(scheme) ?? .secondary | ||
| 129 | Text(todo) | ||
| 130 | .font(.system(size: 9, weight: .bold)) | ||
| 131 | .foregroundStyle(color) | ||
| 132 | .padding(.horizontal, 4) | ||
| 133 | .padding(.vertical, 1) | ||
| 134 | .background(color.opacity(0.14), in: Capsule()) | ||
| 135 | } | ||
| 136 | if let priority = row.priority { | ||
| 137 | let color = row.priorityColor?.color(scheme) ?? .orange | ||
| 138 | Text(priority) | ||
| 139 | .font(.system(size: 9, weight: .bold)) | ||
| 140 | .foregroundStyle(color) | ||
| 141 | .frame(width: 14, height: 14) | ||
| 142 | .overlay(Circle().strokeBorder(color, lineWidth: 1)) | ||
| 143 | } | ||
| 144 | Text(row.title).font(.caption).lineLimit(1) | ||
| 145 | Spacer(minLength: 0) | ||
| 146 | Circle().fill(row.categoryColor?.color(scheme) ?? .secondary).frame(width: 6, height: 6) | ||
| 147 | } | ||
| 148 | } | ||
| 149 | } | ||
| 150 | |||
| 151 | #Preview("Small", as: .systemSmall) { | ||
| 152 | TodayWidget() | ||
| 153 | } timeline: { | ||
| 154 | AgendaEntry(date: .now, snapshot: .sample(.now)) | ||
| 155 | } | ||
| 156 | |||
| 157 | #Preview("Medium", as: .systemMedium) { | ||
| 158 | TodayWidget() | ||
| 159 | } timeline: { | ||
| 160 | AgendaEntry(date: .now, snapshot: .sample(.now)) | ||
| 161 | } | ||
| 162 | |||
| 163 | #Preview("Large", as: .systemLarge) { | ||
| 164 | TodayWidget() | ||
| 165 | } timeline: { | ||
| 166 | AgendaEntry(date: .now, snapshot: .sample(.now)) | ||
| 167 | AgendaEntry(date: .now, snapshot: nil) | ||
| 168 | } | ||
Sources/OrgstarWidgets/UpNextWidget.swift added +83
| @@ -0,0 +1,83 @@ | |||
| 1 | import OrgApp | ||
| 2 | import SwiftUI | ||
| 3 | import WidgetKit | ||
| 4 | |||
| 5 | /// The agenda on the Lock Screen: the next entry (rectangular), the next entry or the count | ||
| 6 | /// (inline), today's open entries (circular). | ||
| 7 | struct UpNextWidget: Widget { | ||
| 8 | var body: some WidgetConfiguration { | ||
| 9 | StaticConfiguration(kind: "sh.krz.orgstar.up-next", provider: AgendaProvider()) { entry in | ||
| 10 | UpNextView(entry: entry) | ||
| 11 | } | ||
| 12 | .configurationDisplayName("Up Next") | ||
| 13 | .description("The next agenda entry, or how many are open today.") | ||
| 14 | .supportedFamilies([.accessoryRectangular, .accessoryInline, .accessoryCircular]) | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | struct UpNextView: View { | ||
| 19 | let entry: AgendaEntry | ||
| 20 | @Environment(\.widgetFamily) private var family | ||
| 21 | |||
| 22 | private var next: AgendaSnapshot.Row? { entry.snapshot?.upcoming(at: entry.date).first } | ||
| 23 | private var open: Int { entry.snapshot?.openCount(at: entry.date) ?? 0 } | ||
| 24 | |||
| 25 | var body: some View { | ||
| 26 | content | ||
| 27 | .widgetURL((next?.link ?? .agenda).url) | ||
| 28 | .containerBackground(for: .widget) { Color.clear } | ||
| 29 | } | ||
| 30 | |||
| 31 | @ViewBuilder | ||
| 32 | private var content: some View { | ||
| 33 | switch family { | ||
| 34 | case .accessoryInline: | ||
| 35 | if let next { | ||
| 36 | Text("\(next.gutter) \(next.title)") | ||
| 37 | } else { | ||
| 38 | Text(open == 0 ? "Agenda clear" : "\(open) open today") | ||
| 39 | } | ||
| 40 | case .accessoryCircular: | ||
| 41 | ZStack { | ||
| 42 | AccessoryWidgetBackground() | ||
| 43 | VStack(spacing: -2) { | ||
| 44 | Text("\(open)").font(.title2.weight(.semibold)).widgetAccentable() | ||
| 45 | Text("open").font(.caption2) | ||
| 46 | } | ||
| 47 | } | ||
| 48 | .accessibilityLabel("\(open) open today") | ||
| 49 | default: | ||
| 50 | if let next { | ||
| 51 | VStack(alignment: .leading, spacing: 0) { | ||
| 52 | Text(next.gutter).font(.headline).widgetAccentable().lineLimit(1) | ||
| 53 | Text(next.title).font(.body).lineLimit(2) | ||
| 54 | } | ||
| 55 | .frame(maxWidth: .infinity, alignment: .leading) | ||
| 56 | } else { | ||
| 57 | VStack(alignment: .leading, spacing: 0) { | ||
| 58 | Text("Agenda").font(.headline).widgetAccentable() | ||
| 59 | Text(entry.snapshot == nil ? "Open Orgstar" : "Nothing left today").font(.body) | ||
| 60 | } | ||
| 61 | .frame(maxWidth: .infinity, alignment: .leading) | ||
| 62 | } | ||
| 63 | } | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | #Preview("Rectangular", as: .accessoryRectangular) { | ||
| 68 | UpNextWidget() | ||
| 69 | } timeline: { | ||
| 70 | AgendaEntry(date: .now, snapshot: .sample(.now)) | ||
| 71 | } | ||
| 72 | |||
| 73 | #Preview("Inline", as: .accessoryInline) { | ||
| 74 | UpNextWidget() | ||
| 75 | } timeline: { | ||
| 76 | AgendaEntry(date: .now, snapshot: .sample(.now)) | ||
| 77 | } | ||
| 78 | |||
| 79 | #Preview("Circular", as: .accessoryCircular) { | ||
| 80 | UpNextWidget() | ||
| 81 | } timeline: { | ||
| 82 | AgendaEntry(date: .now, snapshot: .sample(.now)) | ||
| 83 | } | ||
Tests/OrgAppTests/AgendaSnapshotTests.swift added +122
| @@ -0,0 +1,122 @@ | |||
| 1 | import Foundation | ||
| 2 | import OrgCore | ||
| 3 | import OrgPresentation | ||
| 4 | import Testing | ||
| 5 | @testable import OrgApp | ||
| 6 | |||
| 7 | struct AgendaSnapshotTests { | ||
| 8 | static let file = """ | ||
| 9 | #+CATEGORY: life | ||
| 10 | * TODO [#A] Send forms | ||
| 11 | DEADLINE: <2026-10-02 Fri> | ||
| 12 | * TODO Water plants | ||
| 13 | SCHEDULED: <2026-10-05 Mon> | ||
| 14 | * DONE Took out bins | ||
| 15 | SCHEDULED: <2026-10-05 Mon> | ||
| 16 | * Standup | ||
| 17 | SCHEDULED: <2026-10-05 Mon 08:00> | ||
| 18 | * Dentist <2026-10-05 Mon 13:50-14:30> | ||
| 19 | * NEXT Call the bank | ||
| 20 | SCHEDULED: <2026-10-06 Tue 09:30> | ||
| 21 | * Yesterday's note <2026-10-04 Sun> | ||
| 22 | * Far off <2026-10-20 Tue> | ||
| 23 | """ | ||
| 24 | |||
| 25 | static let today = Days.absolute(year: 2026, month: 10, day: 5) | ||
| 26 | static let utc: Calendar = { | ||
| 27 | var c = Calendar(identifier: .gregorian) | ||
| 28 | c.timeZone = TimeZone(identifier: "UTC")! | ||
| 29 | return c | ||
| 30 | }() | ||
| 31 | |||
| 32 | static func date(_ day: Int, _ hour: Int, _ minute: Int = 0) -> Date { | ||
| 33 | Date(timeIntervalSince1970: Double((day - 719163) * 86400 + hour * 3600 + minute * 60)) | ||
| 34 | } | ||
| 35 | |||
| 36 | /// The agenda from three days before today for three weeks, as the app's view may be. | ||
| 37 | static func snapshot() -> AgendaSnapshot { | ||
| 38 | let source = AgendaSource(path: "/notes/life.org", text: file, defaults: OrgSettings.default.withTodoKeywords("TODO NEXT | DONE")!) | ||
| 39 | let days = Agenda.list([source], start: today - 3, days: 21, today: today, now: (10, 0)) | ||
| 40 | let event = AgendaEvent( | ||
| 41 | id: "e1", title: "Lunch", calendarID: "c", calendarTitle: "Home", color: RGBA(hex: "#336699"), | ||
| 42 | start: date(today, 12), end: date(today, 13), isAllDay: false | ||
| 43 | ) | ||
| 44 | let groups = AgendaRows.groups(days, events: [event], today: today, calendar: utc) | ||
| 45 | return AgendaSnapshot(groups: groups, today: today, theme: .default, generated: date(today, 10), calendar: utc) | ||
| 46 | } | ||
| 47 | |||
| 48 | @Test func holdsTodayAndTheNextDaysOnly() { | ||
| 49 | let snapshot = Self.snapshot() | ||
| 50 | #expect(snapshot.days.map(\.day) == [Self.today, Self.today + 1]) | ||
| 51 | let today = snapshot.days[0] | ||
| 52 | #expect(today.date == Self.date(Self.today, 0)) | ||
| 53 | #expect(today.overdue.map(\.title) == ["Send forms"]) | ||
| 54 | #expect(today.rows.map(\.title) == ["Standup", "Lunch", "Dentist", "Water plants", "Took out bins"]) | ||
| 55 | #expect(snapshot.days[1].rows.map(\.title) == ["Call the bank"]) | ||
| 56 | } | ||
| 57 | |||
| 58 | @Test func rowsCarryTimesLinksAndColors() throws { | ||
| 59 | let snapshot = Self.snapshot() | ||
| 60 | let rows = snapshot.days[0].rows + snapshot.days[0].overdue | ||
| 61 | let dentist = try #require(rows.first { $0.title == "Dentist" }) | ||
| 62 | #expect(dentist.gutter == "13:50–14:30") | ||
| 63 | #expect(dentist.start == Self.date(Self.today, 13, 50)) | ||
| 64 | #expect(dentist.end == Self.date(Self.today, 14, 30)) | ||
| 65 | #expect(dentist.path == "/notes/life.org") | ||
| 66 | #expect(dentist.link == .entry(path: "/notes/life.org", offset: dentist.offset!)) | ||
| 67 | let forms = try #require(rows.first { $0.title == "Send forms" }) | ||
| 68 | #expect(forms.status == "overdue") | ||
| 69 | #expect(forms.todo == "TODO") | ||
| 70 | #expect(forms.priority == "A") | ||
| 71 | #expect(forms.todoColor == .init(light: "#d70015", dark: "#ff6961")) | ||
| 72 | #expect(forms.priorityColor == .init(light: "#d70015", dark: "#ff6961")) | ||
| 73 | #expect(forms.statusColor == .init(light: "#d70015", dark: "#ff6961")) | ||
| 74 | let lunch = try #require(rows.first { $0.title == "Lunch" }) | ||
| 75 | #expect(lunch.isEvent && lunch.link == nil) | ||
| 76 | #expect(lunch.categoryColor == .init(light: "#336699", dark: "#336699")) | ||
| 77 | #expect(snapshot.colors["agenda-today"] == .init(light: "#007aff", dark: "#0a84ff")) | ||
| 78 | #expect(snapshot.colors["agenda-background"] == nil) | ||
| 79 | } | ||
| 80 | |||
| 81 | @Test func encodesAndDecodes() throws { | ||
| 82 | let snapshot = Self.snapshot() | ||
| 83 | let data = try AgendaSnapshot.encoder.encode(snapshot) | ||
| 84 | #expect(try AgendaSnapshot.decoder.decode(AgendaSnapshot.self, from: data) == snapshot) | ||
| 85 | } | ||
| 86 | |||
| 87 | @Test func writesOnlyWhatChanged() throws { | ||
| 88 | let folder = try Folder() | ||
| 89 | let file = folder.url.appendingPathComponent("Widgets/agenda.json") | ||
| 90 | var snapshot = Self.snapshot() | ||
| 91 | #expect(try snapshot.write(to: file)) | ||
| 92 | #expect(AgendaSnapshot.read(from: file) == snapshot) | ||
| 93 | snapshot.generated = snapshot.generated.addingTimeInterval(60) | ||
| 94 | #expect(try !snapshot.write(to: file)) | ||
| 95 | snapshot.days.removeLast() | ||
| 96 | #expect(try snapshot.write(to: file)) | ||
| 97 | #expect(AgendaSnapshot.read(from: file)?.days.count == 1) | ||
| 98 | } | ||
| 99 | |||
| 100 | @Test func whatIsLeftOfToday() { | ||
| 101 | let snapshot = Self.snapshot() | ||
| 102 | let morning = Self.date(Self.today, 7) | ||
| 103 | #expect(snapshot.upcoming(at: morning, calendar: Self.utc).map(\.title) == ["Standup", "Lunch", "Dentist", "Water plants", "Send forms"]) | ||
| 104 | #expect(snapshot.upcoming(at: Self.date(Self.today, 14), calendar: Self.utc).map(\.title) == ["Dentist", "Water plants", "Send forms"]) | ||
| 105 | #expect(snapshot.openCount(at: morning, calendar: Self.utc) == 4) | ||
| 106 | #expect(snapshot.overdueCount(at: morning, calendar: Self.utc) == 1) | ||
| 107 | #expect(snapshot.day(after: morning, calendar: Self.utc)?.day == Self.today + 1) | ||
| 108 | #expect(snapshot.upcoming(at: Self.date(Self.today + 3, 9), calendar: Self.utc) == []) | ||
| 109 | #expect(snapshot.changes(after: Self.date(Self.today, 12, 30), calendar: Self.utc) == [ | ||
| 110 | Self.date(Self.today, 13, 1), Self.date(Self.today, 14, 31), Self.date(Self.today + 1, 0), | ||
| 111 | ]) | ||
| 112 | } | ||
| 113 | |||
| 114 | @Test func linksRoundTrip() { | ||
| 115 | for link in [AppLink.agenda, .clock, .entry(path: "/notes/a b&c+d/ünï.org", offset: 42)] { | ||
| 116 | #expect(AppLink(url: link.url) == link) | ||
| 117 | } | ||
| 118 | #expect(AppLink.agenda.url.absoluteString == "orgstar://agenda") | ||
| 119 | #expect(AppLink(url: URL(string: "org-protocol://capture?body=x")!) == nil) | ||
| 120 | #expect(AppLink(url: URL(string: "orgstar://entry?path=/a.org")!) == nil) | ||
| 121 | } | ||
| 122 | } | ||
ios/Orgstar.xcodeproj/project.pbxproj +134
| @@ -9,6 +9,8 @@ | |||
| 9 | /* Begin PBXBuildFile section */ | 9 | /* Begin PBXBuildFile section */ |
| 10 | 1B78003BBCE8A4B809333342 /* OrgApp in Frameworks */ = {isa = PBXBuildFile; productRef = A2BE626BBE45EA52880B6169 /* OrgApp */; }; | 10 | 1B78003BBCE8A4B809333342 /* OrgApp in Frameworks */ = {isa = PBXBuildFile; productRef = A2BE626BBE45EA52880B6169 /* OrgApp */; }; |
| 11 | 1E5861C0EFE1D96CDC21A22F /* OrgApp in Frameworks */ = {isa = PBXBuildFile; productRef = BA239181876756F7732397EB /* OrgApp */; }; | 11 | 1E5861C0EFE1D96CDC21A22F /* OrgApp in Frameworks */ = {isa = PBXBuildFile; productRef = BA239181876756F7732397EB /* OrgApp */; }; |
| 12 | 2BE799BF03ED43EAA6849F53 /* OrgApp in Frameworks */ = {isa = PBXBuildFile; productRef = EDEF22C5B4F393296F1D17BB /* OrgApp */; }; | ||
| 13 | 76BC65EF4BE629390064AE36 /* OrgstarWidgets.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = B54C32C5D364C02EE21DB092 /* OrgstarWidgets.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; | ||
| 12 | 80E85E72A5B727A15D7123D4 /* OrgstarQuickLook.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 54F0339BC26341A6010C1386 /* OrgstarQuickLook.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; | 14 | 80E85E72A5B727A15D7123D4 /* OrgstarQuickLook.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 54F0339BC26341A6010C1386 /* OrgstarQuickLook.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; |
| 13 | 9BE045FD696469CA8D19F22C /* OrgHighlight in Frameworks */ = {isa = PBXBuildFile; productRef = 47D54A361A74FE9E2B0722BB /* OrgHighlight */; }; | 15 | 9BE045FD696469CA8D19F22C /* OrgHighlight in Frameworks */ = {isa = PBXBuildFile; productRef = 47D54A361A74FE9E2B0722BB /* OrgHighlight */; }; |
| 14 | A05D351FCD8FE36B6A58E035 /* OrgstarShare.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = D128CD70D4E88FAA82D23FD9 /* OrgstarShare.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; | 16 | A05D351FCD8FE36B6A58E035 /* OrgstarShare.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = D128CD70D4E88FAA82D23FD9 /* OrgstarShare.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; |
| @@ -16,6 +18,13 @@ | |||
| 16 | /* End PBXBuildFile section */ | 18 | /* End PBXBuildFile section */ |
| 17 | 19 | ||
| 18 | /* Begin PBXContainerItemProxy section */ | 20 | /* Begin PBXContainerItemProxy section */ |
| 21 | 21312AB4CA947625620BE69C /* PBXContainerItemProxy */ = { | ||
| 22 | isa = PBXContainerItemProxy; | ||
| 23 | containerPortal = 46F86FAA6BBF9AC94A7E4595 /* Project object */; | ||
| 24 | proxyType = 1; | ||
| 25 | remoteGlobalIDString = E87BE20AFDC99FD25E1A163F; | ||
| 26 | remoteInfo = OrgstarWidgets; | ||
| 27 | }; | ||
| 19 | 5932E50A667F73AEF6E5FB26 /* PBXContainerItemProxy */ = { | 28 | 5932E50A667F73AEF6E5FB26 /* PBXContainerItemProxy */ = { |
| 20 | isa = PBXContainerItemProxy; | 29 | isa = PBXContainerItemProxy; |
| 21 | containerPortal = 46F86FAA6BBF9AC94A7E4595 /* Project object */; | 30 | containerPortal = 46F86FAA6BBF9AC94A7E4595 /* Project object */; |
| @@ -41,6 +50,7 @@ | |||
| 41 | files = ( | 50 | files = ( |
| 42 | A05D351FCD8FE36B6A58E035 /* OrgstarShare.appex in Embed Foundation Extensions */, | 51 | A05D351FCD8FE36B6A58E035 /* OrgstarShare.appex in Embed Foundation Extensions */, |
| 43 | 80E85E72A5B727A15D7123D4 /* OrgstarQuickLook.appex in Embed Foundation Extensions */, | 52 | 80E85E72A5B727A15D7123D4 /* OrgstarQuickLook.appex in Embed Foundation Extensions */, |
| 53 | 76BC65EF4BE629390064AE36 /* OrgstarWidgets.appex in Embed Foundation Extensions */, | ||
| 44 | ); | 54 | ); |
| 45 | name = "Embed Foundation Extensions"; | 55 | name = "Embed Foundation Extensions"; |
| 46 | runOnlyForDeploymentPostprocessing = 0; | 56 | runOnlyForDeploymentPostprocessing = 0; |
| @@ -52,6 +62,9 @@ | |||
| 52 | 1025FACEDEC31014F0AFA230 /* OrgstarShare/OrgstarShare.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = OrgstarShare/OrgstarShare.entitlements; sourceTree = "<group>"; }; | 62 | 1025FACEDEC31014F0AFA230 /* OrgstarShare/OrgstarShare.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = OrgstarShare/OrgstarShare.entitlements; sourceTree = "<group>"; }; |
| 53 | 48A21BB1AB1E70D4429DCDE4 /* OrgstarQuickLook/Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = OrgstarQuickLook/Info.plist; sourceTree = "<group>"; }; | 63 | 48A21BB1AB1E70D4429DCDE4 /* OrgstarQuickLook/Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = OrgstarQuickLook/Info.plist; sourceTree = "<group>"; }; |
| 54 | 54F0339BC26341A6010C1386 /* OrgstarQuickLook.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = OrgstarQuickLook.appex; sourceTree = BUILT_PRODUCTS_DIR; }; | 64 | 54F0339BC26341A6010C1386 /* OrgstarQuickLook.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = OrgstarQuickLook.appex; sourceTree = BUILT_PRODUCTS_DIR; }; |
| 65 | 6C2E41672FBF640AB5554A2B /* OrgstarWidgets/Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = OrgstarWidgets/Info.plist; sourceTree = "<group>"; }; | ||
| 66 | B54C32C5D364C02EE21DB092 /* OrgstarWidgets.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = OrgstarWidgets.appex; sourceTree = BUILT_PRODUCTS_DIR; }; | ||
| 67 | C0AFAE84CB7F8B19772BF250 /* OrgstarWidgets/OrgstarWidgets.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = OrgstarWidgets/OrgstarWidgets.entitlements; sourceTree = "<group>"; }; | ||
| 55 | D128CD70D4E88FAA82D23FD9 /* OrgstarShare.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = OrgstarShare.appex; sourceTree = BUILT_PRODUCTS_DIR; }; | 68 | D128CD70D4E88FAA82D23FD9 /* OrgstarShare.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = OrgstarShare.appex; sourceTree = BUILT_PRODUCTS_DIR; }; |
| 56 | D72184D78ACF70837216BCBF /* OrgstarShare/Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = OrgstarShare/Info.plist; sourceTree = "<group>"; }; | 69 | D72184D78ACF70837216BCBF /* OrgstarShare/Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = OrgstarShare/Info.plist; sourceTree = "<group>"; }; |
| 57 | ECD4A6B56983444E4E07CE63 /* Orgstar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Orgstar.app; sourceTree = BUILT_PRODUCTS_DIR; }; | 70 | ECD4A6B56983444E4E07CE63 /* Orgstar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Orgstar.app; sourceTree = BUILT_PRODUCTS_DIR; }; |
| @@ -97,6 +110,11 @@ | |||
| 97 | path = ../Sources/OrgstarMobile; | 110 | path = ../Sources/OrgstarMobile; |
| 98 | sourceTree = "<group>"; | 111 | sourceTree = "<group>"; |
| 99 | }; | 112 | }; |
| 113 | DE99BDA1BB90EEDFA8FF4CC2 /* ../Sources/OrgstarWidgets */ = { | ||
| 114 | isa = PBXFileSystemSynchronizedRootGroup; | ||
| 115 | path = ../Sources/OrgstarWidgets; | ||
| 116 | sourceTree = "<group>"; | ||
| 117 | }; | ||
| 100 | /* End PBXFileSystemSynchronizedRootGroup section */ | 118 | /* End PBXFileSystemSynchronizedRootGroup section */ |
| 101 | 119 | ||
| 102 | /* Begin PBXFrameworksBuildPhase section */ | 120 | /* Begin PBXFrameworksBuildPhase section */ |
| @@ -125,6 +143,14 @@ | |||
| 125 | ); | 143 | ); |
| 126 | runOnlyForDeploymentPostprocessing = 0; | 144 | runOnlyForDeploymentPostprocessing = 0; |
| 127 | }; | 145 | }; |
| 146 | AE22603FB5DE3C5FFFBBC68E /* Frameworks */ = { | ||
| 147 | isa = PBXFrameworksBuildPhase; | ||
| 148 | buildActionMask = 2147483647; | ||
| 149 | files = ( | ||
| 150 | 2BE799BF03ED43EAA6849F53 /* OrgApp in Frameworks */, | ||
| 151 | ); | ||
| 152 | runOnlyForDeploymentPostprocessing = 0; | ||
| 153 | }; | ||
| 128 | /* End PBXFrameworksBuildPhase section */ | 154 | /* End PBXFrameworksBuildPhase section */ |
| 129 | 155 | ||
| 130 | /* Begin PBXGroup section */ | 156 | /* Begin PBXGroup section */ |
| @@ -134,6 +160,7 @@ | |||
| 134 | ECD4A6B56983444E4E07CE63 /* Orgstar.app */, | 160 | ECD4A6B56983444E4E07CE63 /* Orgstar.app */, |
| 135 | D128CD70D4E88FAA82D23FD9 /* OrgstarShare.appex */, | 161 | D128CD70D4E88FAA82D23FD9 /* OrgstarShare.appex */, |
| 136 | 54F0339BC26341A6010C1386 /* OrgstarQuickLook.appex */, | 162 | 54F0339BC26341A6010C1386 /* OrgstarQuickLook.appex */, |
| 163 | B54C32C5D364C02EE21DB092 /* OrgstarWidgets.appex */, | ||
| 137 | ); | 164 | ); |
| 138 | name = Products; | 165 | name = Products; |
| 139 | sourceTree = "<group>"; | 166 | sourceTree = "<group>"; |
| @@ -144,6 +171,7 @@ | |||
| 144 | 6425CB8F177EDFF8EE2BD447 /* ../Sources/OrgstarShare */, | 171 | 6425CB8F177EDFF8EE2BD447 /* ../Sources/OrgstarShare */, |
| 145 | 2412EC8ED6427B76498FCD18 /* ../Sources/OrgstarQuickLook */, | 172 | 2412EC8ED6427B76498FCD18 /* ../Sources/OrgstarQuickLook */, |
| 146 | 7E85FA5E5BA11D0F6891693E /* ../Sources/OrgstarMobile */, | 173 | 7E85FA5E5BA11D0F6891693E /* ../Sources/OrgstarMobile */, |
| 174 | DE99BDA1BB90EEDFA8FF4CC2 /* ../Sources/OrgstarWidgets */, | ||
| 147 | 40FCC6CF7BFC065FCDD48D4E /* Support */, | 175 | 40FCC6CF7BFC065FCDD48D4E /* Support */, |
| 148 | 0A2C978E52A76F0AA9F68BB5 /* Products */, | 176 | 0A2C978E52A76F0AA9F68BB5 /* Products */, |
| 149 | ); | 177 | ); |
| @@ -157,6 +185,8 @@ | |||
| 157 | D72184D78ACF70837216BCBF /* OrgstarShare/Info.plist */, | 185 | D72184D78ACF70837216BCBF /* OrgstarShare/Info.plist */, |
| 158 | 1025FACEDEC31014F0AFA230 /* OrgstarShare/OrgstarShare.entitlements */, | 186 | 1025FACEDEC31014F0AFA230 /* OrgstarShare/OrgstarShare.entitlements */, |
| 159 | 48A21BB1AB1E70D4429DCDE4 /* OrgstarQuickLook/Info.plist */, | 187 | 48A21BB1AB1E70D4429DCDE4 /* OrgstarQuickLook/Info.plist */, |
| 188 | 6C2E41672FBF640AB5554A2B /* OrgstarWidgets/Info.plist */, | ||
| 189 | C0AFAE84CB7F8B19772BF250 /* OrgstarWidgets/OrgstarWidgets.entitlements */, | ||
| 160 | ); | 190 | ); |
| 161 | name = Support; | 191 | name = Support; |
| 162 | sourceTree = "<group>"; | 192 | sourceTree = "<group>"; |
| @@ -178,6 +208,7 @@ | |||
| 178 | dependencies = ( | 208 | dependencies = ( |
| 179 | 7F4807D68646366ED2DCA5C2 /* PBXTargetDependency */, | 209 | 7F4807D68646366ED2DCA5C2 /* PBXTargetDependency */, |
| 180 | B35F6E044645C7D88B689DC1 /* PBXTargetDependency */, | 210 | B35F6E044645C7D88B689DC1 /* PBXTargetDependency */, |
| 211 | D82DF00DA5607ABDDF199065 /* PBXTargetDependency */, | ||
| 181 | ); | 212 | ); |
| 182 | fileSystemSynchronizedGroups = ( | 213 | fileSystemSynchronizedGroups = ( |
| 183 | 7E85FA5E5BA11D0F6891693E /* ../Sources/OrgstarMobile */, | 214 | 7E85FA5E5BA11D0F6891693E /* ../Sources/OrgstarMobile */, |
| @@ -237,6 +268,29 @@ | |||
| 237 | productReference = 54F0339BC26341A6010C1386 /* OrgstarQuickLook.appex */; | 268 | productReference = 54F0339BC26341A6010C1386 /* OrgstarQuickLook.appex */; |
| 238 | productType = "com.apple.product-type.app-extension"; | 269 | productType = "com.apple.product-type.app-extension"; |
| 239 | }; | 270 | }; |
| 271 | E87BE20AFDC99FD25E1A163F /* OrgstarWidgets */ = { | ||
| 272 | isa = PBXNativeTarget; | ||
| 273 | buildConfigurationList = 14080276016DB67528B057D6 /* Build configuration list for PBXNativeTarget "OrgstarWidgets" */; | ||
| 274 | buildPhases = ( | ||
| 275 | 296E85448BDDDD3245D3D432 /* Sources */, | ||
| 276 | AE22603FB5DE3C5FFFBBC68E /* Frameworks */, | ||
| 277 | EA6C64E8D42ADCFBC3B131FF /* Resources */, | ||
| 278 | ); | ||
| 279 | buildRules = ( | ||
| 280 | ); | ||
| 281 | dependencies = ( | ||
| 282 | ); | ||
| 283 | fileSystemSynchronizedGroups = ( | ||
| 284 | DE99BDA1BB90EEDFA8FF4CC2 /* ../Sources/OrgstarWidgets */, | ||
| 285 | ); | ||
| 286 | name = OrgstarWidgets; | ||
| 287 | packageProductDependencies = ( | ||
| 288 | EDEF22C5B4F393296F1D17BB /* OrgApp */, | ||
| 289 | ); | ||
| 290 | productName = OrgstarWidgets; | ||
| 291 | productReference = B54C32C5D364C02EE21DB092 /* OrgstarWidgets.appex */; | ||
| 292 | productType = "com.apple.product-type.app-extension"; | ||
| 293 | }; | ||
| 240 | /* End PBXNativeTarget section */ | 294 | /* End PBXNativeTarget section */ |
| 241 | 295 | ||
| 242 | /* Begin PBXProject section */ | 296 | /* Begin PBXProject section */ |
| @@ -267,6 +321,7 @@ | |||
| 267 | 4E815AD2268DF19F304A2880 /* Orgstar iOS */, | 321 | 4E815AD2268DF19F304A2880 /* Orgstar iOS */, |
| 268 | 92364A1473ECC9B162FEAE51 /* OrgstarShare */, | 322 | 92364A1473ECC9B162FEAE51 /* OrgstarShare */, |
| 269 | BBA37636EB6BBA564493899D /* OrgstarQuickLook */, | 323 | BBA37636EB6BBA564493899D /* OrgstarQuickLook */, |
| 324 | E87BE20AFDC99FD25E1A163F /* OrgstarWidgets */, | ||
| 270 | ); | 325 | ); |
| 271 | }; | 326 | }; |
| 272 | /* End PBXProject section */ | 327 | /* End PBXProject section */ |
| @@ -293,9 +348,23 @@ | |||
| 293 | ); | 348 | ); |
| 294 | runOnlyForDeploymentPostprocessing = 0; | 349 | runOnlyForDeploymentPostprocessing = 0; |
| 295 | }; | 350 | }; |
| 351 | EA6C64E8D42ADCFBC3B131FF /* Resources */ = { | ||
| 352 | isa = PBXResourcesBuildPhase; | ||
| 353 | buildActionMask = 2147483647; | ||
| 354 | files = ( | ||
| 355 | ); | ||
| 356 | runOnlyForDeploymentPostprocessing = 0; | ||
| 357 | }; | ||
| 296 | /* End PBXResourcesBuildPhase section */ | 358 | /* End PBXResourcesBuildPhase section */ |
| 297 | 359 | ||
| 298 | /* Begin PBXSourcesBuildPhase section */ | 360 | /* Begin PBXSourcesBuildPhase section */ |
| 361 | 296E85448BDDDD3245D3D432 /* Sources */ = { | ||
| 362 | isa = PBXSourcesBuildPhase; | ||
| 363 | buildActionMask = 2147483647; | ||
| 364 | files = ( | ||
| 365 | ); | ||
| 366 | runOnlyForDeploymentPostprocessing = 0; | ||
| 367 | }; | ||
| 299 | 347F295A9254F751A96C2737 /* Sources */ = { | 368 | 347F295A9254F751A96C2737 /* Sources */ = { |
| 300 | isa = PBXSourcesBuildPhase; | 369 | isa = PBXSourcesBuildPhase; |
| 301 | buildActionMask = 2147483647; | 370 | buildActionMask = 2147483647; |
| @@ -330,6 +399,11 @@ | |||
| 330 | target = BBA37636EB6BBA564493899D /* OrgstarQuickLook */; | 399 | target = BBA37636EB6BBA564493899D /* OrgstarQuickLook */; |
| 331 | targetProxy = D0655711FB3B470A356B2D36 /* PBXContainerItemProxy */; | 400 | targetProxy = D0655711FB3B470A356B2D36 /* PBXContainerItemProxy */; |
| 332 | }; | 401 | }; |
| 402 | D82DF00DA5607ABDDF199065 /* PBXTargetDependency */ = { | ||
| 403 | isa = PBXTargetDependency; | ||
| 404 | target = E87BE20AFDC99FD25E1A163F /* OrgstarWidgets */; | ||
| 405 | targetProxy = 21312AB4CA947625620BE69C /* PBXContainerItemProxy */; | ||
| 406 | }; | ||
| 333 | /* End PBXTargetDependency section */ | 407 | /* End PBXTargetDependency section */ |
| 334 | 408 | ||
| 335 | /* Begin XCBuildConfiguration section */ | 409 | /* Begin XCBuildConfiguration section */ |
| @@ -419,6 +493,29 @@ | |||
| 419 | }; | 493 | }; |
| 420 | name = Release; | 494 | name = Release; |
| 421 | }; | 495 | }; |
| 496 | 7BCEB4BC70BB3B62775CDCFB /* Debug */ = { | ||
| 497 | isa = XCBuildConfiguration; | ||
| 498 | buildSettings = { | ||
| 499 | CODE_SIGN_ENTITLEMENTS = OrgstarWidgets/OrgstarWidgets.entitlements; | ||
| 500 | CODE_SIGN_STYLE = Automatic; | ||
| 501 | CURRENT_PROJECT_VERSION = 1; | ||
| 502 | DEVELOPMENT_TEAM = ZCNAX3VL9D; | ||
| 503 | GENERATE_INFOPLIST_FILE = NO; | ||
| 504 | INFOPLIST_FILE = OrgstarWidgets/Info.plist; | ||
| 505 | IPHONEOS_DEPLOYMENT_TARGET = 26.0; | ||
| 506 | LD_RUNPATH_SEARCH_PATHS = ( | ||
| 507 | "$(inherited)", | ||
| 508 | "@executable_path/Frameworks", | ||
| 509 | "@executable_path/../../Frameworks", | ||
| 510 | ); | ||
| 511 | MARKETING_VERSION = 0.1.0; | ||
| 512 | PRODUCT_BUNDLE_IDENTIFIER = sh.krz.orgstar.widgets; | ||
| 513 | PRODUCT_NAME = "$(TARGET_NAME)"; | ||
| 514 | SKIP_INSTALL = YES; | ||
| 515 | TARGETED_DEVICE_FAMILY = "1,2"; | ||
| 516 | }; | ||
| 517 | name = Debug; | ||
| 518 | }; | ||
| 422 | 942C95A5D90B164020736D83 /* Debug */ = { | 519 | 942C95A5D90B164020736D83 /* Debug */ = { |
| 423 | isa = XCBuildConfiguration; | 520 | isa = XCBuildConfiguration; |
| 424 | buildSettings = { | 521 | buildSettings = { |
| @@ -478,6 +575,29 @@ | |||
| 478 | }; | 575 | }; |
| 479 | name = Debug; | 576 | name = Debug; |
| 480 | }; | 577 | }; |
| 578 | E2365A4C43B017487EC51861 /* Release */ = { | ||
| 579 | isa = XCBuildConfiguration; | ||
| 580 | buildSettings = { | ||
| 581 | CODE_SIGN_ENTITLEMENTS = OrgstarWidgets/OrgstarWidgets.entitlements; | ||
| 582 | CODE_SIGN_STYLE = Automatic; | ||
| 583 | CURRENT_PROJECT_VERSION = 1; | ||
| 584 | DEVELOPMENT_TEAM = ZCNAX3VL9D; | ||
| 585 | GENERATE_INFOPLIST_FILE = NO; | ||
| 586 | INFOPLIST_FILE = OrgstarWidgets/Info.plist; | ||
| 587 | IPHONEOS_DEPLOYMENT_TARGET = 26.0; | ||
| 588 | LD_RUNPATH_SEARCH_PATHS = ( | ||
| 589 | "$(inherited)", | ||
| 590 | "@executable_path/Frameworks", | ||
| 591 | "@executable_path/../../Frameworks", | ||
| 592 | ); | ||
| 593 | MARKETING_VERSION = 0.1.0; | ||
| 594 | PRODUCT_BUNDLE_IDENTIFIER = sh.krz.orgstar.widgets; | ||
| 595 | PRODUCT_NAME = "$(TARGET_NAME)"; | ||
| 596 | SKIP_INSTALL = YES; | ||
| 597 | TARGETED_DEVICE_FAMILY = "1,2"; | ||
| 598 | }; | ||
| 599 | name = Release; | ||
| 600 | }; | ||
| 481 | F25EF7827B5210B4D9103995 /* Debug */ = { | 601 | F25EF7827B5210B4D9103995 /* Debug */ = { |
| 482 | isa = XCBuildConfiguration; | 602 | isa = XCBuildConfiguration; |
| 483 | buildSettings = { | 603 | buildSettings = { |
| @@ -501,6 +621,15 @@ | |||
| 501 | /* End XCBuildConfiguration section */ | 621 | /* End XCBuildConfiguration section */ |
| 502 | 622 | ||
| 503 | /* Begin XCConfigurationList section */ | 623 | /* Begin XCConfigurationList section */ |
| 624 | 14080276016DB67528B057D6 /* Build configuration list for PBXNativeTarget "OrgstarWidgets" */ = { | ||
| 625 | isa = XCConfigurationList; | ||
| 626 | buildConfigurations = ( | ||
| 627 | 7BCEB4BC70BB3B62775CDCFB /* Debug */, | ||
| 628 | E2365A4C43B017487EC51861 /* Release */, | ||
| 629 | ); | ||
| 630 | defaultConfigurationIsVisible = 0; | ||
| 631 | defaultConfigurationName = Release; | ||
| 632 | }; | ||
| 504 | 30435AE6E633F256CC883684 /* Build configuration list for PBXProject "Orgstar" */ = { | 633 | 30435AE6E633F256CC883684 /* Build configuration list for PBXProject "Orgstar" */ = { |
| 505 | isa = XCConfigurationList; | 634 | isa = XCConfigurationList; |
| 506 | buildConfigurations = ( | 635 | buildConfigurations = ( |
| @@ -567,6 +696,11 @@ | |||
| 567 | package = A46A1BCE0B67C45BEC8F435B /* XCLocalSwiftPackageReference ".." */; | 696 | package = A46A1BCE0B67C45BEC8F435B /* XCLocalSwiftPackageReference ".." */; |
| 568 | productName = OrgApp; | 697 | productName = OrgApp; |
| 569 | }; | 698 | }; |
| 699 | EDEF22C5B4F393296F1D17BB /* OrgApp */ = { | ||
| 700 | isa = XCSwiftPackageProductDependency; | ||
| 701 | package = A46A1BCE0B67C45BEC8F435B /* XCLocalSwiftPackageReference ".." */; | ||
| 702 | productName = OrgApp; | ||
| 703 | }; | ||
| 570 | /* End XCSwiftPackageProductDependency section */ | 704 | /* End XCSwiftPackageProductDependency section */ |
| 571 | }; | 705 | }; |
| 572 | rootObject = 46F86FAA6BBF9AC94A7E4595 /* Project object */; | 706 | rootObject = 46F86FAA6BBF9AC94A7E4595 /* Project object */; |
ios/Orgstar/Info.plist +10
| @@ -24,11 +24,21 @@ | |||
| 24 | <string>org-protocol</string> | 24 | <string>org-protocol</string> |
| 25 | </array> | 25 | </array> |
| 26 | </dict> | 26 | </dict> |
| 27 | <dict> | ||
| 28 | <key>CFBundleURLName</key> | ||
| 29 | <string>sh.krz.orgstar</string> | ||
| 30 | <key>CFBundleURLSchemes</key> | ||
| 31 | <array> | ||
| 32 | <string>orgstar</string> | ||
| 33 | </array> | ||
| 34 | </dict> | ||
| 27 | </array> | 35 | </array> |
| 28 | <key>CFBundleVersion</key> | 36 | <key>CFBundleVersion</key> |
| 29 | <string>$(CURRENT_PROJECT_VERSION)</string> | 37 | <string>$(CURRENT_PROJECT_VERSION)</string> |
| 30 | <key>NSCalendarsFullAccessUsageDescription</key> | 38 | <key>NSCalendarsFullAccessUsageDescription</key> |
| 31 | <string>The agenda shows your calendar events alongside your Org entries. Orgstar only reads them.</string> | 39 | <string>The agenda shows your calendar events alongside your Org entries. Orgstar only reads them.</string> |
| 40 | <key>NSSupportsLiveActivities</key> | ||
| 41 | <true/> | ||
| 32 | <key>UIApplicationSceneManifest</key> | 42 | <key>UIApplicationSceneManifest</key> |
| 33 | <dict> | 43 | <dict> |
| 34 | <key>UIApplicationSupportsMultipleScenes</key> | 44 | <key>UIApplicationSupportsMultipleScenes</key> |
ios/OrgstarWidgets/Info.plist added +25
| @@ -0,0 +1,25 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| 3 | <plist version="1.0"> | ||
| 4 | <dict> | ||
| 5 | <key>CFBundleIdentifier</key> | ||
| 6 | <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
| 7 | <key>CFBundleName</key> | ||
| 8 | <string>$(PRODUCT_NAME)</string> | ||
| 9 | <key>CFBundleDisplayName</key> | ||
| 10 | <string>Orgstar</string> | ||
| 11 | <key>CFBundleExecutable</key> | ||
| 12 | <string>$(EXECUTABLE_NAME)</string> | ||
| 13 | <key>CFBundlePackageType</key> | ||
| 14 | <string>XPC!</string> | ||
| 15 | <key>CFBundleShortVersionString</key> | ||
| 16 | <string>$(MARKETING_VERSION)</string> | ||
| 17 | <key>CFBundleVersion</key> | ||
| 18 | <string>$(CURRENT_PROJECT_VERSION)</string> | ||
| 19 | <key>NSExtension</key> | ||
| 20 | <dict> | ||
| 21 | <key>NSExtensionPointIdentifier</key> | ||
| 22 | <string>com.apple.widgetkit-extension</string> | ||
| 23 | </dict> | ||
| 24 | </dict> | ||
| 25 | </plist> | ||
ios/OrgstarWidgets/OrgstarWidgets.entitlements added +8
| @@ -0,0 +1,8 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| 3 | <plist version="1.0"> | ||
| 4 | <dict> | ||
| 5 | <key>com.apple.security.application-groups</key> | ||
| 6 | <array><string>group.sh.krz.orgstar</string></array> | ||
| 7 | </dict> | ||
| 8 | </plist> | ||