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:
50
apple/VniDrop/Platform/AppDependencies+macOS.swift
Normal file
50
apple/VniDrop/Platform/AppDependencies+macOS.swift
Normal file
@@ -0,0 +1,50 @@
|
||||
#if os(macOS)
|
||||
import Foundation
|
||||
import AppKit
|
||||
|
||||
/// Builds the macOS dependency graph, mirroring `rememberIosAppDependencies`.
|
||||
@MainActor
|
||||
func makeAppDependencies(externalInvitations: ExternalInvitationController) -> AppDependencies {
|
||||
let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "0.1.0"
|
||||
let host = Host.current().localizedName ?? "Mac"
|
||||
let env = PlatformEnvironment(
|
||||
name: "macOS " + ProcessInfo.processInfo.operatingSystemVersionString,
|
||||
appVersion: version,
|
||||
defaultCoreDataDir: applicationDataDirectory(),
|
||||
defaultUsername: host
|
||||
)
|
||||
return AppDependencies(
|
||||
environment: env,
|
||||
deviceInfoProvider: MacDeviceInfoProvider(),
|
||||
fileSystemService: MacFileSystemService(),
|
||||
notificationService: LocalNotificationService(),
|
||||
externalInvitations: externalInvitations
|
||||
)
|
||||
}
|
||||
|
||||
private func applicationDataDirectory() -> String {
|
||||
let base = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
|
||||
return base.appendingPathComponent("VniDrop").path
|
||||
}
|
||||
|
||||
private struct MacDeviceInfoProvider: DeviceInfoProvider {
|
||||
func load() async -> DeviceInfo {
|
||||
DeviceInfo(
|
||||
deviceName: Host.current().localizedName,
|
||||
deviceModel: modelIdentifier(),
|
||||
operatingSystem: "macOS " + ProcessInfo.processInfo.operatingSystemVersionString,
|
||||
network: nil,
|
||||
batteryLevel: nil
|
||||
)
|
||||
}
|
||||
|
||||
private func modelIdentifier() -> String? {
|
||||
var size = 0
|
||||
sysctlbyname("hw.model", nil, &size, nil, 0)
|
||||
guard size > 0 else { return nil }
|
||||
var model = [CChar](repeating: 0, count: size)
|
||||
sysctlbyname("hw.model", &model, &size, nil, 0)
|
||||
return String(cString: model)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user