2019-06-14 00:53:17 +00:00
// A d v a n c e d P r e f s V i e w . s w i f t
// T u s k e r
//
// C r e a t e d b y S h a d o w f a c t s o n 6 / 1 3 / 1 9 .
// C o p y r i g h t © 2 0 1 9 S h a d o w f a c t s . A l l r i g h t s r e s e r v e d .
//
import SwiftUI
import Pachyderm
struct AdvancedPrefsView : View {
2019-11-15 00:53:00 +00:00
@ ObservedObject var preferences = Preferences . shared
2019-06-14 00:53:17 +00:00
var body : some View {
List {
2019-07-28 01:43:08 +00:00
formattingSection
automationSection
2020-05-13 22:58:11 +00:00
cachingSection
2019-08-06 03:08:00 +00:00
} . listStyle ( GroupedListStyle ( ) )
2019-07-28 01:43:08 +00:00
. 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 ) {
2019-11-15 00:53:00 +00:00
Picker ( selection : $ preferences . statusContentType , label : Text ( " Post Content Type " ) ) {
2019-07-28 01:43:08 +00:00
ForEach ( StatusContentType . allCases , id : \ . self ) { type in
Text ( type . displayName ) . tag ( type )
} // . n a v i g a t i o n B a r T i t l e ( " P o s t C o n t e n t T y p e " )
// s e e F B 6 8 3 8 2 9 1
2019-06-14 00:53:17 +00:00
}
2019-07-28 01:43:08 +00:00
}
}
var automationSection : some View {
Section ( header : Text ( " AUTOMATION " ) ) {
NavigationLink ( destination : SilentActionPrefs ( ) ) {
Text ( " Silent Action Permissions " )
2019-06-14 00:53:17 +00:00
}
}
2019-07-28 01:43:08 +00:00
}
2020-05-13 22:58:11 +00:00
var cachingSection : some View {
Section ( header : Text ( " CACHING " ) ) {
Button ( action : clearCache ) {
Text ( " Clear Cache " )
} . foregroundColor ( . red )
}
}
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 )
}
}
MastodonController . resetAll ( )
let mostRecent = LocalData . shared . getMostRecentAccount ( ) !
NotificationCenter . default . post ( name : . activateAccount , object : nil , userInfo : [ " account " : mostRecent ] )
}
2019-07-28 01:43:08 +00:00
}
extension StatusContentType {
var displayName : String {
switch self {
case . plain :
return " Plain "
case . markdown :
return " Markdown "
case . html :
return " HTML "
}
2019-06-14 00:53:17 +00:00
}
}
#if DEBUG
struct AdvancedPrefsView_Previews : PreviewProvider {
static var previews : some View {
AdvancedPrefsView ( )
}
}
#endif