From 8ad4c6294c1b0334792b42c4ed97b7f2f378e095 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Wed, 26 Aug 2020 21:25:28 -0700 Subject: [PATCH] Remove macOS vestiges --- Development Assets/DevelopmentModels.swift | 8 +++---- .../TimelinesEndpoint+Stubbing.swift | 4 ---- ...NSMutableAttributedString+Extensions.swift | 4 ---- System/AppDelegate.swift | 24 ++++--------------- System/MetatextApp.swift | 4 ---- Tests/View Models/RootViewModelTests.swift | 2 +- View Models/RootViewModel.swift | 6 ++--- Views/AddIdentityView.swift | 19 --------------- Views/RootView.swift | 22 ++--------------- 9 files changed, 13 insertions(+), 80 deletions(-) diff --git a/Development Assets/DevelopmentModels.swift b/Development Assets/DevelopmentModels.swift index 5193a57..b4bec4e 100644 --- a/Development Assets/DevelopmentModels.swift +++ b/Development Assets/DevelopmentModels.swift @@ -86,19 +86,17 @@ extension AddIdentityViewModel { static let development = RootViewModel.development.addIdentityViewModel() } -extension MainNavigationViewModel { - static let development = RootViewModel.development.mainNavigationViewModel! +extension TabNavigationViewModel { + static let development = RootViewModel.development.tabNavigationViewModel! } -#if os(iOS) extension SecondaryNavigationViewModel { - static let development = MainNavigationViewModel.development.secondaryNavigationViewModel() + static let development = TabNavigationViewModel.development.secondaryNavigationViewModel() } extension IdentitiesViewModel { static let development = IdentitiesViewModel(identityService: .development) } -#endif extension PreferencesViewModel { static let development = PreferencesViewModel(identityService: .development) diff --git a/Development Assets/Mastodon API Stubs/TimelinesEndpoint+Stubbing.swift b/Development Assets/Mastodon API Stubs/TimelinesEndpoint+Stubbing.swift index 66fad3b..f633e61 100644 --- a/Development Assets/Mastodon API Stubs/TimelinesEndpoint+Stubbing.swift +++ b/Development Assets/Mastodon API Stubs/TimelinesEndpoint+Stubbing.swift @@ -1,11 +1,7 @@ // Copyright © 2020 Metabolist. All rights reserved. import Foundation -#if canImport(UIKit) import UIKit -#elseif canImport(AppKit) -import AppKit -#endif extension TimelinesEndpoint: Stubbing { func data(url: URL) -> Data? { diff --git a/Extensions/NSMutableAttributedString+Extensions.swift b/Extensions/NSMutableAttributedString+Extensions.swift index ae79f47..1800a96 100644 --- a/Extensions/NSMutableAttributedString+Extensions.swift +++ b/Extensions/NSMutableAttributedString+Extensions.swift @@ -1,10 +1,6 @@ // Copyright © 2020 Metabolist. All rights reserved. -#if canImport(UIKit) import UIKit -#elseif canImport(AppKit) -import AppKit -#endif import Kingfisher extension NSMutableAttributedString { diff --git a/System/AppDelegate.swift b/System/AppDelegate.swift index 68fe88d..e61674d 100644 --- a/System/AppDelegate.swift +++ b/System/AppDelegate.swift @@ -1,19 +1,10 @@ // Copyright © 2020 Metabolist. All rights reserved. -#if os(macOS) -import AppKit -typealias AppDelegateType = NSApplicationDelegate -typealias ApplicationType = NSApplication -#else import UIKit -typealias AppDelegateType = UIApplicationDelegate -typealias ApplicationType = UIApplication -#endif - import Combine class AppDelegate: NSObject { - @Published private var application: ApplicationType? + @Published private var application: UIApplication? private let remoteNotificationDeviceTokens = PassthroughSubject() } @@ -30,12 +21,7 @@ extension AppDelegate { } } -extension AppDelegate: AppDelegateType { - #if os(macOS) - func applicationDidFinishLaunching(_ notification: Notification) { - application = notification.object as? ApplicationType - } - #else +extension AppDelegate: UIApplicationDelegate { func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { @@ -43,15 +29,13 @@ extension AppDelegate: AppDelegateType { return true } - #endif - func application(_ application: ApplicationType, + func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { - // this doesn't get called on macOS, need to figure out why remoteNotificationDeviceTokens.send(deviceToken) } - func application(_ application: ApplicationType, + func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { remoteNotificationDeviceTokens.send(completion: .failure(error)) } diff --git a/System/MetatextApp.swift b/System/MetatextApp.swift index aef7394..d94c4e0 100644 --- a/System/MetatextApp.swift +++ b/System/MetatextApp.swift @@ -5,11 +5,7 @@ import SwiftUI @main struct MetatextApp: App { // swiftlint:disable weak_delegate - #if os(macOS) - @NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate - #else @UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate - #endif // swiftlint:enable weak_delegate private let allIdentitiesService: AllIdentitiesService = { diff --git a/Tests/View Models/RootViewModelTests.swift b/Tests/View Models/RootViewModelTests.swift index 0ff3989..c6ad723 100644 --- a/Tests/View Models/RootViewModelTests.swift +++ b/Tests/View Models/RootViewModelTests.swift @@ -14,7 +14,7 @@ class RootViewModelTests: XCTestCase { identityDatabase: .fresh(), environment: .development), userNotificationService: UserNotificationService()) - let recorder = sut.$mainNavigationViewModel.record() + let recorder = sut.$tabNavigationViewModel.record() XCTAssertNil(try wait(for: recorder.next(), timeout: 1)) diff --git a/View Models/RootViewModel.swift b/View Models/RootViewModel.swift index 2b47a03..22780e3 100644 --- a/View Models/RootViewModel.swift +++ b/View Models/RootViewModel.swift @@ -4,7 +4,7 @@ import Foundation import Combine class RootViewModel: ObservableObject { - @Published private(set) var mainNavigationViewModel: MainNavigationViewModel? + @Published private(set) var tabNavigationViewModel: TabNavigationViewModel? @Published private var mostRecentlyUsedIdentityID: UUID? // swiftlint:disable weak_delegate @@ -38,7 +38,7 @@ class RootViewModel: ObservableObject { extension RootViewModel { func newIdentitySelected(id: UUID?) { guard let id = id else { - mainNavigationViewModel = nil + tabNavigationViewModel = nil return } @@ -70,7 +70,7 @@ extension RootViewModel { .sink { _ in } receiveValue: { _ in } .store(in: &cancellables) - mainNavigationViewModel = MainNavigationViewModel(identityService: identityService) + tabNavigationViewModel = TabNavigationViewModel(identityService: identityService) } func deleteIdentity(_ identity: Identity) { diff --git a/Views/AddIdentityView.swift b/Views/AddIdentityView.swift index 836ccd5..dfcce47 100644 --- a/Views/AddIdentityView.swift +++ b/Views/AddIdentityView.swift @@ -8,15 +8,10 @@ struct AddIdentityView: View { var body: some View { Form { - #if os(macOS) - Spacer() - urlTextField - #else urlTextField .autocapitalization(.none) .disableAutocorrection(true) .keyboardType(.URL) - #endif Group { if viewModel.loading { ProgressView() @@ -28,11 +23,7 @@ struct AddIdentityView: View { .frame(maxWidth: .infinity, alignment: .center) Button("add-identity.browse-anonymously", action: viewModel.browseAnonymouslyTapped) .frame(maxWidth: .infinity, alignment: .center) - #if os(macOS) - Spacer() - #endif } - .paddingIfMac() .alertItem($viewModel.alertItem) .onReceive(viewModel.addedIdentityID) { id in withAnimation { @@ -48,16 +39,6 @@ extension AddIdentityView { } } -private extension View { - func paddingIfMac() -> some View { - #if os(macOS) - return padding() - #else - return self - #endif - } -} - #if DEBUG struct AddAccountView_Previews: PreviewProvider { static var previews: some View { diff --git a/Views/RootView.swift b/Views/RootView.swift index 606f8dc..9719a92 100644 --- a/Views/RootView.swift +++ b/Views/RootView.swift @@ -2,18 +2,12 @@ import SwiftUI -#if os(macOS) -typealias MainNavigationViewModel = SidebarNavigationViewModel -#else -typealias MainNavigationViewModel = TabNavigationViewModel -#endif - struct RootView: View { @StateObject var viewModel: RootViewModel var body: some View { - if let mainNavigationViewModel = viewModel.mainNavigationViewModel { - Self.mainNavigation(mainNavigationViewModel: mainNavigationViewModel) + if let tabNavigationViewModel = viewModel.tabNavigationViewModel { + TabNavigationView(viewModel: tabNavigationViewModel) .id(UUID()) .environmentObject(viewModel) .transition(.opacity) @@ -25,18 +19,6 @@ struct RootView: View { } } -private extension RootView { - @ViewBuilder - private static func mainNavigation(mainNavigationViewModel: MainNavigationViewModel) -> some View { - #if os(macOS) - SidebarNavigationView(viewModel: mainNavigationViewModel) - .frame(minWidth: 900, maxWidth: .infinity, minHeight: 500, maxHeight: .infinity) - #else - TabNavigationView(viewModel: mainNavigationViewModel) - #endif - } -} - #if DEBUG struct ContentView_Previews: PreviewProvider { static var previews: some View {