mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 16:24:11 +00:00
49457f7ae8
* Add a multi-account feature flag The flag lives in Developer options. Switching it on arms the upcoming one-time multi-account announcement, whose seen state defaults to true so fresh installs never see it. * Add an Add account row to Settings behind the multi-account flag The row sits in its own section under the user status, as in the designs. Tapping it is routed up to the settings flow, which ignores it until the add account flow exists. * Remove the Developer options view model tests The Developer options screen is excluded from coverage, so these tests don't add value. * Apply review suggestions to the multi-account flag - Order the multi-account requirements in DeveloperOptionsProtocol to match the screen's sections. - Drop the redundant "Experimental" from the toggle's subtitle.
74 lines
3.2 KiB
Swift
74 lines
3.2 KiB
Swift
//
|
|
// Copyright 2025 Element Creations Ltd.
|
|
// Copyright 2022-2025 New Vector Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
// Please see LICENSE files in the repository root for full details.
|
|
//
|
|
|
|
import Combine
|
|
import SwiftUI
|
|
|
|
typealias DeveloperOptionsScreenViewModelType = StateStoreViewModelV2<DeveloperOptionsScreenViewState, DeveloperOptionsScreenViewAction>
|
|
|
|
class DeveloperOptionsScreenViewModel: DeveloperOptionsScreenViewModelType, DeveloperOptionsScreenViewModelProtocol {
|
|
private var actionsSubject: PassthroughSubject<DeveloperOptionsScreenViewModelAction, Never> = .init()
|
|
|
|
var actions: AnyPublisher<DeveloperOptionsScreenViewModelAction, Never> {
|
|
actionsSubject.eraseToAnyPublisher()
|
|
}
|
|
|
|
private let clientProxy: ClientProxyProtocol?
|
|
|
|
init(developerOptions: DeveloperOptionsProtocol, appHooks: AppHooks, clientProxy: ClientProxyProtocol?) {
|
|
self.clientProxy = clientProxy
|
|
super.init(initialViewState: .init(appHooks: appHooks,
|
|
shouldShowClearCache: clientProxy != nil,
|
|
isSignedIn: clientProxy != nil,
|
|
bindings: .init(developerOptions: developerOptions)))
|
|
|
|
developerOptions.multiAccountEnabledPublisher
|
|
.removeDuplicates()
|
|
.dropFirst() // The publisher replays the current value, so only an actual toggle arms the announcement.
|
|
.filter { $0 }
|
|
.sink { _ in developerOptions.hasSeenMultiAccountAnnouncement = false }
|
|
.store(in: &cancellables)
|
|
|
|
Task {
|
|
if case let .success(sizes) = await clientProxy?.storeSizes() {
|
|
let formatter = ByteCountFormatStyle(style: .file)
|
|
|
|
var components = [DeveloperOptionsScreenViewState.StoreSize]()
|
|
if let cryptoStore = sizes.cryptoStore {
|
|
components.append(.init(name: "CryptoStore", size: formatter.format(Int64(cryptoStore))))
|
|
}
|
|
if let stateStore = sizes.stateStore {
|
|
components.append(.init(name: "StateStore", size: formatter.format(Int64(stateStore))))
|
|
}
|
|
if let eventCacheStore = sizes.eventCacheStore {
|
|
components.append(.init(name: "EventCacheStore", size: formatter.format(Int64(eventCacheStore))))
|
|
}
|
|
if let mediaStore = sizes.mediaStore {
|
|
components.append(.init(name: "MediaStore", size: formatter.format(Int64(mediaStore))))
|
|
}
|
|
if let logsSize = try? FileManager.default.sizeForDirectory(at: .appGroupLogsDirectory) {
|
|
components.append(.init(name: "Log Files", size: formatter.format(Int64(logsSize))))
|
|
}
|
|
|
|
state.storeSizes = components
|
|
}
|
|
}
|
|
}
|
|
|
|
override func process(viewAction: DeveloperOptionsScreenViewAction) {
|
|
switch viewAction {
|
|
case .clearCache:
|
|
actionsSubject.send(.clearCache)
|
|
case .markAllRoomsAsRead:
|
|
Task {
|
|
await self.clientProxy?.markAllRoomsAsRead()
|
|
}
|
|
}
|
|
}
|
|
}
|