Sources/OrgApp/WhatsNew.swift

19641366e5de9103a7d88bf80436ab2aebc03cf5
orgstar/Sources/OrgApp/WhatsNew.swift

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

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form