Associate and handle imported files (#628)

This commit is contained in:
Davide 2024-09-28 11:43:57 +02:00 committed by GitHub
parent 95c09f4353
commit 9e6e59276b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 5 deletions

View File

@ -32,8 +32,7 @@
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.text</string>
<string>public.zip-archive</string>
<string>public.item</string>
</array>
</dict>
<dict>

View File

@ -42,11 +42,13 @@ struct PassepartoutApp: App {
private let context: AppContext = .shared
// private let context: AppContext = .mock(withRegistry: .shared)
private let appName = Constants.shared.identifiers.displayName
@StateObject
private var theme = Theme()
var body: some Scene {
WindowGroup {
Window(appName, id: appName) {
AppCoordinator(
profileManager: context.profileManager,
tunnel: context.tunnel,

View File

@ -47,8 +47,11 @@ struct ProfileImporterModifier: ViewModifier {
isPresented: $isPresented,
allowedContentTypes: [.item],
allowsMultipleSelection: true,
onCompletion: onCompletion
onCompletion: handleResult
)
.onOpenURL { url in
handleResult(.success([url]))
}
.alert(
Strings.Views.Profiles.Toolbar.importProfile,
isPresented: $importer.isPresentingPassphrase,
@ -85,7 +88,7 @@ private extension ProfileImporterModifier {
Text(Strings.Views.Profiles.Alerts.Import.Passphrase.message(url.lastPathComponent))
}
func onCompletion(_ result: Result<[URL], Error>) {
func handleResult(_ result: Result<[URL], Error>) {
Task.detached {
do {
let urls = try result.get()