Skip to content

Commit

Permalink
Update data structs to classes. Update comments. Add environment obje…
Browse files Browse the repository at this point in the history
…cts.
  • Loading branch information
W1W1-M committed Dec 16, 2021
1 parent 8c12901 commit d3cf6ef
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
6 changes: 3 additions & 3 deletions Sources/PackAPrefPane/PrefPaneData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public struct PrefPaneData {
public let legalSectionData: LegalSectionData
}
/// Type to group help section data
public struct HelpSectionData {
public class HelpSectionData: ObservableObject {
/// ``HelpSectionData`` public initializer for swift package usage
/// - Parameters:
/// - showHelpSection: ``HelpSectionData/showHelpSection``
Expand Down Expand Up @@ -129,7 +129,7 @@ public struct FrequentlyAskedQuestions: Identifiable {
public let answer: String
}
/// Type to group about section data
public struct AboutSectionData {
public class AboutSectionData: ObservableObject {
/// ``AboutSectionData`` public initializer for swift package usage
/// - Parameters:
/// - developerInfoText: ``AboutSectionData/developerInfoText``
Expand Down Expand Up @@ -196,7 +196,7 @@ public struct ThirdPartyCode: Identifiable {
public let sourceLicenseText: String
}
/// Type to group legal section data
public struct LegalSectionData {
public class LegalSectionData: ObservableObject {
/// ``LegalSectionData`` public initializer for swift package usage
/// - Parameters:
/// - showLegalSection: ``LegalSectionData/showLegalSection``
Expand Down
14 changes: 7 additions & 7 deletions Sources/PackAPrefPane/Views/Help.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ public struct Help: View {
public var body: some View {
Section(header: Text(NSLocalizedString("🆘 Help", tableName: "Localizable", bundle: .module, value: "", comment: ""))) {
if helpSectionData.showFeedbackLink {
Feedback(helpSectionData: helpSectionData)
Feedback()
}
if helpSectionData.showSupportLink {
Support(helpSectionData: helpSectionData)
Support()
}
if helpSectionData.showWhatsNew {
WhatsNew(helpSectionData: helpSectionData)
WhatsNew()
}
if helpSectionData.showFAQ {
FAQ(faq: helpSectionData.faq)
}
}
}.environmentObject(helpSectionData)
}
}
// MARK: - Feedback
@available(macOS 11.0, iOS 14, *)
struct Feedback: View {
// Variables
let helpSectionData: HelpSectionData
@EnvironmentObject var helpSectionData: HelpSectionData
// UI
var body: some View {
Link(destination: PrefPaneHelper.appFeedbackURL(for: helpSectionData.appID)) {
Expand All @@ -50,7 +50,7 @@ struct Feedback: View {
@available(macOS 11.0, iOS 14, *)
struct Support: View {
// Variables
let helpSectionData: HelpSectionData
@EnvironmentObject var helpSectionData: HelpSectionData
// UI
var body: some View {
Link(destination: PrefPaneHelper.supportEmailURL(
Expand All @@ -72,7 +72,7 @@ struct Support: View {
struct WhatsNew: View {
// Variables
@State private var whatsNewExpanded: Bool = false
let helpSectionData: HelpSectionData
@EnvironmentObject var helpSectionData: HelpSectionData
let appVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String
// UI
var body: some View {
Expand Down
22 changes: 12 additions & 10 deletions Sources/PackAPrefPane/Views/Legal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,26 @@ public struct Legal: View {
if legalSectionData.showDisclaimer {
Disclaimer(
alertPresented: $alertPresented,
alert: $alert,
legalSectionData: legalSectionData
alert: $alert
)
}
if legalSectionData.showPrivacyPolicy {
PrivacyPolicy(
alertPresented: $alertPresented,
alert: $alert,
legalSectionData: legalSectionData
alert: $alert
)
}
if legalSectionData.showAcknowledgments {
Acknowledgments(alertPresented: $alertPresented, alert: $alert)
Acknowledgments(
alertPresented: $alertPresented,
alert: $alert
)
}
if legalSectionData.showTOS {
TermsOfService(legalSectionData: legalSectionData)
TermsOfService()
}
}.alert(isPresented: $alertPresented, content: { // alert switch cases
}.environmentObject(legalSectionData)
.alert(isPresented: $alertPresented, content: { // alert switch cases
switch alert {
case .disclaimerAlert:
return Alert(
Expand Down Expand Up @@ -86,7 +88,7 @@ struct Disclaimer: View {
// Variables
@Binding var alertPresented: Bool
@Binding var alert: Legal.alerts
let legalSectionData: LegalSectionData
@EnvironmentObject var legalSectionData: LegalSectionData
// UI
var body: some View {
Button(action: {
Expand Down Expand Up @@ -115,7 +117,7 @@ struct PrivacyPolicy: View {
// Variables
@Binding var alertPresented: Bool
@Binding var alert: Legal.alerts
let legalSectionData: LegalSectionData
@EnvironmentObject var legalSectionData: LegalSectionData
// UI
var body: some View {
Button(action: {
Expand Down Expand Up @@ -164,7 +166,7 @@ struct Acknowledgments: View {
struct TermsOfService: View {
// Variables
@State private var tosExpanded: Bool = false
let legalSectionData: LegalSectionData
@EnvironmentObject var legalSectionData: LegalSectionData
// UI
var body: some View {
DisclosureGroup(NSLocalizedString("Terms of Service", tableName: "Localizable", bundle: .module, value: "", comment: ""), isExpanded: $tosExpanded) {
Expand Down
4 changes: 4 additions & 0 deletions Sources/PackAPrefPane/Views/PackAPrefPane.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ public struct PackAPrefPane<Content: View>: View {
public var body: some View {
NavigationView {
Form {
// Your app settings section view
appSettingsView
// Optionnal Help section view
if prefPaneData.helpSectionData.showHelpSection {
Help(helpSectionData: prefPaneData.helpSectionData)
}
// Mandatory About section view
About(aboutSectionData: prefPaneData.aboutSectionData)
// Optionnal Legal section view
if prefPaneData.legalSectionData.showLegalSection {
Legal(legalSectionData: prefPaneData.legalSectionData)
}
Expand Down

0 comments on commit d3cf6ef

Please sign in to comment.