Add browse button to open working directory in Files app (iOS)
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
import Libbox
|
import Libbox
|
||||||
import Library
|
import Library
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
#if os(iOS)
|
||||||
|
import FileProvider
|
||||||
|
import UIKit
|
||||||
|
#endif
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
public struct CoreView: View {
|
public struct CoreView: View {
|
||||||
@@ -41,6 +45,16 @@ public struct CoreView: View {
|
|||||||
} label: {
|
} label: {
|
||||||
Label("Open", systemImage: "macwindow.and.cursorarrow")
|
Label("Open", systemImage: "macwindow.and.cursorarrow")
|
||||||
}
|
}
|
||||||
|
#elseif os(iOS)
|
||||||
|
if #available(iOS 16.0, *) {
|
||||||
|
FormButton {
|
||||||
|
Task {
|
||||||
|
await openInFilesApp()
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
|
Label("Browse", systemImage: "folder.fill")
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
FormButton(role: .destructive) {
|
FormButton(role: .destructive) {
|
||||||
Task {
|
Task {
|
||||||
@@ -115,6 +129,30 @@ public struct CoreView: View {
|
|||||||
isLoading = true
|
isLoading = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if os(iOS)
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
private nonisolated func openInFilesApp() async {
|
||||||
|
do {
|
||||||
|
let domains = try await NSFileProviderManager.domains()
|
||||||
|
guard let domain = domains.first(where: { $0.identifier.rawValue == "io.nekohasekai.sfavt.workingdir" }) 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"])
|
||||||
|
}
|
||||||
|
let url = try await manager.getUserVisibleURL(for: .rootContainer)
|
||||||
|
guard let sharedURL = URL(string: "shareddocuments://\(url.path)") else {
|
||||||
|
throw NSError(domain: "CoreView", code: 0, userInfo: [NSLocalizedDescriptionKey: "Failed to create shared documents URL"])
|
||||||
|
}
|
||||||
|
await UIApplication.shared.open(sharedURL)
|
||||||
|
} catch {
|
||||||
|
await MainActor.run {
|
||||||
|
alert = AlertState(error: error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension URL {
|
private extension URL {
|
||||||
|
|||||||
@@ -204,6 +204,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"Browse" : {
|
||||||
|
"localizations" : {
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "浏览"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"By default, segment routing is used in `auto_route` instead of global routing.\nIf `<route_address/route_exclude_address>` exists in the configuration, this item will not take effect on the corresponding network (commonly used to resolve HomeKit compatibility issues)." : {
|
"By default, segment routing is used in `auto_route` instead of global routing.\nIf `<route_address/route_exclude_address>` exists in the configuration, this item will not take effect on the corresponding network (commonly used to resolve HomeKit compatibility issues)." : {
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
"zh-Hans" : {
|
"zh-Hans" : {
|
||||||
|
|||||||
Reference in New Issue
Block a user