Commit 08c0099083
Copy SHA
08c0099083bdaefdf673453b8c2875fedcb094aa
parent: c17e16cfba
Verified · cmc
cmc <hello@cleberg.net> · 2026-10-09 05:46 UTC
iOS: agenda snapshot for widgets, orgstar:// links, clock Live Activity
The app writes the next seven days to the app group when the agenda's
inputs change and reloads widget timelines. orgstar://agenda, entry and
clock links open the agenda, an entry, or the clocked entry. A Live
Activity follows the running clock; its Clock Out intent runs the app's
clock-out.
Changed files (6)
Sources/OrgApp/AgendaSnapshot.swift
+32 · view
@@ -47,6 +47,30 @@ public struct AgendaSnapshot: Codable, Equatable, Sendable {
47 47 public var priorityColor : Hex ?
48 48 public var categoryColor : Hex ?
49 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
50 74 public var link : AppLink ? {
51 75 guard let path , let offset else { return nil }
52 76 return . entry ( path : path , offset : offset )
@@ -67,6 +91,14 @@ public struct AgendaSnapshot: Codable, Equatable, Sendable {
67 91 public var rows : [ Row ]
68 92
69 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 }
70 102 }
71 103
72 104 public var generated : Date
Sources/OrgApp/ClockActivity.swift
added
+48 · view
@@ -0,0 +1,48 @@
1 #if os ( iOS )
2 import ActivityKit
3 import AppIntents
4 import Foundation
5
6 // / T h e r u n n i n g c l o c k ' s L i v e A c t i v i t y , w h i c h t h e a p p s t a r t s a n d t h e w i d g e t e x t e n s i o n d r a w s .
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 // / T h e c l o c k ' s f i l e a n d t h e s t a m p i n i t s ` C L O C K : [ s t a r t ] ` l i n e , w h i c h n a m e t h e c l o c k .
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 // / T h e L i v e A c t i v i t y ' s C l o c k O u t b u t t o n . I t r u n s i n t h e a p p ' s p r o c e s s , w h i c h s e t s ` h a n d l e r ` .
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 // / C l o c k s o u t ; s e t b y t h e a p p a t l a u n c h .
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 // / O r g A p p ' s A p p I n t e n t s , f o r t h e a p p a n d t h e w i d g e t e x t e n s i o n t o i n c l u d e .
47 public struct OrgAppIntents : AppIntentsPackage { }
48 #endif
Sources/OrgstarMobile/LiveClock.swift
added
+47 · view
@@ -0,0 +1,47 @@
1 #if os ( iOS )
2 import ActivityKit
3 import AppIntents
4 import OrgApp
5
6 // / T h e r u n n i n g c l o c k ' s L i v e A c t i v i t y : o n e w h i l e a c l o c k r u n s , s t a r t e d w h e n i t s t a r t s a n d
7 // / e n d e d w h e n i t s t o p s , h o w e v e r t h a t h a p p e n s .
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 // / E n d s a c t i v i t i e s o f o t h e r c l o c k s ; s t a r t s o n e f o r ` r u n n i n g ` u n l e s s i t h a s o n e .
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 // / T h e C l o c k O u t b u t t o n ' s w o r k , i n t h e a p p ' s p r o c e s s .
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 // / T h e A p p I n t e n t s O r g A p p d e c l a r e s .
44 struct OrgstarIntents : AppIntentsPackage {
45 static var includedPackages : [ any AppIntentsPackage . Type ] { [ OrgAppIntents . self ] }
46 }
47 #endif
Sources/OrgstarMobile/MobileModel.swift
+18 · view
@@ -7,6 +7,7 @@ import OrgIndex
7 7 import OrgPresentation
8 8 import OrgWorkspace
9 9 import UIKit
10 import WidgetKit
10 11
11 12 // / T h e a p p ' s m o d e l s , a n d t h e s e t t i n g s f r o m t h e c o n f i g u r a t i o n f o l d e r : a f o l d e r y o u c h o o s e
12 13 // / ( a s y n c e d c o p y o f t h e M a c ' s ` ~ / . c o n f i g / o r g s t a r ` ) w i t h ` c o n f i g . t o m l ` a n d ` c a p t u r e . t o m l ` .
@@ -209,5 +210,22 @@ final class MobileModel {
209 210 let reminders = await agenda . reminders ( open : session . openTexts , lead : OrgPreferences . reminderLead ( ) )
210 211 await scheduler . reconcile ( reminders )
211 212 }
213
214 // / T h e w i d g e t s ' a g e n d a : t o d a y a n d t h e n e x t d a y s i n t h e a p p g r o u p ' s c o n t a i n e r , w i t h t h e
215 // / w i d g e t s r e l o a d e d w h e n i t c h a n g e d .
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 231 #endif
Sources/OrgstarMobile/OrgstarMobileApp.swift
+28 −1 · view
@@ -11,6 +11,10 @@ struct OrgstarMobileApp: App {
11 11 @ UIApplicationDelegateAdaptor private var delegate : AppDelegate
12 12 @ State private var model = MobileModel . shared
13 13
14 init ( ) {
15 LiveClock . install ( )
16 }
17
14 18 var body : some Scene {
15 19 WindowGroup {
16 20 if let workspace = model . workspace , let agenda = model . agenda {
@@ -197,6 +201,7 @@ struct RootView: View {
197 201 try ? await Task . sleep ( for : . seconds ( 1 ) )
198 202 guard ! Task . isCancelled else { return }
199 203 await model . updateReminders ( )
204 await model . updateWidgets ( )
200 205 }
201 206 // S p o t l i g h t f o l l o w s t h e f i l e s a n d s a v e d e d i t s .
202 207 . task ( id : SpotlightKey ( files : workspace . files . count , changed : workspace . changedFile ? . version , saved : session . dirtyPaths . count ) ) {
@@ -217,7 +222,16 @@ struct RootView: View {
217 222 Task { await workspace . refresh ( ) }
218 223 }
219 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 // T h e L i v e A c t i v i t y f o l l o w s t h e c l o c k , w h e r e v e r i t s t a r t s o r s t o p s .
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 245 if ! waiting . isEmpty { capture = waiting . removeFirst ( ) }
232 246 }
233 247
248 // / A w i d g e t ' s o r t h e L i v e A c t i v i t y ' s l i n k .
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 261 private func clock ( _ id : String ) {
235 262 if id = = " app.clock.report " {
236 263 showingClockReport = true
ios/Orgstar/Info.plist
+10 · view
@@ -24,11 +24,21 @@
24 24 <string>org-protocol</string>
25 25 </array>
26 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 35 </array>
28 36 <key>CFBundleVersion</key>
29 37 <string>$(CURRENT_PROJECT_VERSION)</string>
30 38 <key>NSCalendarsFullAccessUsageDescription</key>
31 39 <string>The agenda shows your calendar events alongside your Org entries. Orgstar only reads them.</string>
40 <key>NSSupportsLiveActivities</key>
41 <true/>
32 42 <key>UIApplicationSceneManifest</key>
33 43 <dict>
34 44 <key>UIApplicationSupportsMultipleScenes</key>