Sources/OrgApp/WhatsNew.swift

b30097e424f50f317c0ad40ea5ee764c57f31028
orgstar/Sources/OrgApp/WhatsNew.swift

133 lines · 5470 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.2.0", items: ios + [
 42            .init("square.and.arrow.up", "LaTeX, OpenDocument and plain text export",
 43                  "Export and publish to LaTeX, ODT and ASCII without Emacs."),
 44            .init("play.rectangle", "Code blocks that run in orgstar",
 45                  "Emacs Lisp, JavaScript, calc and sqlite blocks run without any other program installed."),
 46            .init("tablecells", "More table formulas",
 47                  "More Calc and Lisp formulas, date arithmetic and org-sbe are worked out without Emacs."),
 48            .init("chart.xyaxis.line", "Plots",
 49                  "Radar plots, more of gnuplot's set options, and SVG files without gnuplot."),
 50            .init("point.3.connected.trianglepath.dotted", "Diagrams",
 51                  "dot and mermaid blocks draw SVG and PNG pictures without Graphviz or mermaid installed."),
 52            .init("circle.hexagongrid", "Node graph",
 53                  "Show Node Graph draws your org-roam or Denote notes and the links between them."),
 54            .init("function", "Math in PDFs",
 55                  "PDF export typesets math without a network connection."),
 56        ] + mac),
 57    ]
 58
 59    #if os(iOS)
 60    private static let ios = [
 61        ReleaseNotes.Item("iphone", "More from the Mac app",
 62                          "Archive subtrees, publish projects, show calendars in the agenda, copy rich text, and resolve idle clock time."),
 63        ReleaseNotes.Item("doc.viewfinder", "Scan documents",
 64                          "More ▸ Attachments ▸ Scan Document… saves the pages as a PDF and links it at the caret."),
 65    ]
 66    private static let mac: [ReleaseNotes.Item] = []
 67    #else
 68    private static let ios: [ReleaseNotes.Item] = []
 69    private static let mac = [
 70        ReleaseNotes.Item("menubar.rectangle", "orgstar in the menu bar",
 71                          "Settings ▸ General ▸ Keep orgstar in the menu bar adds capture, the agenda and today's entries to the menu bar."),
 72    ]
 73    #endif
 74
 75    /// The notes to show at launch: those for `version`, the first time it runs after another
 76    /// version did. Records `version` as seen. `firstLaunch` is a new install, which shows none.
 77    public static func pending(
 78        version: String = appVersion, firstLaunch: Bool, defaults: UserDefaults = .standard, releases: [ReleaseNotes] = releases
 79    ) -> ReleaseNotes? {
 80        let seen = defaults.string(forKey: seenKey)
 81        defaults.set(version, forKey: seenKey)
 82        guard seen != version, !firstLaunch else { return nil }
 83        return releases.first { $0.version == version }
 84    }
 85}
 86
 87/// A version's notes, as a sheet.
 88public struct WhatsNewView: View {
 89    let notes: ReleaseNotes
 90    @Environment(\.dismiss) private var dismiss
 91
 92    public init(notes: ReleaseNotes) {
 93        self.notes = notes
 94    }
 95
 96    public var body: some View {
 97        VStack(spacing: 24) {
 98            Text("What's New in orgstar \(notes.version)").font(.title2.bold()).multilineTextAlignment(.center)
 99            #if os(macOS)
100            items
101            #else
102            ScrollView { items }
103            #endif
104            Button { dismiss() } label: {
105                Text("Continue").frame(maxWidth: .infinity)
106            }
107            .buttonStyle(.borderedProminent)
108            .controlSize(.large)
109            .keyboardShortcut(.defaultAction)
110        }
111        .padding(24)
112        #if os(macOS)
113        .frame(width: 460)
114        #endif
115    }
116
117    private var items: some View {
118        VStack(alignment: .leading, spacing: 16) {
119            ForEach(notes.items) { item in
120                HStack(alignment: .top, spacing: 14) {
121                    Image(systemName: item.systemImage).font(.title2).foregroundStyle(Color.accentColor).frame(width: 32)
122                        .accessibilityHidden(true)
123                    VStack(alignment: .leading, spacing: 2) {
124                        Text(item.title).font(.headline)
125                        Text(item.text).font(.subheadline).foregroundStyle(.secondary)
126                    }
127                    .fixedSize(horizontal: false, vertical: true)
128                }
129            }
130        }
131        .frame(maxWidth: .infinity, alignment: .leading)
132    }
133}
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