Compare commits

..

3 Commits

Author SHA1 Message Date
Shadowfacts e5363b2e21 Fix sidebar key commands not working on macOS
Closes #253
2023-04-03 23:25:33 -04:00
Shadowfacts d04259b253 Fix scroll to top not working in presented VCs
Closes #363
2023-04-03 22:45:15 -04:00
Shadowfacts f50c219f95 Send scopes in /oauth/token request
Closes #360
2023-04-03 22:43:01 -04:00
4 changed files with 39 additions and 45 deletions

View File

@ -139,13 +139,14 @@ public class Client {
} }
} }
public func getAccessToken(authorizationCode: String, redirectURI: String, completion: @escaping Callback<LoginSettings>) { public func getAccessToken(authorizationCode: String, redirectURI: String, scopes: [Scope], completion: @escaping Callback<LoginSettings>) {
let request = Request<LoginSettings>(method: .post, path: "/oauth/token", body: ParametersBody([ let request = Request<LoginSettings>(method: .post, path: "/oauth/token", body: ParametersBody([
"client_id" => clientID, "client_id" => clientID,
"client_secret" => clientSecret, "client_secret" => clientSecret,
"grant_type" => "authorization_code", "grant_type" => "authorization_code",
"code" => authorizationCode, "code" => authorizationCode,
"redirect_uri" => redirectURI "redirect_uri" => redirectURI,
"scope" => scopes.scopeString,
])) ]))
run(request) { result in run(request) { result in
defer { completion(result) } defer { completion(result) }

View File

@ -10,6 +10,8 @@ import Foundation
import Pachyderm import Pachyderm
import Combine import Combine
private let oauthScopes = [Scope.read, .write, .follow]
class MastodonController: ObservableObject { class MastodonController: ObservableObject {
static private(set) var all = [LocalData.UserAccountInfo: MastodonController]() static private(set) var all = [LocalData.UserAccountInfo: MastodonController]()
@ -128,7 +130,7 @@ class MastodonController: ObservableObject {
return (clientID, clientSecret) return (clientID, clientSecret)
} else { } else {
let app: RegisteredApplication = try await withCheckedThrowingContinuation({ continuation in let app: RegisteredApplication = try await withCheckedThrowingContinuation({ continuation in
client.registerApp(name: "Tusker", redirectURI: "tusker://oauth", scopes: [.read, .write, .follow]) { response in client.registerApp(name: "Tusker", redirectURI: "tusker://oauth", scopes: oauthScopes) { response in
switch response { switch response {
case .failure(let error): case .failure(let error):
continuation.resume(throwing: error) continuation.resume(throwing: error)
@ -146,7 +148,7 @@ class MastodonController: ObservableObject {
/// - Returns: The access token /// - Returns: The access token
func authorize(authorizationCode: String) async throws -> String { func authorize(authorizationCode: String) async throws -> String {
return try await withCheckedThrowingContinuation({ continuation in return try await withCheckedThrowingContinuation({ continuation in
client.getAccessToken(authorizationCode: authorizationCode, redirectURI: "tusker://oauth") { response in client.getAccessToken(authorizationCode: authorizationCode, redirectURI: "tusker://oauth", scopes: oauthScopes) { response in
switch response { switch response {
case .failure(let error): case .failure(let error):
continuation.resume(throwing: error) continuation.resume(throwing: error)

View File

@ -18,33 +18,22 @@ struct MenuController {
return UIKeyCommand(title: "Refresh", action: #selector(RefreshableViewController.refresh), input: "r", modifierFlags: .command, discoverabilityTitle: discoverabilityTitle) return UIKeyCommand(title: "Refresh", action: #selector(RefreshableViewController.refresh), input: "r", modifierFlags: .command, discoverabilityTitle: discoverabilityTitle)
} }
static func sidebarCommand(item: MainSidebarViewController.Item, command: String) -> UIKeyCommand { static func sidebarCommand(item: MainSidebarViewController.Item, command: String, action: Selector) -> UIKeyCommand {
let data: Any
if case let .tab(tab) = item {
data = tab.rawValue
} else if case .explore = item {
data = "search"
} else if case .bookmarks = item {
data = "bookmarks"
} else {
fatalError()
}
return UIKeyCommand( return UIKeyCommand(
title: item.title, title: item.title,
image: UIImage(systemName: item.imageName!), image: UIImage(systemName: item.imageName!),
action: #selector(MainSplitViewController.handleSidebarItemCommand(_:)), action: action,
input: command, input: command,
modifierFlags: .command, modifierFlags: .command
propertyList: data
) )
} }
static let sidebarItemKeyCommands: [UIKeyCommand] = [ static let sidebarItemKeyCommands: [UIKeyCommand] = [
sidebarCommand(item: .tab(.timelines), command: "1"), sidebarCommand(item: .tab(.timelines), command: "1", action: #selector(MainSplitViewController.handleSidebarCommandTimelines)),
sidebarCommand(item: .tab(.notifications), command: "2"), sidebarCommand(item: .tab(.notifications), command: "2", action: #selector(MainSplitViewController.handleSidebarCommandNotifications)),
sidebarCommand(item: .explore, command: "3"), sidebarCommand(item: .explore, command: "3", action: #selector(MainSplitViewController.handleSidebarCommandExplore)),
sidebarCommand(item: .bookmarks, command: "4"), sidebarCommand(item: .bookmarks, command: "4", action: #selector(MainSplitViewController.handleSidebarCommandBookmarks)),
sidebarCommand(item: .tab(.myProfile), command: "5"), sidebarCommand(item: .tab(.myProfile), command: "5", action: #selector(MainSplitViewController.handleSidebarCommandMyProfile)),
] ]
static let nextSubTabCommand = UIKeyCommand(title: "Next Sub Tab", action: #selector(TabbedPageViewController.selectNextPage), input: "]", modifierFlags: [.command, .shift]) static let nextSubTabCommand = UIKeyCommand(title: "Next Sub Tab", action: #selector(TabbedPageViewController.selectNextPage), input: "]", modifierFlags: [.command, .shift])

View File

@ -101,27 +101,29 @@ class MainSplitViewController: UISplitViewController {
} }
} }
@objc func handleSidebarItemCommand(_ sender: AnyObject) { @objc func handleSidebarCommandTimelines() {
// workaround for crash when sender is not a UICommand, see #253 and FB11804009 sidebar.select(item: .tab(.timelines), animated: false)
guard let command = sender as? UICommand else { select(item: .tab(.timelines))
return
} }
let item: MainSidebarViewController.Item
if let index = command.propertyList as? Int { @objc func handleSidebarCommandNotifications() {
item = .tab(MainTabBarViewController.Tab(rawValue: index)!) sidebar.select(item: .tab(.notifications), animated: false)
} else if let str = command.propertyList as? String { select(item: .tab(.notifications))
if str == "search" {
item = .explore
} else if str == "bookmarks" {
item = .bookmarks
} else {
fatalError()
} }
} else {
fatalError() @objc func handleSidebarCommandExplore() {
sidebar.select(item: .tab(.explore), animated: false)
select(item: .tab(.explore))
} }
sidebar.select(item: item, animated: false)
select(item: item) @objc func handleSidebarCommandBookmarks() {
sidebar.select(item: .bookmarks, animated: false)
select(item: .bookmarks)
}
@objc func handleSidebarCommandMyProfile() {
sidebar.select(item: .tab(.myProfile), animated: false)
select(item: .tab(.myProfile))
} }
@objc private func sidebarTapped() { @objc private func sidebarTapped() {
@ -519,7 +521,7 @@ extension MainSplitViewController: TuskerRootViewController {
func handleStatusBarTapped(xPosition: CGFloat) -> StatusBarTapActionResult { func handleStatusBarTapped(xPosition: CGFloat) -> StatusBarTapActionResult {
guard presentedViewController == nil else { guard presentedViewController == nil else {
return .stop return .continue
} }
if traitCollection.horizontalSizeClass == .compact { if traitCollection.horizontalSizeClass == .compact {
return tabBarViewController.handleStatusBarTapped(xPosition: xPosition) return tabBarViewController.handleStatusBarTapped(xPosition: xPosition)