Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1d5609f
converting url_launcher from objc to swift
chrisdlangham Aug 18, 2023
d5727dd
converting tests to swift
chrisdlangham Aug 22, 2023
c4e55fb
converting tests to swift
chrisdlangham Aug 22, 2023
050d6b3
fixing issue where pigeon and method channels were not setup right
chrisdlangham Aug 22, 2023
5278199
formatting
chrisdlangham Aug 22, 2023
55a345b
reverting unintentional local changes
chrisdlangham Aug 22, 2023
8356d7a
fixing issues with Ui tests
chrisdlangham Aug 22, 2023
120b2d4
formating
chrisdlangham Aug 22, 2023
1316f3c
Merge branch 'main' into coverting-objc-to-swift
chrisdlangham Aug 22, 2023
7bd3553
updating version and change log
chrisdlangham Aug 22, 2023
2741de4
converting tests to swift
chrisdlangham Aug 22, 2023
495de26
converting unit tests to swift
chrisdlangham Aug 23, 2023
c898698
Merge branch 'main' into converting-url-launcher-ios-tests-to-swift
chrisdlangham Aug 23, 2023
6a6c8d5
updating change log
chrisdlangham Aug 23, 2023
254b9af
resolving merge conflicts
chrisdlangham Aug 23, 2023
869f18f
formatting
chrisdlangham Aug 23, 2023
1120baa
making test class final and private
chrisdlangham Aug 29, 2023
9f591e3
resolving merge conflicts
chrisdlangham Sep 13, 2023
13cd002
updated tests and formated pigeon file
chrisdlangham Sep 13, 2023
f8f5f0b
updates changelog
chrisdlangham Sep 13, 2023
827204a
Update CHANGELOG.md
chrisdlangham Sep 14, 2023
30568fd
Merge branch 'main' into coverting-objc-to-swift
chrisdlangham Sep 14, 2023
6b5e4cd
uses latest version of pigeon
chrisdlangham Sep 15, 2023
3651a97
updates change log
chrisdlangham Sep 15, 2023
257b7cc
moves setting up the pigeon api to the register function instead of t…
chrisdlangham Sep 15, 2023
3ee9d96
resolving merge conflicts
chrisdlangham Sep 28, 2023
d90702f
Merge branch 'main' into coverting-objc-to-swift
chrisdlangham Oct 7, 2023
7241d20
adds in missing throws keyword
chrisdlangham Oct 7, 2023
9d578f2
addresses feedback
chrisdlangham Oct 7, 2023
657c011
changes pigeon api to not throw errors, and let the dart side throw e…
chrisdlangham Oct 11, 2023
7a2fac5
Merge branch 'main' into coverting-objc-to-swift
chrisdlangham Oct 19, 2023
4d4f1bb
addresses feedback
chrisdlangham Oct 19, 2023
7b6272f
addressing feedback
chrisdlangham Oct 26, 2023
b91dca7
Merge branch 'main' into coverting-objc-to-swift
stuartmorgan-g Oct 26, 2023
e7e011a
Replace default launcher implementation with conformance extension
stuartmorgan-g Oct 26, 2023
d955ef8
swift-format
stuartmorgan-g Oct 26, 2023
1297683
Rework return enum to have different versions
stuartmorgan-g Oct 26, 2023
43966a0
Improve invalid URL testing
stuartmorgan-g Oct 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
addressing feedback
  • Loading branch information
