diff --git a/Tusker/Preferences/Preferences.swift b/Tusker/Preferences/Preferences.swift index 08d386e3..f29bcc91 100644 --- a/Tusker/Preferences/Preferences.swift +++ b/Tusker/Preferences/Preferences.swift @@ -38,9 +38,10 @@ class Preferences: Codable { var avatarStyle = AvatarStyle.roundRect var hideCustomEmojiInUsernames = false + // MARK: - Behavior var defaultPostVisibility = Status.Visibility.public - var automaticallySaveDrafts = true + var openLinksInApps = true // MARK: - Advanced var silentActions: [String: Permission] = [:] diff --git a/Tusker/Screens/Preferences/BehaviorTableViewController.swift b/Tusker/Screens/Preferences/BehaviorTableViewController.swift index a30ec27a..c72ba06a 100644 --- a/Tusker/Screens/Preferences/BehaviorTableViewController.swift +++ b/Tusker/Screens/Preferences/BehaviorTableViewController.swift @@ -12,16 +12,14 @@ class BehaviorTableViewController: UITableViewController { @IBOutlet weak var defaultPostVisibilityLabel: UILabel! @IBOutlet weak var automaticallySaveDraftsSwitch: UISwitch! + @IBOutlet weak var openLinksInAppsSwitch: UISwitch! override func viewDidLoad() { super.viewDidLoad() defaultPostVisibilityLabel.text = Preferences.shared.defaultPostVisibility.displayName automaticallySaveDraftsSwitch.setOn(Preferences.shared.automaticallySaveDrafts, animated: false) - } - - @IBAction func automaticallySaveDraftsChanged(_ sender: Any) { - Preferences.shared.automaticallySaveDrafts = automaticallySaveDraftsSwitch.isOn + openLinksInAppsSwitch.setOn(Preferences.shared.openLinksInApps, animated: false) } override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { @@ -43,4 +41,13 @@ class BehaviorTableViewController: UITableViewController { present(alertController, animated: true) } + @IBAction func automaticallySaveDraftsChanged(_ sender: Any) { + Preferences.shared.automaticallySaveDrafts = automaticallySaveDraftsSwitch.isOn + } + + @IBAction func openLinksInAppsChanged(_ sender: Any) { + Preferences.shared.openLinksInApps = openLinksInAppsSwitch.isOn + } + + } diff --git a/Tusker/Screens/Preferences/Preferences.storyboard b/Tusker/Screens/Preferences/Preferences.storyboard index bb6ea324..af8c2d09 100644 --- a/Tusker/Screens/Preferences/Preferences.storyboard +++ b/Tusker/Screens/Preferences/Preferences.storyboard @@ -1,10 +1,10 @@ - + - + @@ -292,6 +292,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -302,6 +335,7 @@ + diff --git a/Tusker/TuskerNavigationDelegate.swift b/Tusker/TuskerNavigationDelegate.swift index 13490bcf..0d9a41ea 100644 --- a/Tusker/TuskerNavigationDelegate.swift +++ b/Tusker/TuskerNavigationDelegate.swift @@ -60,7 +60,15 @@ extension TuskerNavigationDelegate where Self: UIViewController { } func selected(url: URL) { - present(SFSafariViewController(url: url), animated: true) + if (Preferences.shared.openLinksInApps) { + UIApplication.shared.open(url, options: [.universalLinksOnly: true]) { (success) in + if (!success) { + self.present(SFSafariViewController(url: url), animated: true) + } + } + } else { + present(SFSafariViewController(url: url), animated: true) + } } func selected(status statusID: String) {