Sources/OrgApp/WhatsNew.swift
188 lines · 9767 bytes
1import SwiftUI
2
3/// What changed in one version.
4public struct ReleaseNotes: Identifiable, Sendable {
5 public struct Item: Identifiable, Sendable {
6 public let systemImage: String
7 public let title: LocalizedStringResource
8 public let text: LocalizedStringResource
9
10 public var id: String { title.key }
11
12 public init(_ systemImage: String, _ title: LocalizedStringResource, _ text: LocalizedStringResource) {
13 self.systemImage = systemImage
14 self.title = title
15 self.text = text
16 }
17 }
18
19 /// The `CFBundleShortVersionString` the notes are for.
20 public let version: String
21 public let items: [Item]
22
23 public var id: String { version }
24
25 public init(version: String, items: [Item]) {
26 self.version = version
27 self.items = items
28 }
29}
30
31/// The notes shown once after an update to a version that has some.
32public enum WhatsNew {
33 static let seenKey = "whatsNew.seenVersion"
34
35 public static var appVersion: String {
36 Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
37 }
38
39 /// Newest first. A version without an entry shows nothing.
40 public static let releases: [ReleaseNotes] = [
41 ReleaseNotes(version: "1.4.0", items: [
42 .init("printer", "Printing", "Print the file, a subtree, the selection or the agenda."),
43 .init("doc.plaintext", "Markdown and plain text",
44 "Markdown and text files open with highlighting, heading folds and an outline, and search finds them."),
45 .init("note.text", "Denote in Markdown and text",
46 "Denote notes in Markdown and plain text, with their front matter, renaming, links and backlinks."),
47 .init("quote.opening", "Citations",
48 "Insert citations from your bibliography, complete keys after @, follow a citation to its entry, and open Zotero links."),
49 .init("point.3.connected.trianglepath.dotted", "More org-roam",
50 "Aliases, refs, excluded nodes, tags in the node chooser, and capture templates for new nodes and daily notes."),
51 ] + mac14),
52 ReleaseNotes(version: "1.3.0", items: [
53 .init("text.cursor", "Completion as you type",
54 "A completion list opens by itself in every preset, matches loosely, and offers words from your files, id links by title, property values and Denote notes."),
55 .init("text.badge.plus", "Snippets and templates",
56 "Snippets with tab stops, and templates for new files."),
57 .init("magnifyingglass", "Replace across files",
58 "Replace text in every file of your folders, or rename a tag or TODO keyword everywhere at once."),
59 .init("clock.arrow.circlepath", "File history",
60 "A file's recovery versions and git commits in one list."),
61 .init("checklist", "Lint",
62 "Lint File and Lint All Folders check your files with org-lint's rules."),
63 .init("lock.doc", "Encrypted files",
64 "Open and save .org.gpg files, encrypt entries tagged crypt whenever the file is saved, and, if you turn it on, unlock saved passphrases with Face ID or Touch ID."),
65 .init("laptopcomputer.and.iphone", "Handoff",
66 "Continue the open file at the same place on your Mac, iPhone or iPad."),
67 ] + ios13 + mac13 + [
68 .init("speedometer", "Faster",
69 "Files open, parse and are styled faster, and typing in long files stays smooth."),
70 ]),
71 ReleaseNotes(version: "1.2.0", items: ios + [
72 .init("square.and.arrow.up", "LaTeX, OpenDocument and plain text export",
73 "Export and publish to LaTeX, ODT and ASCII without Emacs."),
74 .init("play.rectangle", "Code blocks that run in orgstar",
75 "Emacs Lisp, JavaScript, calc and sqlite blocks run without any other program installed."),
76 .init("tablecells", "More table formulas",
77 "More Calc and Lisp formulas, date arithmetic and org-sbe are worked out without Emacs."),
78 .init("chart.xyaxis.line", "Plots",
79 "Radar plots, more of gnuplot's set options, and SVG files without gnuplot."),
80 .init("point.3.connected.trianglepath.dotted", "Diagrams",
81 "dot and mermaid blocks draw SVG and PNG pictures without Graphviz or mermaid installed."),
82 .init("circle.hexagongrid", "Node graph",
83 "Show Node Graph draws your org-roam or Denote notes and the links between them."),
84 .init("function", "Math in PDFs",
85 "PDF export typesets math without a network connection."),
86 ] + mac),
87 ]
88
89 #if os(iOS)
90 private static let ios = [
91 ReleaseNotes.Item("iphone", "More from the Mac app",
92 "Archive subtrees, publish projects, show calendars in the agenda, copy rich text, and resolve idle clock time."),
93 ReleaseNotes.Item("doc.viewfinder", "Scan documents",
94 "More ▸ Attachments ▸ Scan Document… saves the pages as a PDF and links it at the caret."),
95 ]
96 private static let mac: [ReleaseNotes.Item] = []
97 private static let ios13 = [
98 ReleaseNotes.Item("command", "One Commands list",
99 "Every screen has the same Commands list, and you can choose the keys on the bar above the keyboard."),
100 ReleaseNotes.Item("ipad", "iPad", "A sidebar layout, the menu bar and keyboard shortcuts."),
101 ReleaseNotes.Item("arrow.triangle.branch", "Working Copy", "Sync a folder that is a git repository through Working Copy."),
102 ]
103 private static let mac13: [ReleaseNotes.Item] = []
104 private static let mac14: [ReleaseNotes.Item] = []
105 #else
106 private static let ios: [ReleaseNotes.Item] = []
107 private static let ios13: [ReleaseNotes.Item] = []
108 private static let mac13 = [
109 ReleaseNotes.Item("record.circle", "Keyboard macros",
110 "Record and replay keyboard macros in the Emacs and Mac presets; named ones are kept across restarts."),
111 ReleaseNotes.Item("command", "Command palette", "Recent commands come first, and the ones you use most rank higher."),
112 ]
113 private static let mac14 = [
114 ReleaseNotes.Item("square.and.arrow.down", "Import Markdown and Obsidian",
115 "File ▸ Import converts Markdown files or an Obsidian vault to org files."),
116 ReleaseNotes.Item("textformat.size", "Larger text",
117 "Settings ▸ Appearance ▸ Size now enlarges the agenda and the sidebars as well as the editor."),
118 ]
119 private static let mac = [
120 ReleaseNotes.Item("sidebar.left", "Agenda in the sidebar",
121 "The calendar button under the sidebar shows your agenda, or a view from views.toml, beside the editor."),
122 ReleaseNotes.Item("menubar.rectangle", "orgstar in the menu bar",
123 "Settings ▸ General ▸ Keep orgstar in the menu bar adds capture, the agenda and today's entries to the menu bar."),
124 ]
125 #endif
126
127 /// The notes to show at launch, the first time `version` runs after another version did: the
128 /// newest notes for a version after the one seen last, up to `version`, so an update that
129 /// skips a version still shows its notes. Records `version` as seen. `firstLaunch` is a new
130 /// install, which shows none.
131 public static func pending(
132 version: String = appVersion, firstLaunch: Bool, defaults: UserDefaults = .standard, releases: [ReleaseNotes] = releases
133 ) -> ReleaseNotes? {
134 let seen = defaults.string(forKey: seenKey)
135 defaults.set(version, forKey: seenKey)
136 guard seen != version, !firstLaunch else { return nil }
137 func newer(_ a: String, than b: String) -> Bool { a.compare(b, options: .numeric) == .orderedDescending }
138 return releases.first { notes in !newer(notes.version, than: version) && seen.map { newer(notes.version, than: $0) } ?? true }
139 }
140}
141
142/// A version's notes, as a sheet.
143public struct WhatsNewView: View {
144 let notes: ReleaseNotes
145 @Environment(\.dismiss) private var dismiss
146
147 public init(notes: ReleaseNotes) {
148 self.notes = notes
149 }
150
151 public var body: some View {
152 VStack(spacing: 24) {
153 Text("What's New in orgstar \(notes.version)").font(.title2.bold()).multilineTextAlignment(.center)
154 #if os(macOS)
155 items
156 #else
157 ScrollView { items }
158 #endif
159 Button { dismiss() } label: {
160 Text("Continue").frame(maxWidth: .infinity)
161 }
162 .buttonStyle(.borderedProminent)
163 .controlSize(.large)
164 .keyboardShortcut(.defaultAction)
165 }
166 .padding(24)
167 #if os(macOS)
168 .frame(width: 460)
169 #endif
170 }
171
172 private var items: some View {
173 VStack(alignment: .leading, spacing: 16) {
174 ForEach(notes.items) { item in
175 HStack(alignment: .top, spacing: 14) {
176 Image(systemName: item.systemImage).font(.title2).foregroundStyle(Color.accentColor).frame(width: 32)
177 .accessibilityHidden(true)
178 VStack(alignment: .leading, spacing: 2) {
179 Text(item.title).font(.headline)
180 Text(item.text).font(.subheadline).foregroundStyle(.secondary)
181 }
182 .fixedSize(horizontal: false, vertical: true)
183 }
184 }
185 }
186 .frame(maxWidth: .infinity, alignment: .leading)
187 }
188}