forked from shadowfacts/Tusker
Support settings -> app notification preferences link
This commit is contained in:
parent
bc516a6326
commit
baf96a8b06
|
@ -84,7 +84,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
|
|
||||||
BackgroundManager.shared.registerHandlers()
|
BackgroundManager.shared.registerHandlers()
|
||||||
|
|
||||||
initializePushManager()
|
initializePushNotifications()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
PushManager.shared.didFailToRegisterForRemoteNotifications(error: error)
|
PushManager.shared.didFailToRegisterForRemoteNotifications(error: error)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func initializePushManager() {
|
private func initializePushNotifications() {
|
||||||
|
UNUserNotificationCenter.current().delegate = self
|
||||||
Task {
|
Task {
|
||||||
PushManager.captureError = { SentrySDK.capture(error: $0) }
|
PushManager.captureError = { SentrySDK.capture(error: $0) }
|
||||||
await PushManager.shared.updateIfNecessary(updateSubscription: {
|
await PushManager.shared.updateIfNecessary(updateSubscription: {
|
||||||
|
@ -255,3 +256,23 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension AppDelegate: UNUserNotificationCenterDelegate {
|
||||||
|
func userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?) {
|
||||||
|
let mainSceneDelegate: MainSceneDelegate
|
||||||
|
if let delegate = UIApplication.shared.activeScene?.delegate as? MainSceneDelegate {
|
||||||
|
mainSceneDelegate = delegate
|
||||||
|
} else if let scene = UIApplication.shared.connectedScenes.first(where: { $0.delegate is MainSceneDelegate }) {
|
||||||
|
mainSceneDelegate = scene.delegate as! MainSceneDelegate
|
||||||
|
} else if let accountID = UserAccountsManager.shared.mostRecentAccountID {
|
||||||
|
let activity = UserActivityManager.mainSceneActivity(accountID: accountID)
|
||||||
|
activity.addUserInfoEntries(from: ["showNotificationsPreferences": true])
|
||||||
|
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: activity, options: nil)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
// without an account, we can't do anything
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mainSceneDelegate.showNotificationsPreferences()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -283,6 +283,16 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDelegate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func showNotificationsPreferences() {
|
||||||
|
let preferencesVC: PreferencesNavigationController?
|
||||||
|
if let presented = rootViewController?.presentedViewController as? PreferencesNavigationController {
|
||||||
|
preferencesVC = presented
|
||||||
|
} else {
|
||||||
|
preferencesVC = rootViewController?.presentPreferences(completion: nil)
|
||||||
|
}
|
||||||
|
preferencesVC?.navigationState.showNotificationPreferences = true
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension MainSceneDelegate: OnboardingViewControllerDelegate {
|
extension MainSceneDelegate: OnboardingViewControllerDelegate {
|
||||||
|
|
|
@ -152,9 +152,9 @@ extension AccountSwitchingContainerViewController: TuskerRootViewController {
|
||||||
root.performSearch(query: query)
|
root.performSearch(query: query)
|
||||||
}
|
}
|
||||||
|
|
||||||
func presentPreferences(completion: (() -> Void)?) {
|
func presentPreferences(completion: (() -> Void)?) -> PreferencesNavigationController? {
|
||||||
loadViewIfNeeded()
|
loadViewIfNeeded()
|
||||||
root.presentPreferences(completion: completion)
|
return root.presentPreferences(completion: completion)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleStatusBarTapped(xPosition: CGFloat) -> StatusBarTapActionResult {
|
func handleStatusBarTapped(xPosition: CGFloat) -> StatusBarTapActionResult {
|
||||||
|
|
|
@ -47,7 +47,7 @@ extension DuckableContainerViewController: AccountSwitchableViewController {
|
||||||
(child as? TuskerRootViewController)?.performSearch(query: query)
|
(child as? TuskerRootViewController)?.performSearch(query: query)
|
||||||
}
|
}
|
||||||
|
|
||||||
func presentPreferences(completion: (() -> Void)?) {
|
func presentPreferences(completion: (() -> Void)?) -> PreferencesNavigationController? {
|
||||||
(child as? TuskerRootViewController)?.presentPreferences(completion: completion)
|
(child as? TuskerRootViewController)?.presentPreferences(completion: completion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -623,8 +623,10 @@ extension MainSplitViewController: TuskerRootViewController {
|
||||||
searchViewController.resultsController.performSearch(query: query)
|
searchViewController.resultsController.performSearch(query: query)
|
||||||
}
|
}
|
||||||
|
|
||||||
func presentPreferences(completion: (() -> Void)?) {
|
func presentPreferences(completion: (() -> Void)?) -> PreferencesNavigationController? {
|
||||||
present(PreferencesNavigationController(mastodonController: mastodonController), animated: true, completion: completion)
|
let vc = PreferencesNavigationController(mastodonController: mastodonController)
|
||||||
|
present(vc, animated: true, completion: completion)
|
||||||
|
return vc
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleStatusBarTapped(xPosition: CGFloat) -> StatusBarTapActionResult {
|
func handleStatusBarTapped(xPosition: CGFloat) -> StatusBarTapActionResult {
|
||||||
|
|
|
@ -342,8 +342,10 @@ extension MainTabBarViewController: TuskerRootViewController {
|
||||||
exploreController.resultsController.performSearch(query: query)
|
exploreController.resultsController.performSearch(query: query)
|
||||||
}
|
}
|
||||||
|
|
||||||
func presentPreferences(completion: (() -> Void)?) {
|
func presentPreferences(completion: (() -> Void)?) -> PreferencesNavigationController? {
|
||||||
present(PreferencesNavigationController(mastodonController: mastodonController), animated: true, completion: completion)
|
let vc = PreferencesNavigationController(mastodonController: mastodonController)
|
||||||
|
present(vc, animated: true, completion: completion)
|
||||||
|
return vc
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleStatusBarTapped(xPosition: CGFloat) -> StatusBarTapActionResult {
|
func handleStatusBarTapped(xPosition: CGFloat) -> StatusBarTapActionResult {
|
||||||
|
|
|
@ -17,7 +17,8 @@ protocol TuskerRootViewController: UIViewController, StateRestorableViewControll
|
||||||
func getNavigationDelegate() -> TuskerNavigationDelegate?
|
func getNavigationDelegate() -> TuskerNavigationDelegate?
|
||||||
func getNavigationController() -> NavigationControllerProtocol
|
func getNavigationController() -> NavigationControllerProtocol
|
||||||
func performSearch(query: String)
|
func performSearch(query: String)
|
||||||
func presentPreferences(completion: (() -> Void)?)
|
@discardableResult
|
||||||
|
func presentPreferences(completion: (() -> Void)?) -> PreferencesNavigationController?
|
||||||
}
|
}
|
||||||
|
|
||||||
//extension TuskerRootViewController {
|
//extension TuskerRootViewController {
|
||||||
|
|
|
@ -70,8 +70,7 @@ struct NotificationsPrefsView: View {
|
||||||
private func startRegistration() async -> Bool {
|
private func startRegistration() async -> Bool {
|
||||||
let authorized: Bool
|
let authorized: Bool
|
||||||
do {
|
do {
|
||||||
// TODO: support .providesAppNotificationSettings
|
authorized = try await UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .providesAppNotificationSettings])
|
||||||
authorized = try await UNUserNotificationCenter.current().requestAuthorization(options: [.alert])
|
|
||||||
} catch {
|
} catch {
|
||||||
self.error = .requestingAuthorization(error)
|
self.error = .requestingAuthorization(error)
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -13,16 +13,24 @@ import SafariServices
|
||||||
import AuthenticationServices
|
import AuthenticationServices
|
||||||
import Pachyderm
|
import Pachyderm
|
||||||
|
|
||||||
|
// TODO: replace this with NavigationStack and path once we target iOS 16
|
||||||
|
class PreferencesNavigationState: ObservableObject {
|
||||||
|
@Published var showNotificationPreferences = false
|
||||||
|
}
|
||||||
|
|
||||||
class PreferencesNavigationController: UINavigationController {
|
class PreferencesNavigationController: UINavigationController {
|
||||||
|
|
||||||
private let mastodonController: MastodonController
|
private let mastodonController: MastodonController
|
||||||
|
let navigationState: PreferencesNavigationState
|
||||||
|
|
||||||
private var isSwitchingAccounts = false
|
private var isSwitchingAccounts = false
|
||||||
|
|
||||||
init(mastodonController: MastodonController) {
|
init(mastodonController: MastodonController) {
|
||||||
self.mastodonController = mastodonController
|
self.mastodonController = mastodonController
|
||||||
|
let navigationState = PreferencesNavigationState()
|
||||||
|
self.navigationState = navigationState
|
||||||
|
|
||||||
let view = PreferencesView(mastodonController: mastodonController)
|
let view = PreferencesView(mastodonController: mastodonController, navigationState: navigationState)
|
||||||
let hostingController = UIHostingController(rootView: view)
|
let hostingController = UIHostingController(rootView: view)
|
||||||
super.init(rootViewController: hostingController)
|
super.init(rootViewController: hostingController)
|
||||||
hostingController.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(donePressed))
|
hostingController.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(donePressed))
|
||||||
|
|
|
@ -10,12 +10,14 @@ import UserAccounts
|
||||||
|
|
||||||
struct PreferencesView: View {
|
struct PreferencesView: View {
|
||||||
let mastodonController: MastodonController
|
let mastodonController: MastodonController
|
||||||
|
@ObservedObject var navigationState: PreferencesNavigationState
|
||||||
|
|
||||||
@ObservedObject private var userAccounts = UserAccountsManager.shared
|
@ObservedObject private var userAccounts = UserAccountsManager.shared
|
||||||
@State private var showingLogoutConfirmation = false
|
@State private var showingLogoutConfirmation = false
|
||||||
|
|
||||||
init(mastodonController: MastodonController) {
|
init(mastodonController: MastodonController, navigationState: PreferencesNavigationState) {
|
||||||
self.mastodonController = mastodonController
|
self.mastodonController = mastodonController
|
||||||
|
self.navigationState = navigationState
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
@ -92,7 +94,9 @@ struct PreferencesView: View {
|
||||||
|
|
||||||
private var notificationsSection: some View {
|
private var notificationsSection: some View {
|
||||||
Section {
|
Section {
|
||||||
NavigationLink(destination: NotificationsPrefsView()) {
|
NavigationLink(isActive: $navigationState.showNotificationPreferences) {
|
||||||
|
NotificationsPrefsView()
|
||||||
|
} label: {
|
||||||
Text("Notifications")
|
Text("Notifications")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue