This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[url_launcher] Adds macOS support #2187
Closed
stuartmorgan-g
wants to merge
3
commits into
flutter:master
from
stuartmorgan-g:url-launcher-macos-revisit
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # url\_launcher\_macos | ||
|
|
||
| The macOS implementation of [`url_launcher`][1]. | ||
|
|
||
| ## Usage | ||
|
|
||
| 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 | ||
| 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 |
21 changes: 21 additions & 0 deletions
21
packages/url_launcher/url_launcher_macos/ios/url_launcher_macos.podspec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
48 changes: 48 additions & 0 deletions
48
packages/url_launcher/url_launcher_macos/macos/Classes/UrlLauncherPlugin.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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))") | ||
| } |
20 changes: 20 additions & 0 deletions
20
packages/url_launcher/url_launcher_macos/macos/url_launcher_fde.podspec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| name: url_launcher_macos | ||
| description: macOS platform implementation of url_launcher | ||
| version: 0.9.0 | ||
| author: Flutter Team <flutter-dev@googlegroups.com> | ||
| 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" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.