mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 10:29:58 +02:00
- Introduce a CoreGateway protocol so feature models depend on a seam (CoreRepository conforms); enables faking the core in tests - Add a VniDropTests target with 42 tests mirroring the KMP suites: approval coordinator, send/receive/settings/app models, preferences, file previews, invitation decode, message queue, error mapping - Add a fake gateway/file-system/device-info and fixtures - Add .github/workflows/apple.yml: build the Rust core, generate the project, and run the tests on an iOS Simulator
45 lines
1.3 KiB
Swift
45 lines
1.3 KiB
Swift
import Foundation
|
|
import Combine
|
|
|
|
/// Top-level app state, ported from `feature/app/AppViewModel.kt`. Initializes the
|
|
/// core on launch and tracks the selected destination + theme.
|
|
@MainActor
|
|
final class AppModel: ObservableObject {
|
|
@Published private(set) var destination: AppDestination = .send
|
|
@Published private(set) var themeMode: ThemeMode = .system
|
|
|
|
private let environment: PlatformEnvironment
|
|
private let repository: CoreGateway
|
|
private let messages: UiMessageController
|
|
private var cancellables = Set<AnyCancellable>()
|
|
|
|
init(
|
|
environment: PlatformEnvironment,
|
|
repository: CoreGateway,
|
|
preferences: AppPreferencesRepository,
|
|
messages: UiMessageController
|
|
) {
|
|
self.environment = environment
|
|
self.repository = repository
|
|
self.messages = messages
|
|
|
|
AppLogger.info("lifecycle", "app started", ["platform": environment.name])
|
|
|
|
Task {
|
|
let result = await repository.initialize(appDataDir: environment.defaultCoreDataDir)
|
|
if case .failure(let error) = result { messages.error(error) }
|
|
}
|
|
|
|
preferences.$preferences
|
|
.map(\.themeMode)
|
|
.removeDuplicates()
|
|
.sink { [weak self] mode in self?.themeMode = mode }
|
|
.store(in: &cancellables)
|
|
}
|
|
|
|
func selectDestination(_ destination: AppDestination) {
|
|
guard destination != self.destination else { return }
|
|
self.destination = destination
|
|
}
|
|
}
|