Tusker/Tusker/Preferences/Preferences.swift

64 lines
1.8 KiB
Swift
Raw Normal View History

2018-08-28 23:16:17 +00:00
//
// Preferences.swift
// Tusker
//
// Created by Shadowfacts on 8/28/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import Foundation
2018-09-11 14:52:21 +00:00
import Pachyderm
2018-08-28 23:16:17 +00:00
class Preferences: Codable {
private(set) static var shared: Preferences = load()
private static var documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
private static var archiveURL = Preferences.documentsDirectory.appendingPathComponent("preferences").appendingPathExtension("plist")
static func save() {
let encoder = PropertyListEncoder()
let data = try? encoder.encode(shared)
try? data?.write(to: Preferences.archiveURL, options: .noFileProtection)
}
static func load() -> Preferences {
let decoder = PropertyListDecoder()
if let data = try? Data(contentsOf: Preferences.archiveURL),
let preferences = try? decoder.decode(Preferences.self, from: data) {
return preferences
}
return Preferences()
}
private init() {}
2018-08-28 23:16:17 +00:00
// MARK: - Appearance
var showRepliesInProfiles = false
2018-08-28 23:49:31 +00:00
var avatarStyle = AvatarStyle.roundRect
var hideCustomEmojiInUsernames = false
var tabs: [Tab: Int] = [.home: 0, .notifications: 1, .local: -1, .federated: 2, .myProfile: 3, .preferences: 4]
2018-09-11 14:52:21 +00:00
var defaultPostVisibility = Status.Visibility.public
2018-08-31 02:30:19 +00:00
// MARK: - Advanced
var silentActions: [String: Permission] = [:]
// MARK: - Utility Methods
func tabIndex(_ tab: Tab) -> Int {
if let index = tabs[tab] {
return index
} else {
tabs[tab] = -1
return -1
}
}
}
extension Preferences {
enum Permission: String, Codable {
case undecided, accepted, rejected
}
2018-08-28 23:16:17 +00:00
}