Sources/OrgApp/WhatsNew.swift
167 lines · 8041 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.3.0", items: [
42 .init("text.cursor", "Completion as you type",
43 "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."),
44 .init("text.badge.plus", "Snippets and templates",
45 "Snippets with tab stops, and templates for new files."),
46 .init("magnifyingglass", "Replace across files",
47 "Replace text in every file of your folders, or rename a tag or TODO keyword everywhere at once."),
48 .init("clock.arrow.circlepath", "File history",
49 "A file's recovery versions and git commits in one list."),
50 .init("checklist", "Lint",
51 "Lint File and Lint All Folders check your files with org-lint's rules."),
52 .init("lock.doc", "Encrypted files",
53 "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."),
54 .init("laptopcomputer.and.iphone", "Handoff",
55 "Continue the open file at the same place on your Mac, iPhone or iPad."),
56 ] + ios13 + mac13 + [
57 .init("speedometer", "Faster",
58 "Files open, parse and are styled faster, and typing in long files stays smooth."),
59 ]),
60 ReleaseNotes(version: "1.2.0", items: ios + [
61 .init("square.and.arrow.up", "LaTeX, OpenDocument and plain text export",
62 "Export and publish to LaTeX, ODT and ASCII without Emacs."),
63 .init("play.rectangle", "Code blocks that run in orgstar",
64 "Emacs Lisp, JavaScript, calc and sqlite blocks run without any other program installed."),
65 .init("tablecells", "More table formulas",
66 "More Calc and Lisp formulas, date arithmetic and org-sbe are worked out without Emacs."),
67 .init("chart.xyaxis.line", "Plots",
68 "Radar plots, more of gnuplot's set options, and SVG files without gnuplot."),
69 .init("point.3.connected.trianglepath.dotted", "Diagrams",
70 "dot and mermaid blocks draw SVG and PNG pictures without Graphviz or mermaid installed."),
71 .init("circle.hexagongrid", "Node graph",
72 "Show Node Graph draws your org-roam or Denote notes and the links between them."),
73 .init("function", "Math in PDFs",
74 "PDF export typesets math without a network connection."),
75 ] + mac),
76 ]
77
78 #if os(iOS)
79 private static let ios = [
80 ReleaseNotes.Item("iphone", "More from the Mac app",
81 "Archive subtrees, publish projects, show calendars in the agenda, copy rich text, and resolve idle clock time."),
82 ReleaseNotes.Item("doc.viewfinder", "Scan documents",
83 "More ▸ Attachments ▸ Scan Document… saves the pages as a PDF and links it at the caret."),
84 ]
85 private static let mac: [ReleaseNotes.Item] = []
86 private static let ios13 = [
87 ReleaseNotes.Item("command", "One Commands list",
88 "Every screen has the same Commands list, and you can choose the keys on the bar above the keyboard."),
89 ReleaseNotes.Item("ipad", "iPad", "A sidebar layout, the menu bar and keyboard shortcuts."),
90 ReleaseNotes.Item("arrow.triangle.branch", "Working Copy", "Sync a folder that is a git repository through Working Copy."),
91 ]
92 private static let mac13: [ReleaseNotes.Item] = []
93 #else
94 private static let ios: [ReleaseNotes.Item] = []
95 private static let ios13: [ReleaseNotes.Item] = []
96 private static let mac13 = [
97 ReleaseNotes.Item("record.circle", "Keyboard macros",
98 "Record and replay keyboard macros in the Emacs and Mac presets; named ones are kept across restarts."),
99 ReleaseNotes.Item("command", "Command palette", "Recent commands come first, and the ones you use most rank higher."),
100 ]
101 private static let mac = [
102 ReleaseNotes.Item("sidebar.left", "Agenda in the sidebar",
103 "The calendar button under the sidebar shows your agenda, or a view from views.toml, beside the editor."),
104 ReleaseNotes.Item("menubar.rectangle", "orgstar in the menu bar",
105 "Settings ▸ General ▸ Keep orgstar in the menu bar adds capture, the agenda and today's entries to the menu bar."),
106 ]
107 #endif
108
109 /// The notes to show at launch: those for `version`, the first time it runs after another
110 /// version did. Records `version` as seen. `firstLaunch` is a new install, which shows none.
111 public static func pending(
112 version: String = appVersion, firstLaunch: Bool, defaults: UserDefaults = .standard, releases: [ReleaseNotes] = releases
113 ) -> ReleaseNotes? {
114 let seen = defaults.string(forKey: seenKey)
115 defaults.set(version, forKey: seenKey)
116 guard seen != version, !firstLaunch else { return nil }
117 return releases.first { $0.version == version }
118 }
119}
120
121/// A version's notes, as a sheet.
122public struct WhatsNewView: View {
123 let notes: ReleaseNotes
124 @Environment(\.dismiss) private var dismiss
125
126 public init(notes: ReleaseNotes) {
127 self.notes = notes
128 }
129
130 public var body: some View {
131 VStack(spacing: 24) {
132 Text("What's New in orgstar \(notes.version)").font(.title2.bold()).multilineTextAlignment(.center)
133 #if os(macOS)
134 items
135 #else
136 ScrollView { items }
137 #endif
138 Button { dismiss() } label: {
139 Text("Continue").frame(maxWidth: .infinity)
140 }
141 .buttonStyle(.borderedProminent)
142 .controlSize(.large)
143 .keyboardShortcut(.defaultAction)
144 }
145 .padding(24)
146 #if os(macOS)
147 .frame(width: 460)
148 #endif
149 }
150
151 private var items: some View {
152 VStack(alignment: .leading, spacing: 16) {
153 ForEach(notes.items) { item in
154 HStack(alignment: .top, spacing: 14) {
155 Image(systemName: item.systemImage).font(.title2).foregroundStyle(Color.accentColor).frame(width: 32)
156 .accessibilityHidden(true)
157 VStack(alignment: .leading, spacing: 2) {
158 Text(item.title).font(.headline)
159 Text(item.text).font(.subheadline).foregroundStyle(.secondary)
160 }
161 .fixedSize(horizontal: false, vertical: true)
162 }
163 }
164 }
165 .frame(maxWidth: .infinity, alignment: .leading)
166 }
167}