Open app with multiple files (#640)

onOpenURL cannot handle multiple URLs on macOS, whereas
NSApplicationDelegate can.

Fixes #637
This commit is contained in:
Davide 2024-09-30 17:22:16 +02:00 committed by GitHub
parent 4877c2bd20
commit aead866275
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 2 deletions

View File

@ -25,9 +25,14 @@
#if os(iOS)
import AppUI
import UIKit
final class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
ImporterPipe.shared.send([url])
return true
}
}
#else
@ -53,6 +58,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
}
return .terminateNow
}
func application(_ application: NSApplication, open urls: [URL]) {
ImporterPipe.shared.send(urls)
}
}
@MainActor

View File

@ -0,0 +1,31 @@
//
// ImporterPipe.swift
// Passepartout
//
// Created by Davide De Rosa on 9/30/24.
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
//
// https://github.com/passepartoutvpn
//
// This file is part of Passepartout.
//
// Passepartout is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Passepartout is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
//
import Combine
import Foundation
public enum ImporterPipe {
public static let shared = PassthroughSubject<[URL], Never>()
}

View File

@ -49,8 +49,8 @@ struct ProfileImporterModifier: ViewModifier {
allowsMultipleSelection: true,
onCompletion: handleResult
)
.onOpenURL { url in
handleResult(.success([url]))
.onReceive(ImporterPipe.shared) {
handleResult(.success($0))
}
.alert(
Strings.Views.Profiles.Toolbar.importProfile,