39 lines
1.0 KiB
Swift
39 lines
1.0 KiB
Swift
import Foundation
|
|
import Library
|
|
|
|
@MainActor
|
|
public struct ButtonVisibilityState {
|
|
public var showGroupsButton = false
|
|
public var showConnectionsButton = false
|
|
public var groupsCount = 0
|
|
public var connectionsCount = 0
|
|
|
|
public init() {}
|
|
|
|
public mutating func update(
|
|
profile: ExtensionProfile?,
|
|
commandClient: CommandClient,
|
|
requireAnyConnection: Bool = false
|
|
) {
|
|
guard let profile else {
|
|
reset()
|
|
return
|
|
}
|
|
|
|
groupsCount = commandClient.groups?.count ?? 0
|
|
connectionsCount = commandClient.connections?.count ?? 0
|
|
|
|
let isConnected = ApplicationLibrary.inPreview || profile.status.isConnectedStrict
|
|
|
|
showConnectionsButton = isConnected && (!requireAnyConnection || commandClient.hasAnyConnection)
|
|
showGroupsButton = isConnected && (commandClient.groups?.isEmpty == false)
|
|
}
|
|
|
|
private mutating func reset() {
|
|
showGroupsButton = false
|
|
showConnectionsButton = false
|
|
groupsCount = 0
|
|
connectionsCount = 0
|
|
}
|
|
}
|