Edit config.toml on iOS !195

merged merged by cmc on 2026-10-10 03:34 UTC · krz/orgstar:ios-edit-config into main

3 files changed, +90 −0

Layout: unified · split

Sources/OrgstarMobile/MobileModel.swift +15
@@ -129,6 +129,21 @@ final class MobileModel {
129129 settingsVersion += 1
130130 }
131131
132 /// The folder's `config.toml`, read in coordination with the app that syncs it.
133 func configText() -> String? {
134 configFolder.flatMap { Self.read($0.appendingPathComponent("config.toml")) }
135 }
136
137 /// Writes the folder's `config.toml` and applies it.
138 func saveConfig(_ text: String) {
139 guard let configFolder else { return }
140 var error: NSError?
141 NSFileCoordinator(filePresenter: nil).coordinate(writingItemAt: configFolder.appendingPathComponent("config.toml"), options: [], error: &error) { url in
142 try? text.write(to: url, atomically: true, encoding: .utf8)
143 }
144 reloadConfig()
145 }
146
132147 /// Changes a setting from the app: in the folder's config.toml when there is a folder, as
133148 /// the Mac's Settings write it, else in this device's settings.
134149 func set(_ defaultsKey: String, to value: TOML.Value) {
Sources/OrgstarMobile/SettingsScreen.swift +73
@@ -24,6 +24,7 @@ struct SettingsScreen: View {
2424 LabeledContent("Folder", value: model.configFolder?.lastPathComponent ?? "None")
2525 Button(model.configFolder == nil ? "Choose Folder…" : "Choose Another Folder…") { choosing = true }
2626 if model.configFolder != nil {
27 NavigationLink("Edit config.toml") { ConfigFileEditor(model: model) }
2728 Button("Stop Using This Folder", role: .destructive) { model.setConfigFolder(nil) }
2829 }
2930 ForEach(model.configProblems, id: \.self) { Text($0).foregroundStyle(.red) }
@@ -158,4 +159,76 @@ struct SettingsScreen: View {
158159 .joined(separator: "; ")
159160 }
160161}
162/// The configuration folder's `config.toml` as plain text, saved when you tap Save or leave.
163struct ConfigFileEditor: View {
164 let model: MobileModel
165 @State private var text = ""
166 @State private var saved: String?
167
168 var body: some View {
169 PlainTextView(text: $text)
170 .navigationTitle("config.toml")
171 .navigationBarTitleDisplayMode(.inline)
172 .toolbar {
173 Button("Save") { save() }.disabled(text == saved)
174 }
175 .safeAreaInset(edge: .bottom) {
176 let _ = model.settingsVersion
177 if !model.configProblems.isEmpty {
178 VStack(alignment: .leading, spacing: 4) {
179 ForEach(model.configProblems, id: \.self) { Text($0) }
180 }
181 .font(.footnote)
182 .foregroundStyle(.red)
183 .padding()
184 .frame(maxWidth: .infinity, alignment: .leading)
185 .background(.bar)
186 }
187 }
188 .onAppear {
189 guard saved == nil else { return }
190 text = model.configText() ?? UserConfig.defaultTemplate
191 saved = text
192 }
193 .onDisappear { save() }
194 }
195
196 private func save() {
197 guard text != saved else { return }
198 model.saveConfig(text)
199 saved = text
200 }
201}
202
203/// A monospaced text view without smart quotes, dashes or autocorrection, which would break TOML.
204private struct PlainTextView: UIViewRepresentable {
205 @Binding var text: String
206
207 func makeUIView(context: Context) -> UITextView {
208 let view = UITextView()
209 view.font = .monospacedSystemFont(ofSize: UIFont.preferredFont(forTextStyle: .footnote).pointSize, weight: .regular)
210 view.adjustsFontForContentSizeCategory = true
211 view.autocorrectionType = .no
212 view.autocapitalizationType = .none
213 view.smartQuotesType = .no
214 view.smartDashesType = .no
215 view.smartInsertDeleteType = .no
216 view.spellCheckingType = .no
217 view.keyboardDismissMode = .interactive
218 view.delegate = context.coordinator
219 return view
220 }
221
222 func updateUIView(_ view: UITextView, context: Context) {
223 if view.text != text { view.text = text }
224 }
225
226 func makeCoordinator() -> Coordinator { Coordinator(text: $text) }
227
228 final class Coordinator: NSObject, UITextViewDelegate {
229 var text: Binding<String>
230 init(text: Binding<String>) { self.text = text }
231 func textViewDidChange(_ view: UITextView) { text.wrappedValue = view.text }
232 }
233}
161234#endif
docs/manual/guide/14-ios.org +2
@@ -309,6 +309,8 @@ The iOS app reads its settings from a configuration folder: a folder holding =co
309309
310310Changes 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.
311311
312Edit config.toml opens the folder's =config.toml= as plain text, with smart quotes and dashes off. Save, or going back, writes it and applies it at once; problems show in red below the text.
313
312314Stop Using This Folder returns every setting to its default.
313315
314316The Agenda, TODO Dependencies and Calendar sections are the only places the app changes a setting itself: