mirror of
https://github.com/maxgoedjen/secretive.git
synced 2025-09-20 03:10:57 +00:00
Cleaup.
This commit is contained in:
parent
34aad09126
commit
80ffe466f7
@ -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 }
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user