From e6f529e0fc76caf332bb6151ebf7f06b71e0e23c Mon Sep 17 00:00:00 2001 From: John Burwell Date: Fri, 29 May 2026 13:48:52 -0500 Subject: [PATCH] Extract root view dependencies and item actions --- .../Export/ContentItemActionService.swift | 19 +++++++++++++++ .../UI/Root/ContentView.swift | 21 ++++++++--------- .../UI/Root/ContentViewDependencies.swift | 23 +++++++++++++++++++ 3 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 World Manager for Minecraft/Services/AppSupport/Export/ContentItemActionService.swift create mode 100644 World Manager for Minecraft/UI/Root/ContentViewDependencies.swift diff --git a/World Manager for Minecraft/Services/AppSupport/Export/ContentItemActionService.swift b/World Manager for Minecraft/Services/AppSupport/Export/ContentItemActionService.swift new file mode 100644 index 0000000..8d2b84a --- /dev/null +++ b/World Manager for Minecraft/Services/AppSupport/Export/ContentItemActionService.swift @@ -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 + ) + } +} diff --git a/World Manager for Minecraft/UI/Root/ContentView.swift b/World Manager for Minecraft/UI/Root/ContentView.swift index d53b987..27cc98c 100644 --- a/World Manager for Minecraft/UI/Root/ContentView.swift +++ b/World Manager for Minecraft/UI/Root/ContentView.swift @@ -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 ) diff --git a/World Manager for Minecraft/UI/Root/ContentViewDependencies.swift b/World Manager for Minecraft/UI/Root/ContentViewDependencies.swift new file mode 100644 index 0000000..3bcfdd2 --- /dev/null +++ b/World Manager for Minecraft/UI/Root/ContentViewDependencies.swift @@ -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() + ) + } +}