Skip to content

Commit

Permalink
Updated inline with MR feedback
Browse files Browse the repository at this point in the history
* Replaced device name with model identifier. This provides enough information (e.g. iPhone14,5) to be able to easily cross reference somewhere like https://www.theiphonewiki.com and find the exact device model information. This of course proves useful when wanting to know device characteristics which may relate to an issue.
* Removed Mac support. There are several existing compilation issues on Mac already.
* Corrected spacing to align with project norms (spaces not tabs)
  • Loading branch information
lawmaestro committed Jan 23, 2024
1 parent 229e0ca commit 30d1cb7
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 107 deletions.
3 changes: 1 addition & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ let package = Package(
name: "FeedbacksKit",
defaultLocalization: "en",
platforms: [
.iOS(.v14),
.macOS(.v13),
.iOS(.v14)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
Expand Down
20 changes: 10 additions & 10 deletions Sources/FeedbacksKit/FeedbackForm/FeedbackForm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ public struct FeedbackForm: View {

public struct Config {
let title: String
let textForegroundColor: Color
let textForegroundColor: Color

public init(
title: String? = nil,
textForegroundColor: Color? = nil
) {
self.title = title ?? "_send_a_feedback".localized
self.textForegroundColor = textForegroundColor ?? .blue
title: String? = nil,
textForegroundColor: Color? = nil
) {
self.title = title ?? "_send_a_feedback".localized
self.textForegroundColor = textForegroundColor ?? .blue
}
}

Expand Down Expand Up @@ -40,8 +40,8 @@ public struct FeedbackForm: View {
Button {
presentationMode.wrappedValue.dismiss()
} label: {
Text("_cancel".localized)
.foregroundColor(config.textForegroundColor)
Text("_cancel".localized)
.foregroundColor(config.textForegroundColor)
}
}
}
Expand All @@ -57,7 +57,7 @@ public struct FeedbackForm: View {
TextField("_email_placeholder".localized, text: $viewModel.email)
.keyboardType(.emailAddress)
.autocapitalization(.none)
.autocorrectionDisabled()
.autocorrectionDisabled()
} header: {
Text("_email_title".localized)
}
Expand All @@ -82,7 +82,7 @@ public struct FeedbackForm: View {
.frame(maxWidth: .infinity)
} else {
Text("_send_feedback".localized)
.foregroundColor(viewModel.isSubmitDisabled ? .gray : config.textForegroundColor)
.foregroundColor(viewModel.isSubmitDisabled ? .gray : config.textForegroundColor)
.frame(maxWidth: .infinity)
}
}
Expand Down
16 changes: 8 additions & 8 deletions Sources/FeedbacksKit/Model/FeedbackFormData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ public struct FeedbackFormData {
let email: String
let message: String

let deviceName: String
let systemNameAndVersion: String
let appVersion: String
let language: String
let deviceModelIdentifier: String
let systemNameAndVersion: String
let appVersion: String
let language: String

public init(
email: String,
Expand All @@ -16,9 +16,9 @@ public struct FeedbackFormData {
self.email = email
self.message = message

deviceName = UIDevice.current.name
systemNameAndVersion = "\(UIDevice.current.systemName) \(UIDevice.current.systemVersion)"
appVersion = "\(Bundle.main.appVersionLong) (\(Bundle.main.appBuild))"
language = Locale.current.localizedString(forIdentifier: Locale.current.identifier) ?? Locale.current.identifier
deviceModelIdentifier = UIDevice.modelIdentifier
systemNameAndVersion = "\(UIDevice.current.systemName) \(UIDevice.current.systemVersion)"
appVersion = "\(Bundle.main.appVersionLong) (\(Bundle.main.appBuild))"
language = Locale.current.localizedString(forIdentifier: Locale.current.identifier) ?? Locale.current.identifier
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,75 +74,75 @@ public struct NotionSubmitService: SubmitService {
]
)
),
.init(type: "divider", divider: .init()),
.init(
object: "block",
type: "paragraph",
paragraph: .init(
richText: [
.init(
type: "text",
text: .init(content: "App version: "),
annotations: .init(bold: true)
),
.init(
type: "text",
text: .init(content: formData.appVersion)
)
]
)
),
.init(
object: "block",
type: "paragraph",
paragraph: .init(
richText: [
.init(
type: "text",
text: .init(content: "Device name: "),
annotations: .init(bold: true)
),
.init(
type: "text",
text: .init(content: formData.deviceName)
)
]
)
),
.init(
object: "block",
type: "paragraph",
paragraph: .init(
richText: [
.init(
type: "text",
text: .init(content: "System: "),
annotations: .init(bold: true)
),
.init(
type: "text",
text: .init(content: formData.systemNameAndVersion)
)
]
)
),
.init(
object: "block",
type: "paragraph",
paragraph: .init(
richText: [
.init(
type: "text",
text: .init(content: "System Locale: "),
annotations: .init(bold: true)
),
.init(
type: "text",
text: .init(content: formData.language)
)
]
)
)
.init(type: "divider", divider: .init()),
.init(
object: "block",
type: "paragraph",
paragraph: .init(
richText: [
.init(
type: "text",
text: .init(content: "App version: "),
annotations: .init(bold: true)
),
.init(
type: "text",
text: .init(content: formData.appVersion)
)
]
)
),
.init(
object: "block",
type: "paragraph",
paragraph: .init(
richText: [
.init(
type: "text",
text: .init(content: "Device model identifier: "),
annotations: .init(bold: true)
),
.init(
type: "text",
text: .init(content: formData.deviceModelIdentifier)
)
]
)
),
.init(
object: "block",
type: "paragraph",
paragraph: .init(
richText: [
.init(
type: "text",
text: .init(content: "System: "),
annotations: .init(bold: true)
),
.init(
type: "text",
text: .init(content: formData.systemNameAndVersion)
)
]
)
),
.init(
object: "block",
type: "paragraph",
paragraph: .init(
richText: [
.init(
type: "text",
text: .init(content: "System Locale: "),
annotations: .init(bold: true)
),
.init(
type: "text",
text: .init(content: formData.language)
)
]
)
)
]
)
}
Expand Down Expand Up @@ -185,25 +185,25 @@ private struct NotionBody: Codable {
var object: String?
let type: String
var paragraph: Paragraph?
var divider: Divider?

struct Divider: Codable {}
var divider: Divider?
struct Divider: Codable {}

struct Paragraph: Codable {
let richText: [RichText]

struct RichText: Codable {
let type: String
let text: Text
struct Annotations: Codable {
var bold = false
var italic = false
var strikethrough = false
var underline = false
var code = false
var color = "default"
}
var annotations: Annotations?
struct Annotations: Codable {
var bold = false
var italic = false
var strikethrough = false
var underline = false
var code = false
var color = "default"
}
var annotations: Annotations?

struct Text: Codable {
let content: String
Expand Down
12 changes: 6 additions & 6 deletions Sources/FeedbacksKit/Utils/Bundle+VersionInfo.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Foundation

extension Bundle {
var appBuild: String { getInfo("CFBundleVersion") }
var appVersionLong: String { getInfo("CFBundleShortVersionString") }
var appVersionShort: String { getInfo("CFBundleShortVersion") }
var appBuild: String { getInfo("CFBundleVersion") }
var appVersionLong: String { getInfo("CFBundleShortVersionString") }
var appVersionShort: String { getInfo("CFBundleShortVersion") }

private func getInfo(_ string: String) -> String {
infoDictionary?[string] as? String ?? "⚠️"
}
private func getInfo(_ string: String) -> String {
infoDictionary?[string] as? String ?? "⚠️"
}
}
22 changes: 22 additions & 0 deletions Sources/FeedbacksKit/Utils/UIDevice+ModelInfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import UIKit

extension UIDevice {

/// The device model identifier e.g. "iPhone14,5" (iPhone 13) or "Simulator"
static var modelIdentifier: String {
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.machine)
let identifier = machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}

switch identifier {
case "i386", "x86_64":
return "Simulator"
default:
return identifier
}
}
}
4 changes: 4 additions & 0 deletions Sources/FeedbacksKit/Utils/View+hideKeyboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ extension View {
}
}
#endif




0 comments on commit 30d1cb7

Please sign in to comment.