iOS/Sources/App/Utilities/OpenInFirefoxControllerSwift.swift
Zac West d51a2d6893
Update to Xcode 14 & dependencies (#2228)
Fixes #2214.

## Summary
Updates to building with Xcode 14 as the minimum. Updates all
dependencies (as many both require Xcode 14 to update and would not work
with it without updating).

## Any other notes
This excludes `arm64` (new in Xcode 14) from watchOS builds. This is due
to App Store Connect having a bad heuristic for file size:

> ITMS-90389: Size Limit Exceeded - The size of watch application
'/Payload/Home Assistant.app/Watch/HomeAssistant-WatchApp.app' (102MB)
has exceeded the 75MB size limit.

Our binary file is larger than 75 MB unthinned and our thinned install
size is sub-25 MB, so I don't think this is testing the right thing. In
either case, we're somehow below whatever the limit actually is with
just `arm64_32_v8` and `arm_v7k` slices.

The first build on TF using the Xcode 14 build for distribution is
2022.413.
2022-10-19 13:56:30 -07:00

59 lines
1.7 KiB
Swift

// swiftformat:disable fileHeader
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import Foundation
import UIKit
open class OpenInFirefoxControllerSwift {
enum FirefoxType {
case regular
case focus
case klar
var urlScheme: String {
switch self {
case .regular:
return "firefox"
case .focus:
return "firefox-focus"
case .klar:
return "firefox-klar"
}
}
}
let type: FirefoxType
// This would need to be changed if used from an extension but you
// can't open arbitrary URLs from an extension anyway.
let app = UIApplication.shared
init(type: FirefoxType = .regular) {
self.type = type
}
private func encodeByAddingPercentEscapes(_ input: String) -> String {
NSString(string: input).addingPercentEncoding(
withAllowedCharacters: .urlQueryAllowed
)!
}
open func isFirefoxInstalled() -> Bool {
app.canOpenURL(URL(string: "\(type.urlScheme)://")!)
}
open func openInFirefox(_ url: URL, privateTab: Bool = false) {
let scheme = url.scheme
if scheme == "http" || scheme == "https" {
let escaped = encodeByAddingPercentEscapes(url.absoluteString)
if let firefoxURL =
URL(string: "\(type.urlScheme)://open-url?\(privateTab ? "private=true&" : "")url=\(escaped)") {
app.open(firefoxURL, options: [:], completionHandler: nil)
}
}
}
}