Skip to content

Commit

Permalink
[Device] Remove StorageInfo from Flipper GATT model
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfreeman committed Jun 7, 2024
1 parent b947a0d commit efeebe3
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
6 changes: 0 additions & 6 deletions Flipper/Packages/Core/Sources/Flipper/Flipper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public struct Flipper: Equatable, Identifiable {
public var state: FlipperState = .disconnected
public var information: DeviceInformation?
public var battery: Battery?
public var storage: StorageInfo?

// swiftlint:disable discouraged_optional_boolean
public var hasProtobufVersion: Bool?
Expand All @@ -33,11 +32,6 @@ public struct Flipper: Equatable, Identifiable {
self.battery = battery
self.hasProtobufVersion = hasProtobufVersion
}

public struct StorageInfo: Equatable {
public var `internal`: StorageSpace?
public var external: StorageSpace?
}
}

fileprivate extension String {
Expand Down
12 changes: 9 additions & 3 deletions Flipper/Packages/Core/Sources/Model/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ public class Device: ObservableObject {
@Published public var isLocked = false

@Published public var flipper: Flipper?
@Published public var storageInfo: StorageInfo?
@Published public private(set) var frame: ScreenFrame?

@Published public private(set) var info: Info = .init()
@Published public private(set) var isInfoReady = false

public struct StorageInfo: Equatable {
public var `internal`: StorageSpace?
public var external: StorageSpace?
}

public init(
central: Central,
pairedDevice: PairedDevice,
Expand Down Expand Up @@ -201,9 +207,9 @@ public class Device: ObservableObject {
// MARK: API

private func loadStorageInfo() async throws {
var storageInfo = Flipper.StorageInfo()
var storageInfo = StorageInfo()
defer {
flipper?.storage = storageInfo
self.storageInfo = storageInfo
}
do {
storageInfo.internal = try await storage.space(of: "/int")
Expand Down Expand Up @@ -428,7 +434,7 @@ extension Device {
Task {
guard
let protobufRevision = flipper?.information?.protobufRevision,
let storage = flipper?.storage
let storage = storageInfo
else {
return
}
Expand Down
2 changes: 1 addition & 1 deletion Flipper/Packages/Core/Sources/Model/UpdateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public class UpdateModel: ObservableObject {
var provisionedRegion: LazyResult<ISOCode, Swift.Error> = .idle

var hasSDCard: LazyResult<Bool, Swift.Error> {
guard let storage = flipper?.storage else { return .working }
guard let storage = device.storageInfo else { return .working }
return .success(storage.external != nil)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ extension FlipperPeripheral: CBPeripheralDelegate {
if let batteryPowerState = characteristics.batteryPowerState {
peripheral.setNotifyValue(true, for: batteryPowerState)
peripheral.readValue(for: batteryPowerState)
return
}
}

Expand Down
4 changes: 2 additions & 2 deletions Flipper/Packages/UI/Sources/Device/Info/DeviceInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ struct DeviceInfoView: View {
private func share() {
var array = info.keys.toArray().sorted()

if let int = device.flipper?.storage?.internal {
if let int = device.storageInfo?.internal {
array.append("storage.int.available: \(int.free)")
array.append("storage.int.total: \(int.total)")
}
if let ext = device.flipper?.storage?.external {
if let ext = device.storageInfo?.external {
array.append("storage.ext.available: \(ext.free)")
array.append("storage.ext.total: \(ext.total)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct DeviceInfoCard: View {
}

var internalSpace: AttributedString? {
guard isConnected, let int = device.flipper?.storage?.internal else {
guard isConnected, let int = device.storageInfo?.internal else {
return nil
}
var result = AttributedString(int.description)
Expand All @@ -79,10 +79,10 @@ struct DeviceInfoCard: View {
}

var externalSpace: AttributedString? {
guard isConnected, device.flipper?.storage?.internal != nil else {
guard isConnected, device.storageInfo?.internal != nil else {
return nil
}
guard let ext = device.flipper?.storage?.external else {
guard let ext = device.storageInfo?.external else {
return ""
}
var result = AttributedString(ext.description)
Expand Down

0 comments on commit efeebe3

Please sign in to comment.