Commit 6236c2f7de

6236c2f7de7b4f3c92176353e4a33e66b9181766

parent: 173b70c8c8

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-14 03:50 UTC

Welcome sheet on first launch; iOS opens on Folders until a folder exists

With no folder added, the Mac shows a sheet once: choose a folder, or make
org/notes.org in iCloud Drive (when iCloud Drive is on) and add it, and
pick the key preset. Get Started… in the empty window opens it again. On
iOS the Agenda tab has nothing to show without a folder, so the app starts
on Folders until one is added.

Closes #72

Layout: unified · split

Sources/Orgstar/ContentView.swift +19 −5
@@ -32,6 +32,8 @@ struct ContentView: View {
32 @State private var keymap = KeymapPreset.emacs.keymap 32 @State private var keymap = KeymapPreset.emacs.keymap
33 @AppStorage("tagsColumn") private var tagsColumn = -77 33 @AppStorage("tagsColumn") private var tagsColumn = -77
34 @AppStorage("headingAfterSubtree") private var headingAfterSubtree = false 34 @AppStorage("headingAfterSubtree") private var headingAfterSubtree = false
35 /// The welcome sheet has been shown once; it comes back only through the empty state.
36 @AppStorage("welcomeShown") private var welcomeShown = false
35 @AppStorage("splitLine") private var splitLine = false 37 @AppStorage("splitLine") private var splitLine = false
36 @AppStorage("alphabeticalLists") private var alphabeticalLists = true 38 @AppStorage("alphabeticalLists") private var alphabeticalLists = true
37 @AppStorage("fillColumn") private var fillColumn = 80 39 @AppStorage("fillColumn") private var fillColumn = 80
@@ -171,11 +173,13 @@ struct ContentView: View {
171 } 173 }
172 } 174 }
173 } else { 175 } else {
174 ContentUnavailableView( 176 ContentUnavailableView {
175 workspace.roots.isEmpty ? "Add a folder of org files" : "Choose a file", 177 Label(workspace.roots.isEmpty ? "Add a folder of org files" : "Choose a file", systemImage: "doc.text")
176 systemImage: "doc.text", 178 } description: {
177 description: Text(workspace.roots.isEmpty ? "File ▸ Add Folder… (⇧⌘O)" : "Or press ⌘P to open one by name.") 179 Text(workspace.roots.isEmpty ? "File ▸ Add Folder… (⇧⌘O)" : "Or press ⌘P to open one by name.")
178 ) 180 } actions: {
181 if workspace.roots.isEmpty { Button("Get Started…") { commands.showingWelcome = true } }
182 }
179 } 183 }
180 } 184 }
181 185
@@ -299,6 +303,10 @@ struct ContentView: View {
299 clock.remindAtEffort(session) 303 clock.remindAtEffort(session)
300 commands.knownTags = { [index = workspace.index] in (try? index.tags()) ?? [] } 304 commands.knownTags = { [index = workspace.index] in (try? index.tags()) ?? [] }
301 commands.mainWindowOpen = true 305 commands.mainWindowOpen = true
306 if workspace.roots.isEmpty, !welcomeShown {
307 welcomeShown = true
308 commands.showingWelcome = true
309 }
302 if let stale = window { commands.store.windows.removeAll { $0 === stale } } 310 if let stale = window { commands.store.windows.removeAll { $0 === stale } }
303 // The session's first pane the first time; a new one showing the focused buffer 311 // The session's first pane the first time; a new one showing the focused buffer
304 // when the window opens again. 312 // when the window opens again.
@@ -336,6 +344,12 @@ struct ContentView: View {
336 commands.editor?.perform(ReplaceBlockLines(edit: request.edit, content: content)) 344 commands.editor?.perform(ReplaceBlockLines(edit: request.edit, content: content))
337 } 345 }
338 } 346 }
347 .sheet(isPresented: $commands.showingWelcome) {
348 WelcomeView(workspace: workspace, chooseFolder: {
349 // After the sheet closes, so the picker can present.
350 DispatchQueue.main.async { commands.showingFolderPicker = true }
351 }, open: { selectedFile = $0 })
352 }
339 .sheet(isPresented: $commands.showingPalette) { 353 .sheet(isPresented: $commands.showingPalette) {
340 PaletteView(commands: commands) { id in 354 PaletteView(commands: commands) { id in
341 commands.showingPalette = false 355 commands.showingPalette = false
Sources/Orgstar/OrgstarApp.swift +2
@@ -12,6 +12,8 @@ import UserNotifications
12final class AppCommands { 12final class AppCommands {
13 var showingQuickOpen = false 13 var showingQuickOpen = false
14 var showingFolderPicker = false 14 var showingFolderPicker = false
15 /// The first-launch sheet, while no folder has been added.
16 var showingWelcome = false
15 var focusSearch = false 17 var focusSearch = false
16 var showingConflict = false 18 var showingConflict = false
17 var showingPalette = false 19 var showingPalette = false
Sources/Orgstar/WelcomeView.swift added +75
@@ -0,0 +1,75 @@
1import OrgApp
2import OrgCore
3import SwiftUI
4
5/// The first launch, with no folder added: add a folder or start one, and pick the keys.
6struct WelcomeView: View {
7 let workspace: WorkspaceModel
8 /// Opens the folder picker once the sheet has closed.
9 let chooseFolder: () -> Void
10 /// Shows the file the sheet made.
11 let open: (String) -> Void
12 @AppStorage("keymap") private var preset = KeymapPreset.emacs
13 @State private var error: String?
14 @Environment(\.dismiss) private var dismiss
15
16 /// iCloud Drive's folder, when iCloud Drive is on for this user.
17 static var iCloudDrive: URL? {
18 let url = FileManager.default.homeDirectoryForCurrentUser
19 .appendingPathComponent("Library/Mobile Documents/com~apple~CloudDocs")
20 return FileManager.default.fileExists(atPath: url.path) ? url : nil
21 }
22
23 var body: some View {
24 VStack(alignment: .leading, spacing: 14) {
25 Text("Welcome to orgstar").font(.title2.bold())
26 Text("orgstar edits a folder of plain-text org files in place. Add the folder your notes are in, or start a new one. Nothing is copied or moved, and you can add more folders later with File ▸ Add Folder….")
27 Picker("Keys", selection: $preset) {
28 ForEach(KeymapPreset.allCases, id: \.self) { Text($0.title).tag($0) }
29 }
30 Text(presetNote).font(.callout).foregroundStyle(.secondary)
31 if let error { Text(error).foregroundStyle(.red) }
32 HStack {
33 Button("Not Now") { dismiss() }
34 Spacer()
35 if let drive = Self.iCloudDrive {
36 Button("New Folder in iCloud Drive") { start(in: drive.appendingPathComponent("org")) }
37 .help("Makes org/notes.org in iCloud Drive and adds the folder")
38 }
39 Button("Choose Folder…") {
40 dismiss()
41 chooseFolder()
42 }
43 .keyboardShortcut(.defaultAction)
44 }
45 }
46 .padding(20)
47 .frame(width: 480)
48 }
49
50 private var presetNote: String {
51 switch preset {
52 case .emacs: "Org's own bindings: C-c C-t cycles TODO, C-c C-s schedules, M-RET makes a heading."
53 case .mac: "Standard Mac editing keys, with Org commands on ⌃⌘: ⌃⌘T cycles TODO, ⌃⌘S schedules."
54 case .doom: "Modal editing as in Doom Emacs, with SPC as the leader: SPC m t cycles TODO."
55 }
56 }
57
58 /// Makes `folder` with a notes file in it, adds it, and opens the file.
59 private func start(in folder: URL) {
60 Task {
61 do {
62 let file = folder.appendingPathComponent("notes.org")
63 try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)
64 if !FileManager.default.fileExists(atPath: file.path) {
65 try "* Inbox\n".write(to: file, atomically: true, encoding: .utf8)
66 }
67 try await workspace.addRoot(folder)
68 open(file.standardizedFileURL.path)
69 dismiss()
70 } catch {
71 self.error = error.localizedDescription
72 }
73 }
74 }
75}
Sources/OrgstarMobile/OrgstarMobileApp.swift +2
@@ -190,6 +190,8 @@ struct RootView: View {
190 } 190 }
191 } 191 }
192 .clockAccessory(model.clock, perform: clock) 192 .clockAccessory(model.clock, perform: clock)
193 // Until a folder is added there is nothing for the agenda to show.
194 .onAppear { if workspace.rootPaths.isEmpty { tab = .folders } }
193 .sheet(item: Binding(get: { model.clockPrompts.pending }, set: { if $0 == nil { model.clockPrompts.answer(nil) } })) { pending in 195 .sheet(item: Binding(get: { model.clockPrompts.pending }, set: { if $0 == nil { model.clockPrompts.answer(nil) } })) { pending in
194 ClockPromptSheet(prompt: pending.prompt) { model.clockPrompts.answer($0) } 196 ClockPromptSheet(prompt: pending.prompt) { model.clockPrompts.answer($0) }
195 } 197 }
docs/manual/guide/01-files-and-folders.org +1 −1
@@ -46,7 +46,7 @@ orgstar does not open a single folder like a project. You add any number of fold
46 46
47** Adding a folder 47** Adding a folder
48 48
49Choose File ▸ Add Folder… (=⇧⌘O=), or click =+= at the bottom of the sidebar, and pick a folder. orgstar indexes it in the background; the toolbar shows a progress indicator while it works. 49Choose File ▸ Add Folder… (=⇧⌘O=), or click =+= at the bottom of the sidebar, and pick a folder. The first time orgstar opens with no folder, a welcome sheet offers the same, or a new =org= folder in iCloud Drive with a =notes.org= in it, and the choice of keys; Get Started… in the empty window opens the sheet again. orgstar indexes it in the background; the toolbar shows a progress indicator while it works.
50 50
51orgstar keeps a bookmark to each folder, so a folder you move or rename in Finder is followed. If a folder can't be found at launch, orgstar reports =Can't find the folder PATH.= Adding a folder that is already in the sidebar does nothing. 51orgstar keeps a bookmark to each folder, so a folder you move or rename in Finder is followed. If a folder can't be found at launch, orgstar reports =Can't find the folder PATH.= Adding a folder that is already in the sidebar does nothing.
52 52
docs/manual/guide/14-ios.org +1 −1
@@ -4,7 +4,7 @@
4 4
5* Overview 5* Overview
6 6
7The app has three tabs: 7The app has three tabs, and opens on Folders until a folder has been added:
8 8
9- Agenda :: the agenda over your folders, with capture. 9- Agenda :: the agenda over your folders, with capture.
10- Folders :: the folders of org files you added. Each shows its subfolders and org files; tap a subfolder to open it. 10- Folders :: the folders of org files you added. Each shows its subfolders and org files; tap a subfolder to open it.
docs/manual/quickstart.org +5 −1
@@ -4,7 +4,11 @@
4 4
5* Add a folder 5* Add a folder
6 6
7Choose File ▸ Add Folder… (=⇧⌘O=) and pick the folder that holds your org files. 7The first time orgstar opens with no folder, a welcome sheet offers to choose a folder,
8to make one (=org= in iCloud Drive, with a =notes.org= to start on), and the keys to use. Get
9Started… in the empty window opens it again.
10
11Otherwise, choose File ▸ Add Folder… (=⇧⌘O=) and pick the folder that holds your org files.
8It appears in the sidebar, and orgstar indexes every org file under it for search, 12It appears in the sidebar, and orgstar indexes every org file under it for search,
9the agenda and links. You can add several folders. Nothing is copied or moved. 13the agenda and links. You can add several folders. Nothing is copied or moved.
10 14