From 80ffe466f7e3679fdaa4fe7fbfd1099ecfa4d62a Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Wed, 3 Sep 2025 00:18:18 -0700 Subject: [PATCH] Cleaup. --- Sources/Secretive/App.swift | 4 +- .../Secretive/Views/Views/UpdateView.swift | 73 +++++-------------- 2 files changed, 22 insertions(+), 55 deletions(-) diff --git a/Sources/Secretive/App.swift b/Sources/Secretive/App.swift index b1b9575..93ecf03 100644 --- a/Sources/Secretive/App.swift +++ b/Sources/Secretive/App.swift @@ -45,9 +45,9 @@ struct Secretive: App { ContentView(showingCreation: $showingCreation, runningSetup: $showingSetup, hasRunSetup: $hasRunSetup) .environment(EnvironmentValues._secretStoreList) .onAppear { -// if !hasRunSetup { + if !hasRunSetup { showingSetup = true -// } + } } .onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in guard hasRunSetup else { return } diff --git a/Sources/Secretive/Views/Views/UpdateView.swift b/Sources/Secretive/Views/Views/UpdateView.swift index 2540bda..810e0e8 100644 --- a/Sources/Secretive/Views/Views/UpdateView.swift +++ b/Sources/Secretive/Views/Views/UpdateView.swift @@ -12,7 +12,7 @@ struct UpdateDetailView: View { Text(.updateVersionName(updateName: update.name)).font(.title) GroupBox(label: Text(.updateReleaseNotesTitle)) { ScrollView { - Text(attributedBody) + attributedBody } } HStack { @@ -35,62 +35,29 @@ struct UpdateDetailView: View { .frame(maxWidth: 500) } - var attributedBody: AttributedString { - do { - var text = try AttributedString( - markdown: update.body, - options: .init( - allowsExtendedAttributes: true, - interpretedSyntax: .full, - ), - baseURL: URL(string: "https://github.com/maxgoedjen/secretive")! - ) - .transformingAttributes(AttributeScopes.FoundationAttributes.PresentationIntentAttribute.self) { key in - let font: Font? = switch key.value?.components.first?.kind { - case .header(level: 1): - Font.title - case .header(level: 2): - Font.title2 - case .header(level: 3): - Font.title3 + var attributedBody: Text { + var text = Text(verbatim: "") + for line in update.body.split(whereSeparator: \.isNewline) { + let attributed: Text + let split = line.split(separator: " ") + let unprefixed = split.dropFirst().joined(separator: " ") + if let prefix = split.first { + switch prefix { + case "#": + attributed = Text(unprefixed).font(.title) + Text(verbatim: "\n") + case "##": + attributed = Text(unprefixed).font(.title2) + Text(verbatim: "\n") + case "###": + attributed = Text(unprefixed).font(.title3) + Text(verbatim: "\n") default: - nil - } - if let font { - key.replace(with: AttributeScopes.SwiftUIAttributes.FontAttribute.self, value: font) + attributed = Text(line) + Text(verbatim: "\n\n") } + } else { + attributed = Text(line) + Text(verbatim: "\n\n") } - let lineBreak = AttributedString("\n\n") - for run in text.runs.reversed() { - text.insert(lineBreak, at: run.range.lowerBound) - } - return text - } catch { - var text = AttributedString() - for line in update.body.split(whereSeparator: \.isNewline) { - let attributed: AttributedString - let split = line.split(separator: " ") - let unprefixed = split.dropFirst().joined(separator: " ") - if let prefix = split.first { - var container = AttributeContainer() - switch prefix { - case "#": - container.font = .title - case "##": - container.font = .title2 - case "###": - container.font = .title3 - default: - continue - } - attributed = AttributedString(unprefixed, attributes: container) - } else { - attributed = AttributedString(line + "\n\n") - } - text = text + attributed - } - return text + text = text + attributed } + return text } }