This commit is contained in:
Max Goedjen 2025-09-03 00:18:18 -07:00
parent 34aad09126
commit 80ffe466f7
No known key found for this signature in database
2 changed files with 22 additions and 55 deletions

View File

@ -45,9 +45,9 @@ struct Secretive: App {
ContentView(showingCreation: $showingCreation, runningSetup: $showingSetup, hasRunSetup: $hasRunSetup) ContentView(showingCreation: $showingCreation, runningSetup: $showingSetup, hasRunSetup: $hasRunSetup)
.environment(EnvironmentValues._secretStoreList) .environment(EnvironmentValues._secretStoreList)
.onAppear { .onAppear {
// if !hasRunSetup { if !hasRunSetup {
showingSetup = true showingSetup = true
// } }
} }
.onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in .onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in
guard hasRunSetup else { return } guard hasRunSetup else { return }

View File

@ -12,7 +12,7 @@ struct UpdateDetailView: View {
Text(.updateVersionName(updateName: update.name)).font(.title) Text(.updateVersionName(updateName: update.name)).font(.title)
GroupBox(label: Text(.updateReleaseNotesTitle)) { GroupBox(label: Text(.updateReleaseNotesTitle)) {
ScrollView { ScrollView {
Text(attributedBody) attributedBody
} }
} }
HStack { HStack {
@ -35,62 +35,29 @@ struct UpdateDetailView: View {
.frame(maxWidth: 500) .frame(maxWidth: 500)
} }
var attributedBody: AttributedString { var attributedBody: Text {
do { var text = Text(verbatim: "")
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
default:
nil
}
if let font {
key.replace(with: AttributeScopes.SwiftUIAttributes.FontAttribute.self, value: font)
}
}
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) { for line in update.body.split(whereSeparator: \.isNewline) {
let attributed: AttributedString let attributed: Text
let split = line.split(separator: " ") let split = line.split(separator: " ")
let unprefixed = split.dropFirst().joined(separator: " ") let unprefixed = split.dropFirst().joined(separator: " ")
if let prefix = split.first { if let prefix = split.first {
var container = AttributeContainer()
switch prefix { switch prefix {
case "#": case "#":
container.font = .title attributed = Text(unprefixed).font(.title) + Text(verbatim: "\n")
case "##": case "##":
container.font = .title2 attributed = Text(unprefixed).font(.title2) + Text(verbatim: "\n")
case "###": case "###":
container.font = .title3 attributed = Text(unprefixed).font(.title3) + Text(verbatim: "\n")
default: default:
continue attributed = Text(line) + Text(verbatim: "\n\n")
} }
attributed = AttributedString(unprefixed, attributes: container)
} else { } else {
attributed = AttributedString(line + "\n\n") attributed = Text(line) + Text(verbatim: "\n\n")
} }
text = text + attributed text = text + attributed
} }
return text return text
} }
}
} }