Sources/OrgApp/WhatsNew.swift

49c5da97098ed000be935c19462d4102812b0471
orgstar/Sources/OrgApp/WhatsNew.swift

170 lines · 8366 bytes

6 symbols in this file
  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, the first time `version` runs after another version did: the
110    /// newest notes for a version after the one seen last, up to `version`, so an update that
111    /// skips a version still shows its notes. Records `version` as seen. `firstLaunch` is a new
112    /// install, which shows none.
113    public static func pending(
114        version: String = appVersion, firstLaunch: Bool, defaults: UserDefaults = .standard, releases: [ReleaseNotes] = releases
115    ) -> ReleaseNotes? {
116        let seen = defaults.string(forKey: seenKey)
117        defaults.set(version, forKey: seenKey)
118        guard seen != version, !firstLaunch else { return nil }
119        func newer(_ a: String, than b: String) -> Bool { a.compare(b, options: .numeric) == .orderedDescending }
120        return releases.first { notes in !newer(notes.version, than: version) && seen.map { newer(notes.version, than: $0) } ?? true }
121    }
122}
123
124/// A version's notes, as a sheet.
125public struct WhatsNewView: View {
126    let notes: ReleaseNotes
127    @Environment(\.dismiss) private var dismiss
128
129    public init(notes: ReleaseNotes) {
130        self.notes = notes
131    }
132
133    public var body: some View {
134        VStack(spacing: 24) {
135            Text("What's New in orgstar \(notes.version)").font(.title2.bold()).multilineTextAlignment(.center)
136            #if os(macOS)
137            items
138            #else
139            ScrollView { items }
140            #endif
141            Button { dismiss() } label: {
142                Text("Continue").frame(maxWidth: .infinity)
143            }
144            .buttonStyle(.borderedProminent)
145            .controlSize(.large)
146            .keyboardShortcut(.defaultAction)
147        }
148        .padding(24)
149        #if os(macOS)
150        .frame(width: 460)
151        #endif
152    }
153
154    private var items: some View {
155        VStack(alignment: .leading, spacing: 16) {
156            ForEach(notes.items) { item in
157                HStack(alignment: .top, spacing: 14) {
158                    Image(systemName: item.systemImage).font(.title2).foregroundStyle(Color.accentColor).frame(width: 32)
159                        .accessibilityHidden(true)
160                    VStack(alignment: .leading, spacing: 2) {
161                        Text(item.title).font(.headline)
162                        Text(item.text).font(.subheadline).foregroundStyle(.secondary)
163                    }
164                    .fixedSize(horizontal: false, vertical: true)
165                }
166            }
167        }
168        .frame(maxWidth: .infinity, alignment: .leading)
169    }
170}
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