Skip to content

Commit

Permalink
[CI] Fix Xcode Warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Programistich committed Sep 23, 2024
1 parent ba57438 commit 81d6c96
Show file tree
Hide file tree
Showing 23 changed files with 103 additions and 58 deletions.
12 changes: 8 additions & 4 deletions Flipper/LiveWidget/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ struct ConfigurationAppIntent: WidgetConfigurationIntent {
case emulatable
}

@Parameter(title: "Archive Key", default: .none)
var entity: KeyEntity
@Parameter(title: "Archive Key")
private var _entity: KeyEntity?

var entity: KeyEntity {
_entity ?? KeyEntity.invalid
}

init() {
self.entity = .invalid
self._entity = .invalid
}

init(entity: KeyEntity) {
self.entity = entity
self._entity = entity
}

var kind: Kind {
Expand Down
10 changes: 6 additions & 4 deletions Flipper/LiveWidget/LiveWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ struct LiveWidget: Widget {

extension ConfigurationAppIntent {
fileprivate static var cyfral: ConfigurationAppIntent {
let intent = ConfigurationAppIntent()
intent.entity = .init(id: "", name: "Cyfral", kind: .ibutton)
let intent = ConfigurationAppIntent(
entity: .init(id: "", name: "Cyfral", kind: .ibutton)
)
return intent
}

fileprivate static var garage: ConfigurationAppIntent {
let intent = ConfigurationAppIntent()
intent.entity = .init(id: "", name: "Garage", kind: .subghz)
let intent = ConfigurationAppIntent(
entity: .init(id: "", name: "Garage", kind: .subghz)
)
return intent
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ public class WebCatalog: CatalogService {
throw URLError(.badServerResponse)
}
guard statusCode == 200 else {
let response = String(data: data, encoding: .utf8) ?? "unknown"

logger.error("report issue: invalid status code - \(statusCode)")
logger.debug("response: \(String(decoding: data, as: UTF8.self))")
logger.debug("response: \(response)")
return
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ actor FlipperApps {

private func remoteManifest(_ path: Path) async throws -> Manifest {
let data = try await storage.read(at: path).drain()
try await cache.upsert(String(decoding: data, as: UTF8.self), at: path)
try await cache.upsert(data.utf8String, at: path)
let manifest = try FFFDecoder.decode(Manifest.self, from: data)
return manifest
}
Expand Down
3 changes: 1 addition & 2 deletions Flipper/Packages/Core/Sources/Archive/Archive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ extension Archive {
}
if let path = item.layoutPath {
if let layout = item.layout {
let content = String(decoding: layout, as: UTF8.self)
try await mobileArchive.upsert(content, at: path)
try await mobileArchive.upsert(layout.utf8String, at: path)
} else {
try await mobileArchive.delete(path)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class FlipperFavorites: FavoritesStorage {
func read() async throws -> Favorites {
do {
let bytes = try await storage.read(at: path).drain()
let content = String(decoding: bytes, as: UTF8.self)
return try .init(decoding: content)
return try .init(decoding: bytes.utf8String)
} catch let error as Peripheral.Error {
if error == .storage(.doesNotExist) {
return .init([])
Expand Down
3 changes: 1 addition & 2 deletions Flipper/Packages/Core/Sources/Archive/Item/ArchiveItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ extension ArchiveItem {
}

init(filename: String, data: Data) throws {
let content = String(decoding: data, as: UTF8.self)
try self.init(filename: filename, content: content)
try self.init(filename: filename, content: data.utf8String)
}

init(path: Path, content: String) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ public extension InfraredLayout {
encoder.outputFormatting = .sortedKeys // Save order

guard
let layout = try? encoder.encode(self)
let layout = try? encoder.encode(self),
let content = String(data: layout, encoding: .utf8)
else { return nil }

return String(decoding: layout, as: UTF8.self)
return content
.replacingOccurrences(of: "\n", with: "")
.replacingOccurrences(of: "\t", with: "")
.replacingOccurrences(of: "\r", with: "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class MFKnownKeys {

private func readKeys(at path: Path) async throws -> Set<MFKey64> {
let bytes = try await storage.read(at: path).drain()
let array = String(decoding: bytes, as: UTF8.self)
let array = try bytes.utf8String
.split { $0 == "\n" || $0 == "\r\n" }
.compactMap { line in
MFKey64(hexValue: line)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class Tranfser {
guard (response as? HTTPURLResponse)?.statusCode == 200 else {
throw URLError(.badServerResponse)
}
let responseContent = String(decoding: data, as: UTF8.self)
return code(from: responseContent)
return code(from: try data.utf8String)
}

func download(code: String) async throws -> [UInt8] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ extension FileStorage {

func write<T: Codable>(_ value: T, at path: Path) throws {
let data = try JSONEncoder().encode(value)
try write(String(decoding: data, as: UTF8.self), at: path)
try write(try data.utf8String, at: path)
}
}
11 changes: 5 additions & 6 deletions Flipper/Packages/Core/Sources/Utils/AppStorage+Set.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ extension Set: @retroactive RawRepresentable where Element: Codable {
}

public var rawValue: String {
do {
let data = try JSONEncoder().encode(self)
return String(decoding: data, as: UTF8.self)
} catch {
return "[]"
}
guard
let data = try? JSONEncoder().encode(self),
let content = String(data: data, encoding: .utf8)
else { return "[]" }
return content
}
}
14 changes: 14 additions & 0 deletions Flipper/Packages/Core/Sources/Utils/IdentifiableError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation

public struct IdentifiableError: Identifiable {
public let id = UUID()
let error: Error

public init(from error: Error) {
self.error = error
}

public var description: String {
String(describing: error)
}
}
4 changes: 3 additions & 1 deletion Flipper/Packages/Core/Sources/Utils/URLSessionData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class URLSessionData {

private func makeRequest() async throws -> Data {
try await withCheckedThrowingContinuation { continuation in
makeRequest(continuation.resume)
makeRequest { result in
continuation.resume(with: result)
}
}
}

Expand Down
27 changes: 27 additions & 0 deletions Flipper/Packages/Core/Sources/Utils/UTF8+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Foundation

enum DataConversionError: Error {
case invalidUtf8
}

extension Data {
var utf8String: String {
get throws {
guard let string = String(data: self, encoding: .utf8) else {
throw DataConversionError.invalidUtf8
}
return string
}
}
}

extension Sequence where Element == UInt8 {
var utf8String: String {
get throws {
guard let string = String(bytes: self, encoding: .utf8) else {
throw DataConversionError.invalidUtf8
}
return string
}
}
}
9 changes: 6 additions & 3 deletions Flipper/Packages/Notifications/Sources/Notifications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,19 @@ extension Notifications: UNUserNotificationCenterDelegate {
}

extension Notifications: MessagingDelegate {
public func messaging(
public nonisolated func messaging(
_ messaging: Messaging,
didReceiveRegistrationToken fcmToken: String?
) {
#if DEBUG
print("Firebase registration token: \(String(describing: fcmToken))")
#endif

if messaging.apnsToken != nil, fcmToken != nil {
messaging.subscribe(toTopic: firmwareReleaseTopic)
Task { @MainActor in
// Safely update UI or access main actor properties here
if messaging.apnsToken != nil, fcmToken != nil {
messaging.subscribe(toTopic: firmwareReleaseTopic)
}
}

// TODO: If necessary send token to application server.
Expand Down
11 changes: 3 additions & 8 deletions Flipper/Packages/UI/Sources/Archive/Import/ImportView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct ImportView: View {
@State private var backup: ArchiveItem = .none

@State private var isEditing = false
@State private var error: String?
@State private var error: IdentifiableError?

enum ImportState: Equatable {
case loading
Expand Down Expand Up @@ -127,7 +127,7 @@ struct ImportView: View {
}
}
.alert(item: $error) { error in
Alert(title: Text(error))
Alert(title: Text(error.description))
}
.background(Color.background)
.edgesIgnoringSafeArea(.bottom)
Expand Down Expand Up @@ -190,7 +190,7 @@ struct ImportView: View {
}

func showError(_ error: Swift.Error) {
self.error = String(describing: error)
self.error = IdentifiableError(from: error)
}
}

Expand All @@ -203,8 +203,3 @@ extension ArchiveItem {
shadowCopy: [])
}
}

// FIXME: Use Identifiable Error
extension String: Identifiable {
public var id: Self { self }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct DeletedInfoView: View {
let item: ArchiveItem
@State private var showDeleteSheet = false
@State private var isEditing = false
@State private var error: String?
@State private var error: IdentifiableError?

var body: some View {
ScrollView {
Expand Down Expand Up @@ -60,7 +60,7 @@ struct DeletedInfoView: View {
}
}
.alert(item: $error) { error in
Alert(title: Text(error))
Alert(title: Text(error.description))
}
.background(Color.background)
.edgesIgnoringSafeArea(.bottom)
Expand Down Expand Up @@ -89,7 +89,7 @@ struct DeletedInfoView: View {
}

func showError(_ error: Swift.Error) {
self.error = String(describing: error)
self.error = IdentifiableError(from: error)
}
}

Expand Down
6 changes: 3 additions & 3 deletions Flipper/Packages/UI/Sources/Archive/Info/InfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct InfoView: View {
@State private var showDumpEditor = false
@State private var isEditing = false

@State private var error: String?
@State private var error: IdentifiableError?

// Don`t forget to change logic in InfraredMenu too
private var isEditable: Bool {
Expand Down Expand Up @@ -80,7 +80,7 @@ struct InfoView: View {
NFCEditorView(item: $current)
}
.alert(item: $error) { error in
Alert(title: Text(error))
Alert(title: Text(error.description))
}
.background(Color.background)
.edgesIgnoringSafeArea(.bottom)
Expand Down Expand Up @@ -158,7 +158,7 @@ struct InfoView: View {
}

func showError(_ error: Swift.Error) {
self.error = String(describing: error)
self.error = IdentifiableError(from: error)
}

func shareKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct InfraredEditorView: View {

@State private var remotes: [ArchiveItem.InfraredSignal] = []
@State private var showSaveChanges = false
@State private var error: String?
@State private var error: IdentifiableError?

private var canSave: Bool {
remotes.allSatisfy { !$0.name.isEmpty }
Expand Down Expand Up @@ -41,7 +41,7 @@ struct InfraredEditorView: View {
.scrollContentBackground(.hidden)
}
.alert(item: $error) { error in
Alert(title: Text(error))
Alert(title: Text(error.description))
}
.alert(isPresented: $showSaveChanges) {
SaveChangesAlert(
Expand Down Expand Up @@ -80,7 +80,7 @@ struct InfraredEditorView: View {
}

private func showError(_ error: Swift.Error) {
self.error = String(describing: error)
self.error = IdentifiableError(from: error)
}

private func dontSave() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct NFCEditorView: View {
@State private var bytes: [UInt8?] = []
@State private var showSaveAs = false
@State private var showSaveChanges = false
@State private var error: String?
@State private var error: IdentifiableError?

var body: some View {
NavigationStack {
Expand Down Expand Up @@ -90,7 +90,7 @@ struct NFCEditorView: View {
.environmentObject(hexKeyboardController)
}
.alert(item: $error) { error in
Alert(title: Text(error))
Alert(title: Text(error.description))
}
.task {
load()
Expand Down Expand Up @@ -190,7 +190,7 @@ struct NFCEditorView: View {
}

func showError(_ error: Swift.Error) {
self.error = String(describing: error)
self.error = IdentifiableError(from: error)
}
}

Expand Down
Loading

0 comments on commit 81d6c96

Please sign in to comment.