chrisdlangham committed Oct 26, 2023
commit 7b6272f7577e7eb0cd540684b21cacebd292fa01
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ final class URLLaunchSession: NSObject, SFSafariViewControllerDelegate {
/// - controller: The Safari view controller.
/// - didLoadSuccessfully: Indicates if the initial load was successful.
func safariViewController(
_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool
_ controller: SFSafariViewController,
didCompleteInitialLoad didLoadSuccessfully: Bool
) {
if didLoadSuccessfully {
completion(.success(.success))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public final class URLLauncherPlugin: NSObject, FlutterPlugin, UrlLauncherApi {
}

func launchUrl(
url: String, universalLinksOnly: Bool,
url: String,
universalLinksOnly: Bool,
completion: @escaping (Result<LaunchResult, Error>) -> Void
) {
guard let url = URL(string: url) else {
Expand All @@ -48,7 +49,8 @@ public final class URLLauncherPlugin: NSObject, FlutterPlugin, UrlLauncherApi {
}

func openUrlInSafariViewController(
url: String, completion: @escaping (Result<LaunchResult, Error>) -> Void
url: String,
completion: @escaping (Result<LaunchResult, Error>) -> Void
) {
guard let url = URL(string: url) else {
completion(.success(.failedToLoad))
Expand All @@ -64,7 +66,7 @@ public final class URLLauncherPlugin: NSObject, FlutterPlugin, UrlLauncherApi {
topViewController?.present(session.safariViewController, animated: true, completion: nil)
}

func closeSafariViewController() throws {
func closeSafariViewController() {
currentSession?.close()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
// See also: https://pub.dev/packages/pigeon

import Foundation

#if os(iOS)
import Flutter
import Flutter
#elseif os(macOS)
import FlutterMacOS
import FlutterMacOS
#else
#error("Unsupported platform.")
#error("Unsupported platform.")
#endif

private func isNullish(_ value: Any?) -> Bool {
Expand All @@ -27,13 +26,13 @@ private func wrapError(_ error: Any) -> [Any?] {
return [
flutterError.code,
flutterError.message,
flutterError.details,
flutterError.details
]
}
return [
"\(error)",
"\(type(of: error))",
"Stacktrace: \(Thread.callStackSymbols)",
"Stacktrace: \(Thread.callStackSymbols)"
]
}

Expand All @@ -46,9 +45,9 @@ private func nilOrValue<T>(_ value: Any?) -> T? {
enum LaunchResult: Int {
/// The URL was successfully launched.
case success = 0
/// The URL could not be launched
/// The URL could not be launched.
case failedToLoad = 1
/// The URL was not launched because it is not invalid URL
/// The URL was not launched because the URL is invalid.
case invalidUrl = 2
}

Expand All @@ -57,13 +56,10 @@ protocol UrlLauncherApi {
/// Returns true if the URL can definitely be launched.
func canLaunchUrl(url: String) throws -> LaunchResult
/// Opens the URL externally, returning true if successful.
func launchUrl(
url: String, universalLinksOnly: Bool,
completion: @escaping (Result<LaunchResult, Error>) -> Void)
func launchUrl(url: String, universalLinksOnly: Bool, completion: @escaping (Result<LaunchResult, Error>) -> Void)
/// Opens the URL in an in-app SFSafariViewController, returning true
/// when it has loaded successfully.
func openUrlInSafariViewController(
url: String, completion: @escaping (Result<LaunchResult, Error>) -> Void)
func openUrlInSafariViewController(url: String, completion: @escaping (Result<LaunchResult, Error>) -> Void)
/// Closes the view controller opened by [openUrlInSafariViewController].
func closeSafariViewController() throws
}
Expand All @@ -74,9 +70,7 @@ class UrlLauncherApiSetup {
/// Sets up an instance of `UrlLauncherApi` to handle messages through the `binaryMessenger`.
static func setUp(binaryMessenger: FlutterBinaryMessenger, api: UrlLauncherApi?) {
/// Returns true if the URL can definitely be launched.
let canLaunchUrlChannel = FlutterBasicMessageChannel(
name: "dev.flutter.pigeon.url_launcher_ios.UrlLauncherApi.canLaunchUrl",
binaryMessenger: binaryMessenger)
let canLaunchUrlChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.url_launcher_ios.UrlLauncherApi.canLaunchUrl", binaryMessenger: binaryMessenger)
if let api = api {
canLaunchUrlChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
Expand All @@ -92,20 +86,18 @@ class UrlLauncherApiSetup {
canLaunchUrlChannel.setMessageHandler(nil)
}
/// Opens the URL externally, returning true if successful.
let launchUrlChannel = FlutterBasicMessageChannel(
name: "dev.flutter.pigeon.url_launcher_ios.UrlLauncherApi.launchUrl",
binaryMessenger: binaryMessenger)
let launchUrlChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.url_launcher_ios.UrlLauncherApi.launchUrl", binaryMessenger: binaryMessenger)
if let api = api {
launchUrlChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let urlArg = args[0] as! String
let universalLinksOnlyArg = args[1] as! Bool
api.launchUrl(url: urlArg, universalLinksOnly: universalLinksOnlyArg) { result in
switch result {
case .success(let res):
reply(wrapResult(res.rawValue))
case .failure(let error):
reply(wrapError(error))
case .success(let res):
reply(wrapResult(res.rawValue))
case .failure(let error):
reply(wrapError(error))
}
}
}
Expand All @@ -114,29 +106,25 @@ class UrlLauncherApiSetup {
}
/// Opens the URL in an in-app SFSafariViewController, returning true
/// when it has loaded successfully.
let openUrlInSafariViewControllerChannel = FlutterBasicMessageChannel(
name: "dev.flutter.pigeon.url_launcher_ios.UrlLauncherApi.openUrlInSafariViewController",
binaryMessenger: binaryMessenger)
let openUrlInSafariViewControllerChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.url_launcher_ios.UrlLauncherApi.openUrlInSafariViewController", binaryMessenger: binaryMessenger)
if let api = api {
openUrlInSafariViewControllerChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let urlArg = args[0] as! String
api.openUrlInSafariViewController(url: urlArg) { result in
switch result {
case .success(let res):
reply(wrapResult(res.rawValue))
case .failure(let error):
reply(wrapError(error))
case .success(let res):
reply(wrapResult(res.rawValue))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
openUrlInSafariViewControllerChannel.setMessageHandler(nil)
}
/// Closes the view controller opened by [openUrlInSafariViewController].
let closeSafariViewControllerChannel = FlutterBasicMessageChannel(
name: "dev.flutter.pigeon.url_launcher_ios.UrlLauncherApi.closeSafariViewController",
binaryMessenger: binaryMessenger)
let closeSafariViewControllerChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.url_launcher_ios.UrlLauncherApi.closeSafariViewController", binaryMessenger: binaryMessenger)
if let api = api {
closeSafariViewControllerChannel.setMessageHandler { _, reply in
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ enum LaunchResult {
/// The URL was successfully launched.
success,

/// The URL could not be launched
/// The URL could not be launched.
failedToLoad,

/// The URL was not launched because it is not invalid URL
/// The URL was not launched because the URL is invalid.
invalidUrl,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,15 @@ class UrlLauncherIOS extends UrlLauncherPlatform {
required final LaunchResult results,
required String url,
}) {
// Replace this in https://github.com/flutter/flutter/issues/127665
// This is temporary since FlutterError is not a NSError.
// The PlatformExceptions thrown here are for compatibility with the
// previous Objective-C implementation.
switch (results) {
case LaunchResult.success:
return true;
case LaunchResult.failedToLoad:
return false;
case LaunchResult.invalidUrl:
// TODO(stuartmorgan): Remove this as part of standardizing error handling. See
// flutter/flutter#127665
// The PlatformExceptions thrown here is for compatibility with the previous implementation.
throw PlatformException(
code: 'invalidUrl',
message: 'Unable to parse URL $url',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ enum LaunchResult {
/// The URL was successfully launched.
success,

/// The URL could not be launched
/// The URL could not be launched.
failedToLoad,

/// The URL was not launched because it is not invalid URL
/// The URL was not launched because the URL is invalid.
invalidUrl,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void main() {
);
expect(
await launcher.launch(
'invalid://u r l',
'unknown://scheme',
useSafariVC: false,
useWebView: false,
enableJavaScript: false,
Expand Down