Default config.toml on iOS !194
merged
merged by cmc on 2026-10-10 03:26 UTC
· krz/orgstar:ios-default-config into main
Conversation
Commits 1
Files changed 4
4 files changed, +30 −3
Layout: unified · split
Sources/OrgApp/UserConfig.swift
+8 −1
@@ -371,6 +371,13 @@ public enum UserConfig {
371
371
372 // / A c o m m e n t e d f i l e w i t h e v e r y s e t t i n g a t i t s c u r r e n t v a l u e .
372 // / A c o m m e n t e d f i l e w i t h e v e r y s e t t i n g a t i t s c u r r e n t v a l u e .
373 public static func template ( from defaults : UserDefaults ) -> String {
373 public static func template ( from defaults : UserDefaults ) -> String {
374 template { value ( $0 , in : defaults ) }
375 }
376
377 // / A c o m m e n t e d f i l e w i t h e v e r y s e t t i n g a t i t s d e f a u l t .
378 public static var defaultTemplate : String { template ( \ . fallback ) }
379
380 private static func template ( _ value : ( Setting ) -> TOML . Value ) -> String {
374 var out = " " "
381 var out = " " "
375 # Orgstar settings. The Settings window writes its changes here, and edits made here
382 # Orgstar settings. The Settings window writes its changes here, and edits made here
376 # apply while Orgstar runs. Keys go in keymap.toml, capture templates in capture.toml
383 # apply while Orgstar runs. Keys go in keymap.toml, capture templates in capture.toml
@@ -385,7 +392,7 @@ public enum UserConfig {
385 section = setting . section
392 section = setting . section
386 out += " \n [ \( section ) ] \n "
393 out += " \n [ \( section ) ] \n "
387 }
394 }
388 out += " \( setting . key ) = \( format ( value ( setting , in : defaults ) ) ) # \( setting . comment ) \n "
395 out += " \( setting . key ) = \( format ( value ( setting ) ) ) # \( setting . comment ) \n "
389 }
396 }
390 return out
397 return out
391 }
398 }
Sources/OrgstarMobile/MobileModel.swift
+11
@@ -88,6 +88,7 @@ final class MobileModel {
88 if let url {
88 if let url {
89 _ = url . startAccessingSecurityScopedResource ( )
89 _ = url . startAccessingSecurityScopedResource ( )
90 if let bookmark = try ? url . bookmarkData ( ) { UserDefaults . standard . set ( bookmark , forKey : Self . bookmarkKey ) }
90 if let bookmark = try ? url . bookmarkData ( ) { UserDefaults . standard . set ( bookmark , forKey : Self . bookmarkKey ) }
91 Self . createConfig ( in : url )
91 } else {
92 } else {
92 UserDefaults . standard . removeObject ( forKey : Self . bookmarkKey )
93 UserDefaults . standard . removeObject ( forKey : Self . bookmarkKey )
93 // W h a t t h e f o l d e r s e t n o l o n g e r a p p l i e s .
94 // W h a t t h e f o l d e r s e t n o l o n g e r a p p l i e s .
@@ -177,6 +178,16 @@ final class MobileModel {
177
178
178 // / A p p l i e s t h e f o l d e r ' s ` c o n f i g . t o m l ` t o t h e s e t t i n g s ; r e t u r n s i t s p r o b l e m s a n d t h e t h e m e ' s
179 // / A p p l i e s t h e f o l d e r ' s ` c o n f i g . t o m l ` t o t h e s e t t i n g s ; r e t u r n s i t s p r o b l e m s a n d t h e t h e m e ' s
179 // / c o l o r s .
180 // / c o l o r s .
181 // / W r i t e s ` c o n f i g . t o m l ` w i t h e v e r y s e t t i n g a t i t s d e f a u l t w h e n t h e f o l d e r h a s n o n e .
182 private static func createConfig ( in folder : URL ) {
183 let file = folder . appendingPathComponent ( " config.toml " )
184 var error : NSError ?
185 NSFileCoordinator ( filePresenter : nil ) . coordinate ( writingItemAt : file , options : [ ] , error : & error ) { url in
186 guard ! FileManager . default . fileExists ( atPath : url . path ) else { return }
187 try ? UserConfig . defaultTemplate . write ( to : url , atomically : true , encoding : . utf8 )
188 }
189 }
190
180 private static func readConfig ( _ folder : URL ? ) -> ( [ String ] , ThemeSpec ) {
191 private static func readConfig ( _ folder : URL ? ) -> ( [ String ] , ThemeSpec ) {
181 guard let folder else { return ( [ ] , . default ) }
192 guard let folder else { return ( [ ] , . default ) }
182 guard let text = read ( folder . appendingPathComponent ( " config.toml " ) ) else {
193 guard let text = read ( folder . appendingPathComponent ( " config.toml " ) ) else {
Tests/OrgAppTests/UserConfigTests.swift
+9
@@ -32,6 +32,15 @@ struct UserConfigTests {
32 # expect ( target . bool ( forKey : " showLineNumbers " ) = = false )
32 # expect ( target . bool ( forKey : " showLineNumbers " ) = = false )
33 }
33 }
34
34
35 @ Test func defaultTemplateHasEveryDefault ( ) {
36 # expect ( UserConfig . defaultTemplate = = UserConfig . template ( from : defaults ( ) ) )
37 let target = defaults ( )
38 # expect ( UserConfig . apply ( UserConfig . defaultTemplate , to : target ) . isEmpty )
39 for setting in UserConfig . settings {
40 # expect ( UserConfig . value ( setting , in : target ) = = setting . fallback , " \( setting . key ) " )
41 }
42 }
43
35 @ Test func problemsAndRemovedLines ( ) {
44 @ Test func problemsAndRemovedLines ( ) {
36 let target = defaults ( )
45 let target = defaults ( )
37 target . set ( 60 , forKey : " fillColumn " )
46 target . set ( 60 , forKey : " fillColumn " )
docs/manual/guide/14-ios.org
+2 −2
@@ -305,9 +305,9 @@ See [[file:15-alongside-emacs.org][Working alongside Emacs and other tools]] for
305 The iOS app reads its settings from a configuration folder: a folder holding =config.toml= and =capture.toml= , such as a copy of the Mac's =~/.config/orgstar= synced through iCloud Drive or another app.
305 The iOS app reads its settings from a configuration folder: a folder holding =config.toml= and =capture.toml= , such as a copy of the Mac's =~/.config/orgstar= synced through iCloud Drive or another app.
306
306
307 1. Open the Settings tab.
307 1. Open the Settings tab.
308 2. Tap Choose Folder… and choose the folder.
308 2. Tap Choose Folder… and choose the folder. If it has no =config.toml= , Orgstar writes one with every setting at its default, each with a comment, as the Mac does.
309
309
310 Changes to the files apply as they sync, and again each time you return to the app. Problems in the files show in red under the folder. "No config.toml in /folder/ ; the defaults apply" means the folder has no =config.toml= .
310 Changes to the files apply as they sync, and again each time you return to the app. Problems in the files show in red under the folder. "No config.toml in /folder/ ; the defaults apply" means the folder has no =config.toml= , for example because it was removed after you chose the folder.
311
311
312 Stop Using This Folder returns every setting to its default.
312 Stop Using This Folder returns every setting to its default.
313
313
Checks
No checks reported
Revisions
1. 49cb8f339f 2026-10-10 03:26 UTC
Source and target
krz/orgstar:ios-default-config into main
merged at 49cb8f339f · base b98a6509c5 · branch deleted