Compare commits

..

No commits in common. "e5363b2e213a16d4a9edd23f1fcd27b3e83eade2" and "5471d810c86202e3f8a161c0c327de005f85f9a3" have entirely different histories.

4 changed files with 45 additions and 39 deletions

View File

@ -139,14 +139,13 @@ public class Client {
} }
} }
public func getAccessToken(authorizationCode: String, redirectURI: String, scopes: [Scope], completion: @escaping Callback<LoginSettings>) { public func getAccessToken(authorizationCode: String, redirectURI: String, 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,8 +10,6 @@ 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]()
@ -130,7 +128,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: oauthScopes) { response in client.registerApp(name: "Tusker", redirectURI: "tusker://oauth", scopes: [.read, .write, .follow]) { response in
switch response { switch response {
case .failure(let error): case .failure(let error):
continuation.resume(throwing: error) continuation.resume(throwing: error)
@ -148,7 +146,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", scopes: oauthScopes) { response in client.getAccessToken(authorizationCode: authorizationCode, redirectURI: "tusker://oauth") { 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,22 +18,33 @@ 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, action: Selector) -> UIKeyCommand { static func sidebarCommand(item: MainSidebarViewController.Item, command: String) -> 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: action, action: #selector(MainSplitViewController.handleSidebarItemCommand(_:)),
input: command, input: command,
modifierFlags: .command modifierFlags: .command,
propertyList: data
) )
} }
static let sidebarItemKeyCommands: [UIKeyCommand] = [ static let sidebarItemKeyCommands: [UIKeyCommand] = [
sidebarCommand(item: .tab(.timelines), command: "1", action: #selector(MainSplitViewController.handleSidebarCommandTimelines)), sidebarCommand(item: .tab(.timelines), command: "1"),
sidebarCommand(item: .tab(.notifications), command: "2", action: #selector(MainSplitViewController.handleSidebarCommandNotifications)), sidebarCommand(item: .tab(.notifications), command: "2"),
sidebarCommand(item: .explore, command: "3", action: #selector(MainSplitViewController.handleSidebarCommandExplore)), sidebarCommand(item: .explore, command: "3"),
sidebarCommand(item: .bookmarks, command: "4", action: #selector(MainSplitViewController.handleSidebarCommandBookmarks)), sidebarCommand(item: .bookmarks, command: "4"),
sidebarCommand(item: .tab(.myProfile), command: "5", action: #selector(MainSplitViewController.handleSidebarCommandMyProfile)), sidebarCommand(item: .tab(.myProfile), command: "5"),
] ]
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,29 +101,27 @@ class MainSplitViewController: UISplitViewController {
} }
} }
@objc func handleSidebarCommandTimelines() { @objc func handleSidebarItemCommand(_ sender: AnyObject) {
sidebar.select(item: .tab(.timelines), animated: false) // workaround for crash when sender is not a UICommand, see #253 and FB11804009
select(item: .tab(.timelines)) guard let command = sender as? UICommand else {
return
} }
let item: MainSidebarViewController.Item
@objc func handleSidebarCommandNotifications() { if let index = command.propertyList as? Int {
sidebar.select(item: .tab(.notifications), animated: false) item = .tab(MainTabBarViewController.Tab(rawValue: index)!)
select(item: .tab(.notifications)) } else if let str = command.propertyList as? String {
if str == "search" {
item = .explore
} else if str == "bookmarks" {
item = .bookmarks
} else {
fatalError()
} }
} else {
@objc func handleSidebarCommandExplore() { fatalError()
sidebar.select(item: .tab(.explore), animated: false)
select(item: .tab(.explore))
} }
sidebar.select(item: item, animated: false)
@objc func handleSidebarCommandBookmarks() { select(item: item)
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() {
@ -521,7 +519,7 @@ extension MainSplitViewController: TuskerRootViewController {
func handleStatusBarTapped(xPosition: CGFloat) -> StatusBarTapActionResult { func handleStatusBarTapped(xPosition: CGFloat) -> StatusBarTapActionResult {
guard presentedViewController == nil else { guard presentedViewController == nil else {
return .continue return .stop
} }
if traitCollection.horizontalSizeClass == .compact { if traitCollection.horizontalSizeClass == .compact {
return tabBarViewController.handleStatusBarTapped(xPosition: xPosition) return tabBarViewController.handleStatusBarTapped(xPosition: xPosition)