// AdvancedPrefsView.swift // Tusker // // Created by Shadowfacts on 6/13/19. // Copyright © 2019 Shadowfacts. All rights reserved. // import SwiftUI import Pachyderm struct AdvancedPrefsView : View { @ObservedObject var preferences = Preferences.shared var body: some View { List { formattingSection automationSection cachingSection } .listStyle(InsetGroupedListStyle()) .navigationBarTitle(Text("Advanced")) } var formattingFooter: some View { Text("This option is only supported for Pleroma and Mastodon instances with formatting enabled. On all other instances, formatting symbols will remain in the unformatted plain text.").lineLimit(nil) } var formattingSection: some View { Section(footer: formattingFooter) { Picker(selection: $preferences.statusContentType, label: Text("Post Content Type")) { ForEach(StatusContentType.allCases, id: \.self) { type in Text(type.displayName).tag(type) }//.navigationBarTitle("Post Content Type") // see FB6838291 } } } var automationSection: some View { Section(header: Text("Automation")) { NavigationLink(destination: SilentActionPrefs()) { Text("Silent Action Permissions") } } } var cachingSection: some View { Section(header: Text("Caching"), footer: Text("Clearing caches will restart the app.")) { Button(action: clearCache) { Text("Clear Mastodon Cache") }.foregroundColor(.red) Button(action: clearImageCaches) { Text("Clear Image Caches") }.foregroundColor(.red) } } private func clearCache() { for account in LocalData.shared.accounts { let controller = MastodonController.getForAccount(account) let coordinator = controller.persistentContainer.persistentStoreCoordinator for store in coordinator.persistentStores { try! coordinator.destroyPersistentStore(at: store.url!, ofType: store.type, options: store.options) } } resetUI() } private func clearImageCaches() { [ ImageCache.avatars, ImageCache.headers, ImageCache.attachments, ImageCache.emojis, ].forEach { try! $0.reset() } resetUI() } private func resetUI() { let mostRecent = LocalData.shared.getMostRecentAccount()! NotificationCenter.default.post(name: .activateAccount, object: nil, userInfo: ["account": mostRecent]) } } extension StatusContentType { var displayName: String { switch self { case .plain: return "Plain" case .markdown: return "Markdown" case .html: return "HTML" } } } #if DEBUG struct AdvancedPrefsView_Previews : PreviewProvider { static var previews: some View { AdvancedPrefsView() } } #endif