Extract root view dependencies and item actions
This commit is contained in:
parent
ae25c7530b
commit
e6f529e0fc
@ -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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -23,19 +23,16 @@ struct ContentView: View {
|
|||||||
|
|
||||||
private let connectedDeviceAccess: AppleMobileDeviceSourceAccess
|
private let connectedDeviceAccess: AppleMobileDeviceSourceAccess
|
||||||
private let deviceSourceFactory: ConnectedDeviceSourceFactory
|
private let deviceSourceFactory: ConnectedDeviceSourceFactory
|
||||||
|
private let itemActionService: ContentItemActionService
|
||||||
private let directoryPreviewLimit = 12
|
private let directoryPreviewLimit = 12
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
let connectedDeviceAccess = AppleMobileDeviceSourceAccess()
|
let dependencies = ContentViewDependencies.makeDefault()
|
||||||
self.connectedDeviceAccess = connectedDeviceAccess
|
self.connectedDeviceAccess = dependencies.connectedDeviceAccess
|
||||||
self.deviceSourceFactory = ConnectedDeviceSourceFactory()
|
self.deviceSourceFactory = dependencies.deviceSourceFactory
|
||||||
|
self.itemActionService = dependencies.itemActionService
|
||||||
_library = StateObject(
|
_library = StateObject(
|
||||||
wrappedValue: SourceLibrary(
|
wrappedValue: dependencies.library
|
||||||
sourceAccessMethod: SourceAccessCoordinator(
|
|
||||||
connectedDeviceAccess: connectedDeviceAccess
|
|
||||||
),
|
|
||||||
connectedDeviceAccessMethod: connectedDeviceAccess
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -671,7 +668,7 @@ struct ContentView: View {
|
|||||||
panel.showsTagField = false
|
panel.showsTagField = false
|
||||||
panel.title = exportMenuTitle(for: item)
|
panel.title = exportMenuTitle(for: item)
|
||||||
panel.prompt = "Save"
|
panel.prompt = "Save"
|
||||||
panel.nameFieldStringValue = ContentPackageExporter.suggestedBaseFilename(for: item)
|
panel.nameFieldStringValue = itemActionService.suggestedFilename(for: item)
|
||||||
panel.allowedContentTypes = [archiveType(for: item)]
|
panel.allowedContentTypes = [archiveType(for: item)]
|
||||||
|
|
||||||
guard panel.runModal() == .OK, let destinationURL = panel.url else {
|
guard panel.runModal() == .OK, let destinationURL = panel.url else {
|
||||||
@ -683,7 +680,7 @@ struct ContentView: View {
|
|||||||
Task {
|
Task {
|
||||||
do {
|
do {
|
||||||
let finalURL = try await Task.detached(priority: .userInitiated) {
|
let finalURL = try await Task.detached(priority: .userInitiated) {
|
||||||
try await ContentPackageExporter.createArchiveFile(
|
try await itemActionService.createArchiveFile(
|
||||||
for: item,
|
for: item,
|
||||||
source: source,
|
source: source,
|
||||||
destinationURL: destinationURL
|
destinationURL: destinationURL
|
||||||
@ -713,7 +710,7 @@ struct ContentView: View {
|
|||||||
Task {
|
Task {
|
||||||
do {
|
do {
|
||||||
let shareURL = try await Task.detached(priority: .userInitiated) {
|
let shareURL = try await Task.detached(priority: .userInitiated) {
|
||||||
try await ContentPackageExporter.createArchiveFile(
|
try await itemActionService.createArchiveFile(
|
||||||
for: item,
|
for: item,
|
||||||
source: source
|
source: source
|
||||||
)
|
)
|
||||||
|
|||||||
@ -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()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user