Adds social media follow buttons to Settings

This commit is contained in:
Riley Testut
2024-02-14 15:50:09 -06:00
committed by Magesh K
parent f85dcdcd4a
commit 1c02da8806
10 changed files with 220 additions and 13 deletions

View File

@@ -99,6 +99,11 @@ final class SettingsViewController: UITableViewController
@IBOutlet private var enforceThreeAppLimitSwitch: UISwitch!
@IBOutlet private var disableResponseCachingSwitch: UISwitch!
@IBOutlet private var mastodonButton: UIButton!
@IBOutlet private var threadsButton: UIButton!
@IBOutlet private var twitterButton: UIButton!
@IBOutlet private var githubButton: UIButton!
@IBOutlet private var versionLabel: UILabel!
override var preferredStatusBarStyle: UIStatusBarStyle {
@@ -142,7 +147,7 @@ final class SettingsViewController: UITableViewController
let localizedVersion = installedApp.version
#endif
self.versionLabel.text = NSLocalizedString(String(format: "AltStore %@", localizedVersion), comment: "AltStore Version")
self.versionLabel.text = NSLocalizedString(String(format: "Version %@", localizedVersion), comment: "AltStore Version")
}
else if let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
{
@@ -159,9 +164,11 @@ final class SettingsViewController: UITableViewController
versionString += " - \(!pair_test)"
}
}
self.versionLabel.text = NSLocalizedString(String(format: "Version %@", version), comment: "AltStore Version")
}
else
{
self.versionLabel.text = nil
versionString += "SideStore\t"
}
versionString += "\n\(Bundle.Info.appbundleIdentifier)"
@@ -176,10 +183,26 @@ final class SettingsViewController: UITableViewController
self.update()
if #available(iOS 15, *), let appearance = self.tabBarController?.tabBar.standardAppearance
if #available(iOS 15, *)
{
appearance.stackedLayoutAppearance.normal.badgeBackgroundColor = .altPrimary
self.navigationController?.tabBarItem.scrollEdgeAppearance = appearance
if let appearance = self.tabBarController?.tabBar.standardAppearance
{
appearance.stackedLayoutAppearance.normal.badgeBackgroundColor = .altPrimary
self.navigationController?.tabBarItem.scrollEdgeAppearance = appearance
}
// We can only configure the contentMode for a button's background image from Interface Builder.
// This works, but it means buttons don't visually highlight because there's no foreground image.
// As a workaround, we manually set the foreground image + contentMode here.
for button in [self.mastodonButton!, self.threadsButton!, self.twitterButton!, self.githubButton!]
{
// Get the assigned image from Interface Builder.
let image = button.configuration?.background.image
button.configuration = nil
button.setImage(image, for: .normal)
button.imageView?.contentMode = .scaleAspectFit
}
}
}
@@ -497,6 +520,51 @@ private extension SettingsViewController
}
}
}
func openMastodon(username: String)
{
// Rely on universal links to open app.
let components = username.split(separator: "@")
guard components.count == 2 else { return }
let server = String(components[1])
let username = "@" + String(components[0])
guard let serverURL = URL(string: "https://" + server) else { return }
let mastodonURL = serverURL.appendingPathComponent(username)
UIApplication.shared.open(mastodonURL, options: [:])
}
func openThreads(username: String)
{
// Rely on universal links to open app.
let safariURL = URL(string: "https://www.threads.net/@" + username)!
UIApplication.shared.open(safariURL, options: [:])
}
@IBAction func followAltStoreMastodon()
{
self.openMastodon(username: "@altstore@fosstodon.org")
}
@IBAction func followAltStoreThreads()
{
self.openThreads(username: "altstoreio")
}
@IBAction func followAltStoreTwitter()
{
self.openTwitter(username: "altstoreio")
}
@IBAction func followAltStoreGitHub()
{
let safariURL = URL(string: "https://github.com/altstoreio")!
UIApplication.shared.open(safariURL, options: [:])
}
}
private extension SettingsViewController