mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 10:29:58 +02:00
feat(apple): native SwiftUI app for iOS and macOS
Add a native SwiftUI VniDrop app (Send/Receive/Settings) talking to the Rust core via generated UniFFI Swift bindings, plus the uniffi-bindgen helper crate. iOS uses a TabView, macOS a NavigationSplitView sidebar.
This commit is contained in:
44
apple/VniDrop/Features/App/AppModel.swift
Normal file
44
apple/VniDrop/Features/App/AppModel.swift
Normal file
@@ -0,0 +1,44 @@
|
||||
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: CoreRepository
|
||||
private let messages: UiMessageController
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
init(
|
||||
environment: PlatformEnvironment,
|
||||
repository: CoreRepository,
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user