From 4e6749a1d28a887857c714bc689c5660168abab0 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Mon, 14 Oct 2019 11:11:06 -0700 Subject: [PATCH 1/3] Adds macOS support for url_launche Follows the structure established in #2119 to add a federated macOS implementation of the url_launcher plugin. Fixes macOS portion of https://github.com/flutter/flutter/issues/41721 --- .../url_launcher/url_launcher_macos/LICENSE | 27 +++++++++++ .../ios/url_launcher_macos.podspec | 21 ++++++++ .../macos/Classes/UrlLauncherPlugin.swift | 48 +++++++++++++++++++ .../macos/url_launcher_fde.podspec | 20 ++++++++ .../url_launcher_macos/pubspec.yaml | 23 +++++++++ 5 files changed, 139 insertions(+) create mode 100644 packages/url_launcher/url_launcher_macos/LICENSE create mode 100644 packages/url_launcher/url_launcher_macos/ios/url_launcher_macos.podspec create mode 100644 packages/url_launcher/url_launcher_macos/macos/Classes/UrlLauncherPlugin.swift create mode 100644 packages/url_launcher/url_launcher_macos/macos/url_launcher_fde.podspec create mode 100644 packages/url_launcher/url_launcher_macos/pubspec.yaml diff --git a/packages/url_launcher/url_launcher_macos/LICENSE b/packages/url_launcher/url_launcher_macos/LICENSE new file mode 100644 index 000000000000..0c382ce171cc --- /dev/null +++ b/packages/url_launcher/url_launcher_macos/LICENSE @@ -0,0 +1,27 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/url_launcher/url_launcher_macos/ios/url_launcher_macos.podspec b/packages/url_launcher/url_launcher_macos/ios/url_launcher_macos.podspec new file mode 100644 index 000000000000..deba27191128 --- /dev/null +++ b/packages/url_launcher/url_launcher_macos/ios/url_launcher_macos.podspec @@ -0,0 +1,21 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html +# +Pod::Spec.new do |s| + s.name = 'url_launcher_fde' + s.version = '0.0.1' + s.summary = 'No-op implementation of url_launcher_macos to avoid build issues on iOS' + s.description = <<-DESC + No-op implementation of url_launcher_macos to avoid build issues on iOS. + See https://github.com/flutter/flutter/issues/39659 + DESC + s.homepage = 'https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_macos' + s.license = { :file => '../LICENSE' } + s.author = { 'Flutter Team' => 'flutter-dev@googlegroups.com' } + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.public_header_files = 'Classes/**/*.h' + s.dependency 'Flutter' + + s.ios.deployment_target = '8.0' +end diff --git a/packages/url_launcher/url_launcher_macos/macos/Classes/UrlLauncherPlugin.swift b/packages/url_launcher/url_launcher_macos/macos/Classes/UrlLauncherPlugin.swift new file mode 100644 index 000000000000..7f997ce4feeb --- /dev/null +++ b/packages/url_launcher/url_launcher_macos/macos/Classes/UrlLauncherPlugin.swift @@ -0,0 +1,48 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import FlutterMacOS +import Foundation + +public class UrlLauncherPlugin: NSObject, FlutterPlugin { + public static func register(with registrar: FlutterPluginRegistrar) { + let channel = FlutterMethodChannel( + name: "plugins.flutter.io/url_launcher", + binaryMessenger: registrar.messenger) + let instance = UrlLauncherPlugin() + registrar.addMethodCallDelegate(instance, channel: channel) + } + + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + let urlString: String? = (call.arguments as? [String: Any])?["url"] as? String + switch call.method { + case "canLaunch": + guard let unwrappedURLString = urlString, + let url = URL.init(string: unwrappedURLString) + else { + result(invalidURLError(urlString)) + return + } + result(NSWorkspace.shared.urlForApplication(toOpen: url) != nil) + case "launch": + guard let unwrappedURLString = urlString, + let url = URL.init(string: unwrappedURLString) + else { + result(invalidURLError(urlString)) + return + } + result(NSWorkspace.shared.open(url)) + default: + result(FlutterMethodNotImplemented) + } + } +} + +/// Returns an error for the case where a URL string can't be parsed as a URL. +private func invalidURLError(_ url: String?) -> FlutterError { + return FlutterError( + code: "argument_error", + message: "Unable to parse URL", + details: "Provided URL: \(String(describing: url))") +} diff --git a/packages/url_launcher/url_launcher_macos/macos/url_launcher_fde.podspec b/packages/url_launcher/url_launcher_macos/macos/url_launcher_fde.podspec new file mode 100644 index 000000000000..ee82719c5a7f --- /dev/null +++ b/packages/url_launcher/url_launcher_macos/macos/url_launcher_fde.podspec @@ -0,0 +1,20 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html +# +Pod::Spec.new do |s| + s.name = 'url_launcher_macos' + s.version = '0.0.1' + s.summary = 'Flutter plugin for launching a URL.' + s.description = <<-DESC + A macOS implmentation of the url_launcher plugin. + DESC + s.homepage = 'https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_macos' + s.license = { :file => '../LICENSE' } + s.author = { 'Flutter Team' => 'flutter-dev@googlegroups.com' } + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.dependency 'FlutterMacOS' + + s.platform = :osx + s.osx.deployment_target = '10.11' +end diff --git a/packages/url_launcher/url_launcher_macos/pubspec.yaml b/packages/url_launcher/url_launcher_macos/pubspec.yaml new file mode 100644 index 000000000000..dd5b40ece30f --- /dev/null +++ b/packages/url_launcher/url_launcher_macos/pubspec.yaml @@ -0,0 +1,23 @@ +name: url_launcher_macos +description: macOS platform implementation of url_launcher +version: 0.9.0 +author: Flutter Team +homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_macos + +flutter: + plugin: + platforms: + macos: + pluginClass: UrlLauncherPlugin + +dependencies: + flutter: + sdk: flutter + +dev_dependencies: + flutter_test: + sdk: flutter + +environment: + sdk: ">=2.0.0-dev.28.0 <3.0.0" + flutter: ">=1.5.0 <2.0.0" From 0a7244f83a2160129c4731444d41c580a9ed86ab Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Mon, 14 Oct 2019 11:16:40 -0700 Subject: [PATCH 2/3] Add README as in _web version --- .../url_launcher/url_launcher_macos/README.md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 packages/url_launcher/url_launcher_macos/README.md diff --git a/packages/url_launcher/url_launcher_macos/README.md b/packages/url_launcher/url_launcher_macos/README.md new file mode 100644 index 000000000000..f7557d419d4b --- /dev/null +++ b/packages/url_launcher/url_launcher_macos/README.md @@ -0,0 +1,25 @@ +# url\_launcher\_macos + +The macOS implementation of [`url_launcher`][1]. + +## Usage + +To use this plugin in your Flutter Web app, simply add it as a dependency in +your pubspec using a `git` dependency. This is only temporary: in the future +we hope to make this package an "endorsed" implementation of `url_launcher`, +so that it is automatically included in your macOS Flutter app when you depend +on `package:url_launcher`. + +```yaml +dependencies: + url_launcher: ^5.1.4 + url_launcher_macos: + git: + url: git://github.com/flutter/plugins.git + path: packages/url_launcher/url_launcher_macos +``` + +Once you have the `url_launcher_macos` dependency in your pubspec, you should +be able to use `package:url_launcher` as normal. + +[1]: ../url_launcher From 585b03d0ea71efad5780e8243ce41dd6e18b5ee5 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Mon, 14 Oct 2019 14:43:55 -0700 Subject: [PATCH 3/3] Copypasta fix --- packages/url_launcher/url_launcher_macos/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/url_launcher/url_launcher_macos/README.md b/packages/url_launcher/url_launcher_macos/README.md index f7557d419d4b..6a726ec3c688 100644 --- a/packages/url_launcher/url_launcher_macos/README.md +++ b/packages/url_launcher/url_launcher_macos/README.md @@ -4,7 +4,7 @@ The macOS implementation of [`url_launcher`][1]. ## Usage -To use this plugin in your Flutter Web app, simply add it as a dependency in +To use this plugin in your macOS Flutter app, simply add it as a dependency in your pubspec using a `git` dependency. This is only temporary: in the future we hope to make this package an "endorsed" implementation of `url_launcher`, so that it is automatically included in your macOS Flutter app when you depend