Fix destroying working directory
This commit is contained in:
@@ -178,10 +178,15 @@ public struct CoreView: View {
|
|||||||
if Variant.useSystemExtension {
|
if Variant.useSystemExtension {
|
||||||
try RootHelperClient.shared.cleanWorkingDirectory()
|
try RootHelperClient.shared.cleanWorkingDirectory()
|
||||||
} else {
|
} else {
|
||||||
try FileManager.default.removeItem(at: FilePath.workingDirectory)
|
try clearWorkingDirectoryContents()
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
try FileManager.default.removeItem(at: FilePath.workingDirectory)
|
try clearWorkingDirectoryContents()
|
||||||
|
#if os(iOS)
|
||||||
|
if #available(iOS 16.0, *) {
|
||||||
|
await notifyFileProviderWorkingDirectoryChanged()
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
isLoading = true
|
isLoading = true
|
||||||
} catch {
|
} catch {
|
||||||
@@ -189,6 +194,17 @@ public struct CoreView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func clearWorkingDirectoryContents() throws {
|
||||||
|
let url = FilePath.workingDirectory
|
||||||
|
guard FileManager.default.fileExists(atPath: url.path) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let contents = try FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: nil)
|
||||||
|
for item in contents {
|
||||||
|
try FileManager.default.removeItem(at: item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
private func helperRequiredAlert() -> AlertState {
|
private func helperRequiredAlert() -> AlertState {
|
||||||
AlertState(
|
AlertState(
|
||||||
@@ -203,16 +219,35 @@ public struct CoreView: View {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
private nonisolated func fileProviderManager() async throws -> NSFileProviderManager {
|
||||||
|
let domains = try await NSFileProviderManager.domains()
|
||||||
|
guard let domain = domains.first(where: { $0.identifier.rawValue == AppConfiguration.fileProviderDomainID }) else {
|
||||||
|
throw NSError(domain: "CoreView", code: 0, userInfo: [NSLocalizedDescriptionKey: "File provider domain not found"])
|
||||||
|
}
|
||||||
|
guard let manager = NSFileProviderManager(for: domain) else {
|
||||||
|
throw NSError(domain: "CoreView", code: 0, userInfo: [NSLocalizedDescriptionKey: "Failed to get file provider manager"])
|
||||||
|
}
|
||||||
|
return manager
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
private nonisolated func notifyFileProviderWorkingDirectoryChanged() async {
|
||||||
|
do {
|
||||||
|
let manager = try await fileProviderManager()
|
||||||
|
try await manager.signalEnumerator(for: .rootContainer)
|
||||||
|
try await manager.signalEnumerator(for: .workingSet)
|
||||||
|
} catch {
|
||||||
|
await MainActor.run {
|
||||||
|
alert = AlertState(error: error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@available(iOS 16.0, *)
|
@available(iOS 16.0, *)
|
||||||
private nonisolated func openInFilesApp() async {
|
private nonisolated func openInFilesApp() async {
|
||||||
do {
|
do {
|
||||||
let domains = try await NSFileProviderManager.domains()
|
let manager = try await fileProviderManager()
|
||||||
guard let domain = domains.first(where: { $0.identifier.rawValue == AppConfiguration.fileProviderDomainID }) else {
|
|
||||||
throw NSError(domain: "CoreView", code: 0, userInfo: [NSLocalizedDescriptionKey: "File provider domain not found"])
|
|
||||||
}
|
|
||||||
guard let manager = NSFileProviderManager(for: domain) else {
|
|
||||||
throw NSError(domain: "CoreView", code: 0, userInfo: [NSLocalizedDescriptionKey: "Failed to get file provider manager"])
|
|
||||||
}
|
|
||||||
try await manager.signalEnumerator(for: .workingSet)
|
try await manager.signalEnumerator(for: .workingSet)
|
||||||
let url = try await manager.getUserVisibleURL(for: .rootContainer)
|
let url = try await manager.getUserVisibleURL(for: .rootContainer)
|
||||||
guard let sharedURL = URL(string: "shareddocuments://\(url.path)") else {
|
guard let sharedURL = URL(string: "shareddocuments://\(url.path)") else {
|
||||||
|
|||||||
Reference in New Issue
Block a user