Extract root view dependencies and item actions

This commit is contained in:
John Burwell 2026-05-29 13:48:52 -05:00
parent ae25c7530b
commit e6f529e0fc
3 changed files with 51 additions and 12 deletions

View File

@ -0,0 +1,19 @@
import Foundation
struct ContentItemActionService: Sendable {
nonisolated func suggestedFilename(for item: MinecraftContentItem) -> String {
ContentPackageExporter.suggestedBaseFilename(for: item)
}
nonisolated func createArchiveFile(
for item: MinecraftContentItem,
source: MinecraftSource?,
destinationURL: URL? = nil
) async throws -> URL {
try await ContentPackageExporter.createArchiveFile(
for: item,
source: source,
destinationURL: destinationURL
)
}
}

View File

@ -23,19 +23,16 @@ struct ContentView: View {
private let connectedDeviceAccess: AppleMobileDeviceSourceAccess
private let deviceSourceFactory: ConnectedDeviceSourceFactory
private let itemActionService: ContentItemActionService
private let directoryPreviewLimit = 12
init() {
let connectedDeviceAccess = AppleMobileDeviceSourceAccess()
self.connectedDeviceAccess = connectedDeviceAccess
self.deviceSourceFactory = ConnectedDeviceSourceFactory()
let dependencies = ContentViewDependencies.makeDefault()
self.connectedDeviceAccess = dependencies.connectedDeviceAccess
self.deviceSourceFactory = dependencies.deviceSourceFactory
self.itemActionService = dependencies.itemActionService
_library = StateObject(
wrappedValue: SourceLibrary(
sourceAccessMethod: SourceAccessCoordinator(
connectedDeviceAccess: connectedDeviceAccess
),
connectedDeviceAccessMethod: connectedDeviceAccess
)
wrappedValue: dependencies.library
)
}
@ -671,7 +668,7 @@ struct ContentView: View {
panel.showsTagField = false
panel.title = exportMenuTitle(for: item)
panel.prompt = "Save"
panel.nameFieldStringValue = ContentPackageExporter.suggestedBaseFilename(for: item)
panel.nameFieldStringValue = itemActionService.suggestedFilename(for: item)
panel.allowedContentTypes = [archiveType(for: item)]
guard panel.runModal() == .OK, let destinationURL = panel.url else {
@ -683,7 +680,7 @@ struct ContentView: View {
Task {
do {
let finalURL = try await Task.detached(priority: .userInitiated) {
try await ContentPackageExporter.createArchiveFile(
try await itemActionService.createArchiveFile(
for: item,
source: source,
destinationURL: destinationURL
@ -713,7 +710,7 @@ struct ContentView: View {
Task {
do {
let shareURL = try await Task.detached(priority: .userInitiated) {
try await ContentPackageExporter.createArchiveFile(
try await itemActionService.createArchiveFile(
for: item,
source: source
)

View File

@ -0,0 +1,23 @@
import Foundation
struct ContentViewDependencies {
let library: SourceLibrary
let connectedDeviceAccess: AppleMobileDeviceSourceAccess
let deviceSourceFactory: ConnectedDeviceSourceFactory
let itemActionService: ContentItemActionService
static func makeDefault() -> ContentViewDependencies {
let connectedDeviceAccess = AppleMobileDeviceSourceAccess()
return ContentViewDependencies(
library: SourceLibrary(
sourceAccessMethod: SourceAccessCoordinator(
connectedDeviceAccess: connectedDeviceAccess
),
connectedDeviceAccessMethod: connectedDeviceAccess
),
connectedDeviceAccess: connectedDeviceAccess,
deviceSourceFactory: ConnectedDeviceSourceFactory(),
itemActionService: ContentItemActionService()
)
}
}